Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add model config #487

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

feat: add model config #487

wants to merge 5 commits into from

Conversation

NingLu
Copy link
Collaborator

@NingLu NingLu commented Dec 18, 2024

Fixes #

🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request introduces several enhancements and modifications to the language model integration and chat functionality. The primary changes include:

  1. Updates to the langchain_integration module, including modifications to the chains, chat_models, and the addition of a new model_config.py file.
  2. Changes to the common_utils/constant.py file.
  3. Modifications to the common_entry.py file, which handles the online entries for the application.
  4. Updates to the ChatBot.tsx file in the portal's frontend.

These changes aim to improve the overall performance, functionality, and integration of the language models with the application's chat and query handling capabilities.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

File Stats Summary

File number involved in this PR: 10, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/portal/src/pages/chatbot/ChatBot.tsx 5 added, 0 removed The code changes add functionality to store the current chatbot option in the browser's local storage, allowing it to persist across page reloads.
source/lambda/online/common_logic/langchain_integration/chains/tool_calling_chain_api.py 9 added, 42 removed This code change refactors the Claude2ToolCallingChain class into a generic ToolCallingChain class and dynamically creates subclasses for different models based on configurations.
source/lambda/online/lambda_main/main_utils/online_entries/common_entry.py 1 added, 1 removed The code change involves modifying the string quotation marks around the "all_knowledge_rag_tool" key from single quotes to double quotes.
source/lambda/online/common_logic/langchain_integration/chat_models/init.py 0 added, 5 removed The code change removes the import logic for the LLMModelType.NOVA_PRO case from the _load_module function's model_loader dictionary.
source/lambda/online/common_logic/langchain_integration/model_config.py 67 added, 0 removed This code defines a ModelConfig dataclass and a dictionary of model configurations for various LLM models with their respective model IDs and default keyword arguments.
source/lambda/online/common_logic/langchain_integration/chains/rag_chain.py 9 added, 52 removed This code change refactors the existing LLMChain subclasses for different model types into a single RagChain class that dynamically creates chains for different models based on configurations defined in MODEL_CONFIGS.
source/lambda/online/common_logic/common_utils/constant.py 1 added, 0 removed The code adds a new constant DEFAULT to the LLMModelType class, and includes several other model types for the Anthropic Claude language model.
source/lambda/online/common_logic/langchain_integration/chains/chat_chain.py 17 added, 63 removed This code change seems to be refactoring the different LLM chat chain classes. The main changes are:
  1. Introduced a base ChatChain class that sets default model kwargs and handles common logic.
  2. Removed individual chat chain classes for specific models like Claude variants.
  3. Introduced a dictionary chain_classes that dynamically creates chat chain classes for all models defined in MODEL_CONFIGS.
  4. Added these dynamically created classes to the global namespace. |
    | source/lambda/online/common_logic/langchain_integration/chains/query_rewrite_chain.py | 10 added, 32 removed | The code changes introduce a new QueryRewriteChain class that uses the default model specified in MODEL_CONFIGS. It also dynamically creates chain classes for all models in MODEL_CONFIGS for the QUERY_REWRITE_TYPE task, and adds them to the global namespace. |
    | source/lambda/online/common_logic/langchain_integration/chains/init.py | 154 added, 120 removed | This code change introduces a new way to dynamically create LLM chain classes based on the model ID and intent type. It adds methods to convert model IDs to valid Python class names, and a factory method create_for_model to create a new chain class dynamically. It also reorganizes the imports of different chain types into separate functions and updates the global namespace accordingly. |
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request introduces several changes to the codebase, primarily focused on enhancing the integration with LangChain and improving the chat functionality. The modifications span multiple files and directories, including the common utilities, LangChain integration components, and the chatbot user interface.

The key changes include:

  1. Updates to the constant.py file to accommodate new constants or modify existing ones.
  2. Modifications to the LangChain integration chains, such as chat_chain.py, query_rewrite_chain.py, rag_chain.py, and tool_calling_chain_api.py, to improve the chat experience and enhance the functionality of the language model.
  3. Updates to the bedrock_models.py file, which likely involves changes to the underlying language models used in the application.
  4. Addition of a new file, model_config.py, which potentially introduces configuration settings for the language models.
  5. Changes to the common_entry.py file, which may affect the common entry point for the online lambda function.
  6. Modifications to the ChatBot.tsx file in the portal's source code, suggesting updates to the chatbot user interface.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

File Stats Summary

File number involved in this PR: 11, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/online/lambda_main/main_utils/online_entries/common_entry.py 1 added, 1 removed The code change modifies the assignment of the 'all_knowledge_rag_tool' variable, replacing single quotes with double quotes for string consistency.
source/lambda/online/common_logic/common_utils/constant.py 1 added, 0 removed This code change introduces a new constant DEFAULT in the LLMModelType class, and adds three new model types: CLAUDE_INSTANCE, CLAUDE_2, and CLAUDE_21.
source/portal/src/pages/chatbot/ChatBot.tsx 5 added, 0 removed The code adds functionality to store the current chatbot option in the browser's localStorage, allowing it to persist across page reloads or sessions.
source/lambda/online/common_logic/langchain_integration/model_config.py 78 added, 0 removed The code defines a ModelConfig dataclass and a dictionary MODEL_CONFIGS containing configurations for various language models, including settings like model ID, default keyword arguments, and whether to enable auto tool choice and prefill.
source/lambda/online/common_logic/langchain_integration/chains/rag_chain.py 9 added, 52 removed The code changes involve refactoring the various LLMChain subclasses for different models into a single RagChain class that dynamically creates chains based on the model ID. It imports MODEL_CONFIGS from model_config and uses it to generate chain classes for each model ID at runtime.
source/lambda/online/common_logic/langchain_integration/chat_models/bedrock_models.py 9 added, 57 removed The code changes introduce a new BedrockModel class that replaces the previous model-specific classes like Claude2, Claude21, etc. It dynamically creates model classes based on the MODEL_CONFIGS and adds them to the module's global namespace. This change likely aims to simplify and centralize model configuration management.
source/lambda/online/common_logic/langchain_integration/chains/tool_calling_chain_api.py 9 added, 42 removed This code change refactors the model-specific tool calling chain classes into a single ToolCallingChain class that dynamically creates chain instances for different models based on configurations.
source/lambda/online/common_logic/langchain_integration/chains/chat_chain.py 17 added, 63 removed The code changes introduce a new base class ChatChain that extends LLMChain for chat-based language models. It also defines a dictionary chain_classes that maps model IDs to their corresponding ChatChain subclasses, which are dynamically created using LLMChain.create_for_model. The subclasses are then added to the global namespace.
source/lambda/online/common_logic/langchain_integration/chains/query_rewrite_chain.py 10 added, 32 removed This code change introduces a more generic and extensible approach for creating query rewrite chains for different language models. Instead of defining separate classes for each model, it uses a dictionary to map model IDs to their corresponding chain classes. The chain classes are dynamically created using the create_for_model method, which takes the model ID and task type as arguments. Additionally, it removes the individual class definitions for specific models like Claude and replaces them with a single QueryRewriteChain class that uses the LLMModelType.DEFAULT model ID.
source/lambda/online/common_logic/langchain_integration/chains/init.py 150 added, 120 removed This code change introduces a new way to create chains dynamically based on the model ID and intent type. It adds a model_id_to_class_name method to convert the model ID to a valid Python class name, and a create_for_model method to create a new chain class dynamically using the model configuration. It also reorganizes the imports of various chain classes and consolidates some of them into separate modules.
source/lambda/online/common_logic/langchain_integration/chat_models/init.py 83 added, 42 removed The code changes introduce a new factory method create_for_model in the Model class to create a model instance based on the provided model ID. It also adds a helper method model_id_to_class_name to convert the model ID to a valid Python class name. Additionally, it refactors the import statements for different model classes and updates the _import_bedrock_models function to use a more concise approach.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request introduces several updates and improvements to the LangChain integration and chat functionality. The main changes include:

  • Refactoring and optimization of the LangChain chains, including the chat chain, query rewrite chain, and retrieval-augmented generation (RAG) chain.
  • Updates to the Bedrock language models for improved performance and compatibility.
  • Addition of a new model_config.py file to centralize model configuration settings.
  • Modifications to the common entry point for online lambda functions to accommodate the updated LangChain integration.
  • Updates to the chatbot component in the portal to support the new features and changes.

These changes aim to enhance the overall performance, scalability, and maintainability of the LangChain integration and chat functionality within the application.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

File Stats Summary

File number involved in this PR: 12, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/portal/src/utils/const.ts 2 added, 1 removed The provided code change adds a new constant export named "HISTORY_CHATBOT_ID" to the existing list of exported constants.
source/lambda/online/lambda_main/main_utils/online_entries/common_entry.py 1 added, 1 removed The code change modifies the assignment of the 'all_knowledge_rag_tool' variable, replacing single quotes with double quotes for string literals.
source/lambda/online/common_logic/common_utils/constant.py 1 added, 0 removed The code adds a new constant DEFAULT to the LLMModelType class, likely representing a default model ID for language models.
source/lambda/online/common_logic/langchain_integration/chat_models/bedrock_models.py 9 added, 57 removed This code change introduces a new BedrockModel class that serves as a base class for different language models. It imports the MODEL_CONFIGS from the model_config module and dynamically creates model classes based on the configurations. The model classes are added to the module's global namespace for easy access.
source/lambda/online/common_logic/langchain_integration/chains/tool_calling_chain_api.py 9 added, 42 removed The code changes introduce a generic ToolCallingChain class that dynamically creates chain classes for different models based on the MODEL_CONFIGS, replacing the previous approach of defining separate classes for each model.
source/lambda/online/common_logic/langchain_integration/model_config.py 78 added, 0 removed This code defines a ModelConfig dataclass and a dictionary of model configurations for various LLM models, including Claude, Nova, Llama, Mistral, and Cohere models, with settings for model ID, default model parameters, auto tool choice, and prefill options.
source/portal/src/pages/chatbot/ChatBot.tsx 6 added, 2 removed The code changes involve importing a new constant HISTORY_CHATBOT_ID, using it to store and retrieve the chatbot ID from localStorage, and removing the history chatbot ID from localStorage when manually changing the chatbot.
source/lambda/online/common_logic/langchain_integration/chains/chat_chain.py 17 added, 63 removed This code change refactors the ChatChain classes to use a more generic approach based on model configurations, adds support for different language models, and updates default model parameters.
source/lambda/online/common_logic/langchain_integration/chains/query_rewrite_chain.py 10 added, 32 removed This code change introduces a more generic and extensible approach for creating query rewrite chains for different language models. It defines a single QueryRewriteChain class that uses the LLMModelType.DEFAULT model and a chain_classes dictionary that dynamically creates chain classes for all available models in MODEL_CONFIGS. The previously defined model-specific chain classes are removed.
source/lambda/online/common_logic/langchain_integration/chat_models/init.py 83 added, 42 removed The code changes introduce a new factory method create_for_model in the Model class, which dynamically creates a new class for a given model ID using the configurations from MODEL_CONFIGS. It also refactors the import statements for different model classes and updates the model_id_to_class_name method to handle model IDs with version numbers and vendor prefixes.
source/lambda/online/common_logic/langchain_integration/chains/rag_chain.py 9 added, 52 removed The code changes introduce a new RagChain class that serves as a base class for all RAG (Retrieval-Augmented Generation) chains. It simplifies the codebase by consolidating multiple model-specific chain classes into a single class that dynamically creates chains for different models using the MODEL_CONFIGS dictionary. Additionally, it adds a dictionary chain_classes that maps model IDs to their corresponding chain classes, making it easier to access and instantiate chains for different models.
source/lambda/online/common_logic/langchain_integration/chains/init.py 150 added, 120 removed The code changes introduce a new method create_for_model in the LLMChain class, which dynamically creates a new class for a specific model based on the model ID and intent type. It also adds a helper method model_id_to_class_name to convert the model ID to a valid Python class name. Additionally, it refactors the import statements for various chain modules, using a centralized chain_classes dictionary to store the imported classes and updating the global namespace accordingly.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request introduces changes to integrate the LangChain library for natural language processing and model management. The main updates include:

  • Added a new module model_config.py to handle the configuration and loading of language models.
  • Modified various chain files (chat_chain.py, query_rewrite_chain.py, rag_chain.py, tool_calling_chain_api.py) to incorporate LangChain components.
  • Updated the bedrock_models.py file to support LangChain model integration.
  • Modified common_entry.py to utilize the new LangChain chains and models.
  • Updated the frontend ChatBot.tsx and const.ts files to accommodate the backend changes.

The primary motivation behind this change is to leverage the powerful capabilities of LangChain for natural language processing tasks, such as question answering, text generation, and model management. LangChain provides a modular and extensible framework for building applications with language models.

This change does not require any external dependencies beyond the LangChain library itself.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

File Stats Summary

File number involved in this PR: 12, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/portal/src/utils/const.ts 2 added, 1 removed This code change adds a new exported constant called HISTORY_CHATBOT_ID to the existing set of constants.
source/lambda/online/common_logic/common_utils/constant.py 1 added, 0 removed This code change introduces a new constant DEFAULT in the LLMModelType class, likely representing a default model identifier, and adds three constants for different versions of the Claude language model from Anthropic.
source/lambda/online/common_logic/langchain_integration/chains/tool_calling_chain_api.py 9 added, 42 removed The code changes refactor the ToolCallingChain class to dynamically create chain classes for different models based on the MODEL_CONFIGS, instead of having separate classes for each model.
source/lambda/online/common_logic/langchain_integration/chat_models/bedrock_models.py 9 added, 57 removed This code change introduces a more flexible and extensible way of creating and managing different AI models. It removes the individual model classes (e.g., Claude2, Claude21, etc.) and instead creates model instances dynamically based on configurations defined in the MODEL_CONFIGS module. The BedrockModel class serves as a base class for all models, and the model_classes dictionary maps model IDs to their corresponding instances.
source/lambda/online/common_logic/langchain_integration/chains/query_rewrite_chain.py 10 added, 32 removed The code changes introduce a new QueryRewriteChain class that uses a default model specified in MODEL_CONFIGS. It also adds all available query rewrite chain classes to the module's global namespace based on the models defined in MODEL_CONFIGS.
source/lambda/online/lambda_main/main_utils/online_entries/common_entry.py 1 added, 1 removed This code change updates a string quote style from single quotes to double quotes for the 'all_knowledge_rag_tool' key in a dictionary.
source/lambda/online/common_logic/langchain_integration/chains/chat_chain.py 17 added, 63 removed The code changes introduce a new base class ChatChain for LLM chat chains, with a default model type and model parameters. It also adds a dictionary chain_classes that maps model IDs to their corresponding ChatChain subclasses, which are dynamically created using the MODEL_CONFIGS and added to the global namespace.
source/lambda/online/common_logic/langchain_integration/chains/rag_chain.py 9 added, 52 removed The code changes introduce a new class RagChain that serves as a base class for all RAG (Retrieval-Augmented Generation) chains, replacing the previous Claude2RagLLMChain. It also removes several model-specific RAG chain classes and instead dynamically creates chain classes for all available models using a dictionary comprehension. The system prompt addition logic is also refactored into a separate function.
source/portal/src/pages/chatbot/ChatBot.tsx 6 added, 2 removed The code changes include: importing a new constant HISTORY_CHATBOT_ID, using the constant for localStorage key instead of hardcoded string, removing the HISTORY_CHATBOT_ID from localStorage when manually changing chatbot option.
source/lambda/online/common_logic/langchain_integration/model_config.py 78 added, 0 removed This code change introduces a dataclass called ModelConfig to store configuration details for different language models, including model ID, default model parameters, and flags for enabling auto tool choice and prefilling. It also defines a base configuration and a dictionary of configurations for various models like Claude, Nova, Llama, Mistral, and Cohere.
source/lambda/online/common_logic/langchain_integration/chat_models/init.py 83 added, 42 removed The code changes introduce a new method model_id_to_class_name to convert model IDs to valid Python class names, and a factory method create_for_model to dynamically create model classes based on configurations. It also refactors the import statements for bedrock models.
source/lambda/online/common_logic/langchain_integration/chains/init.py 150 added, 120 removed This code change introduces a new way to dynamically create LLMChain classes for different models and intent types. It adds a model_id_to_class_name method to convert model IDs to valid Python class names, and a create_for_model factory method to create a new LLMChain subclass for a specific model and intent type. It also reorganizes the imports of different chain types into separate functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant