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

refactor: Add other bedrock models #432

Merged
merged 33 commits into from
Nov 13, 2024
Merged

refactor: Add other bedrock models #432

merged 33 commits into from
Nov 13, 2024

Conversation

11zhouxuan
Copy link
Collaborator

@11zhouxuan 11zhouxuan commented Nov 12, 2024

refactor: add other bedrock models

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

Description

This pull request includes several changes to the codebase, primarily focused on reorganizing and renaming files within the source/lambda/online/__functions/ directory. The changes are summarized as follows:

  • The __functions/__init__.py file has been added, potentially indicating the creation of a new Python package.
  • Several files have been renamed, such as _tool_base.py, retriever.py, and websearch_retrievers.py.
  • Multiple files and directories under functions_utils/retriever/utils/ have been marked with an error status, suggesting potential issues or conflicts.
  • Several files and directories under lambda_aws_qa_tools/, lambda_common_tools/, and lambda_retail_tools/ have also been marked with an error status.
  • The rag.py file under lambda_common_tools/ has been renamed.

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

Motivation and Context

The motivation behind these changes is not explicitly stated, but it appears to be a reorganization and restructuring of the codebase, potentially to improve code organization, modularity, or to introduce new features or functionality.

Dependencies

Due to the nature of the changes, there may be dependencies or conflicts that need to be resolved, especially for the files and directories marked with an error status. It would be advisable to investigate these errors and ensure that any necessary dependencies or compatibility issues are addressed before merging this pull request.

File Stats Summary

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

The file changes summary is as follows:

Files
Changes
Change Summary
source/infrastructure/lib/chat/chat-stack.ts 20 added, 20 removed The code changes comment out the creation and initialization of the lambdaOnlineFunctions Lambda function, as well as the granting of permissions for other Lambda functions to invoke it.
source/lambda/online/__functions/functions_utils/retriever/retriever.py 1 added, 2 removed The code changes involve removing an unused import, reordering imports, and moving the AmazonKnowledgeBasesRetriever import from the core LangChain package to the community package.
source/lambda/online/__functions/functions_utils/retriever/utils/websearch_retrievers.py 1 added, 1 removed The code change replaces the import of GoogleSearchAPIWrapper from the langchain library with the one from the langchain_community library.
source/lambda/online/__functions/lambda_common_tools/rag.py 1 added, 0 removed The code change adds a line to update the "query" key in the retriever_params dictionary with the value from state using the specified query_key.
source/lambda/online/__functions/_tool_base.py 2 added, 0 removed The code changes introduce a new ToolDefType enum with an "openai" value, add a default value for the "scene" field in the Tool class, and add empty lines for better code readability.
source/lambda/job/dep/llm_bot_dep/sm_utils.py 8 added, 7 removed The code changes involve importing modules from the langchain_community package instead of langchain, updating type annotations for content_type and accepts variables, and modifying the Extra configuration for the Config class to use its value attribute.
source/lambda/online/__functions/init.py 11 added, 0 removed This code change imports and initializes various tool modules, including common tools, AWS QA tools, and retail tools, likely for use in a larger application or framework.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request includes a refactoring of the project's source code structure and file organization. The primary changes are:

  • Renaming and moving files related to the retriever and utility functions used in the online functions.
  • Adding a new file __init__.py under the source/lambda/online/__functions/ directory.
  • Renaming the file _tool_base.py to clarify its purpose.
  • Modifying the chat-stack.ts file in the infrastructure directory, likely to accommodate the changes in the source code.
  • Modifying the sm_utils.py file, which is a dependency for the language model bot.

Additionally, there are several files marked with an "error" status, which may indicate issues or conflicts that need to be resolved before merging the changes.

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

Motivation and Context

The motivation behind this refactoring is likely to improve the overall code organization, maintainability, and potentially separate concerns or responsibilities within the codebase. However, since there are files marked with errors, it's essential to ensure that all dependencies and conflicts are resolved before merging the changes to avoid breaking existing functionality.

Dependencies

This change may require updates to the project's documentation to reflect the new file structure and any changes in the usage or import statements related to the refactored files.

File Stats Summary

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

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/online/__functions/init.py 11 added, 0 removed This code change imports and initializes various tools related to lambda functions, including common tools, AWS QA tools, and retail tools.
source/lambda/online/__functions/functions_utils/retriever/utils/websearch_retrievers.py 1 added, 1 removed The code change replaces the import of GoogleSearchAPIWrapper from the langchain.utilities module with the langchain_community.utilities module.
source/lambda/online/__functions/functions_utils/retriever/retriever.py 1 added, 2 removed The code changes include removing an unused import, reorganizing imports, and importing the AmazonKnowledgeBasesRetriever from the langchain_community.retrievers module instead of langchain.retrievers.
source/infrastructure/lib/chat/chat-stack.ts 20 added, 20 removed The code changes remove the creation and usage of the lambdaOnlineFunctions Lambda function by commenting out the relevant lines.
source/lambda/online/__functions/_tool_base.py 2 added, 0 removed The code changes involve adding an import for the Enum class, defining a new ToolDefType enum with an "openai" value, and adding some formatting changes.
source/lambda/job/dep/llm_bot_dep/sm_utils.py 8 added, 7 removed The code changes involve importing modules from the langchain_community package instead of langchain, updating type annotations for content_type and accepts variables, and modifying the Extra configuration in the Config class to use the .value attribute.
source/lambda/online/__functions/lambda_common_tools/rag.py 1 added, 0 removed The code adds a line to set the "query" key in the retriever_params dictionary using the value from the state dictionary, and then invokes the "Online_Functions" Lambda function with the retriever_params as the event_body.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request includes several changes to the codebase, primarily focused on reorganizing and renaming files and directories within the source/lambda/online/__functions/ directory. The changes are as follows:

  • The __functions/__init__.py file has been added, likely to initialize the package.
  • The _tool_base.py file has been renamed.
  • Several files and directories within the functions_utils/retriever/utils/ directory have been renamed or marked with an error, suggesting potential issues or conflicts.
  • The lambda_aws_qa_tools/, lambda_common_tools/, and lambda_retail_tools/ directories and their respective files have been marked with errors, indicating potential issues or conflicts.
  • The rag.py file within the lambda_common_tools/ directory has been renamed.

These changes appear to be primarily organizational and may involve refactoring or restructuring the codebase. However, some of the errors marked suggest potential conflicts or issues that need to be addressed.

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: 7, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/online/__functions/functions_utils/retriever/utils/websearch_retrievers.py 1 added, 1 removed The code change replaces the import statement for the GoogleSearchAPIWrapper from the langchain package with the langchain_community package.
source/lambda/online/__functions/_tool_base.py 2 added, 0 removed The code changes involve adding an import statement for the 'Enum' class from the 'enum' module, defining a new 'ToolDefType' enumeration with a single value 'openai', and adding some whitespace formatting.
source/infrastructure/lib/chat/chat-stack.ts 20 added, 20 removed The code changes remove the creation and usage of the lambdaOnlineFunctions Lambda function by commenting out the related lines of code.
source/lambda/online/__functions/lambda_common_tools/rag.py 1 added, 0 removed This code change adds a line to set the "query" key in the retriever_params dictionary with the value from the state dictionary, using a nested dictionary lookup.
source/lambda/online/__functions/init.py 11 added, 0 removed This code change introduces a tool module, imports various tool-related modules (lambda_common_tools, lambda_aws_qa_tools, and lambda_retail_tools), and defines functions to initialize these tools.
source/lambda/online/__functions/functions_utils/retriever/retriever.py 1 added, 2 removed The code changes involve removing an unused import, reordering imports, and moving the AmazonKnowledgeBasesRetriever import from langchain to langchain_community.
source/lambda/job/dep/llm_bot_dep/sm_utils.py 8 added, 7 removed The code changes seem to involve updating import paths from langchain to langchain_community, adding type annotations for content_type and accepts variables, and modifying the value assignment for the extra configuration in the Config class.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request includes various changes to the project's source code. Several files have been modified, added, or renamed across different directories. The changes seem to be related to the chat functionality, AWS tools, common tools, and retail tools.

The modifications include updates to the chat stack infrastructure, changes to the language model bot dependencies, and the addition of a new file for online functions. Several files related to retrievers, AWS QA tools, common tools, and retail tools have been renamed or marked with errors, indicating potential issues or incomplete changes.

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

Motivation and Context

Please provide more context and motivation behind these changes, as well as any relevant dependencies that might be required. Additionally, it would be helpful to clarify the errors or issues associated with the files marked with errors, and whether these changes are intended to address specific bugs or introduce new features.

File Stats Summary

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

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/online/__functions/functions_utils/retriever/utils/websearch_retrievers.py 1 added, 1 removed The code change replaces the import of GoogleSearchAPIWrapper from the langchain.utilities module with the langchain_community.utilities module.
source/lambda/online/__functions/init.py 11 added, 0 removed This code change initializes various tools for different purposes, such as common tools, AWS QA tools, and retail tools, by importing them from separate modules.
source/infrastructure/lib/chat/chat-stack.ts 20 added, 20 removed The code changes remove the lambda function lambdaOnlineFunctions by commenting out the relevant lines of code that create and configure the function.
source/lambda/online/__functions/_tool_base.py 2 added, 0 removed The code changes involve adding an empty line for better readability, defining a new Enum called ToolDefType with a value 'openai', and initializing an empty dictionary called 'tools' in the ToolManager class.
source/lambda/job/dep/llm_bot_dep/sm_utils.py 8 added, 7 removed The code changes involve importing modules from the langchain_community package instead of langchain, updating type annotations for content_type and accepts variables, and modifying the value assignment for the extra configuration in the Config class.
source/lambda/online/__functions/functions_utils/retriever/retriever.py 1 added, 2 removed The code changes involve removing an unused import, reordering imports, and updating the import path for the AmazonKnowledgeBasesRetriever from langchain to langchain_community.
source/lambda/online/__functions/lambda_common_tools/rag.py 1 added, 0 removed The code changes add a new line and invoke a Lambda function named "Online_Functions" with the retriever_params as the event_body.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request includes several changes to the codebase. The main modifications are:

  1. Updates to the .viperlightignore file and chat-stack.ts file in the infrastructure and chat components.

  2. Addition of a new directory __functions under source/lambda/online/ with various Python files added, renamed, or marked as errors. These files appear to be related to different tools and functionalities, such as AWS QA tools, common tools, and retail tools.

  3. Modifications to the sm_utils.py file in the llm_bot_dep directory.

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

Motivation and Context

The motivation behind these changes is not entirely clear from the provided information. However, it seems that new functionalities and tools are being added or updated, potentially related to AWS services, common utilities, and retail-specific features.

Dependencies

Based on the file changes, it is likely that this pull request may introduce new dependencies or require updates to existing dependencies. However, without access to the actual code changes and project structure, it is difficult to determine the specific dependencies required.

File Stats Summary

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

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/online/__functions/init.py 11 added, 0 removed This code change imports various tool modules for initializing common, AWS QA, and retail-specific tools in a Python project.
source/lambda/online/__functions/functions_utils/retriever/utils/websearch_retrievers.py 1 added, 1 removed The code change replaces the import of the GoogleSearchAPIWrapper from the langchain library with the import from the langchain_community library.
source/infrastructure/lib/chat/chat-stack.ts 20 added, 20 removed The code changes remove the lambdaOnlineFunctions Lambda function and related configurations by commenting out the relevant lines of code.
source/lambda/online/__functions/_tool_base.py 2 added, 0 removed The code changes include adding an import statement, defining an enum class ToolDefType with a value 'openai', adding fields to the Tool class, and creating an empty ToolManager class.
source/lambda/online/__functions/lambda_common_tools/rag.py 1 added, 0 removed This change adds a line to update the "query" key in the retriever_params dictionary with the value from the state dictionary, using a nested dictionary lookup.
source/lambda/job/dep/llm_bot_dep/sm_utils.py 8 added, 7 removed The code changes involve importing modules from the langchain_community package instead of langchain, updating type annotations for content_type and accepts variables, and modifying the Extra configuration value in the Config class.
.viperlightignore 1 added, 0 removed The code changes include updates to test data, report generation, utility constants, lambda function tests, product information search, data preparation, and documentation.
source/lambda/online/__functions/functions_utils/retriever/retriever.py 1 added, 2 removed The code changes involve removing an unused import, reordering imports, and updating the import path for the AmazonKnowledgeBasesRetriever class.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request includes several changes to the source code, primarily focused on refactoring and reorganizing the langchain_integration module and its submodules. The main changes are:

  1. Renaming and moving various files within the chains submodule to improve code organization and clarity.
  2. Adding a new file tool_calling_chain_api.py to handle API-related functionality.
  3. Modifying existing files related to common utilities, such as constants, logger, prompt handling, and response handling.

The motivation behind these changes is to enhance code maintainability, improve the structure of the project, and potentially introduce new functionality related to API integration.

No external dependencies are introduced with this change.

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: 27, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/online/common_logic/langchain_integration/chains/retail_chains/auto_evaluation_chain.py 1 added, 1 removed The code change updates the import path for the LLMChain class from a relative import to an absolute import within the same package.
source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_conversation_summary_chain.py 1 added, 1 removed The import statement for LLMChain has been updated to use relative imports from the __llm_chain_base module.
source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_tool_calling_chain_claude_xml.py 1 added, 1 removed This code change updates the import path for the LLMChain class from a relative import to an absolute import.
source/lambda/online/common_logic/langchain_integration/chains/intention_chain.py 5 added, 5 removed The code changes involve renaming modules, classes, and updating import statements related to LLM (Large Language Model) models and chat chains for intent recognition tasks.
source/infrastructure/lib/chat/chat-stack.ts 20 added, 20 removed The code changes remove the creation and usage of the lambdaOnlineFunctions Lambda function by commenting out the relevant lines of code.
source/lambda/online/common_logic/langchain_integration/chains/marketing_chains/init.py 4 added, 4 removed This code change fixes a typo in the import statements, changing "Iternlm2Chat" to "Internlm2Chat" for various conversation summary and knowledge QA chains.
.viperlightignore 1 added, 0 removed This commit adds a new test file for common functionality, updates a retail product search lambda function, adds a test data preparation script, and modifies a README file.
source/lambda/online/common_logic/common_utils/response_utils.py 0 added, 1 removed The code change removes an unnecessary blank line and modifies the logic to append each chunk of the response to the answer_str variable.
source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_tool_calling_chain_json.py 1 added, 1 removed This code change updates the import path for the LLMChain class and imports additional modules: Model, GLM4Chat9BChatChain, and get_logger.
source/lambda/online/common_logic/langchain_integration/chains/hyde_chain.py 6 added, 6 removed This code change involves updating import statements, fixing a typo in a class name, and adding new classes for different LLM models (Internlm2Chat20BHydeChain) with specific configurations.
source/lambda/online/common_logic/langchain_integration/chains/stepback_chain.py 5 added, 5 removed The code changes involve refactoring imports, renaming a class from Iternlm2Chat7BStepBackChain to Internlm2Chat7BStepBackChain, and creating a new class Internlm2Chat20BStepBackChain inheriting from Internlm2Chat7BStepBackChain with a different model type.
source/lambda/online/common_logic/common_utils/pydantic_models.py 3 added, 2 removed The code changes include enabling the use of Python enums in Pydantic models, allowing tools to be specified as dictionaries, removing the tools_config field from ChatbotConfig, and adding a method to update the LLM configuration in ChatbotConfig.
source/lambda/job/dep/llm_bot_dep/sm_utils.py 8 added, 7 removed The code changes involve importing modules from the langchain_community package instead of langchain, updating the transform_output method to explicitly define the types of content_type and accepts variables as strings, and modifying the Config class to use the .value attribute when setting the extra field.
source/lambda/online/common_logic/common_utils/logger_utils.py 17 added, 13 removed The code changes introduce a new CloudStreamHandler class that replaces newline characters with carriage returns for better formatting in CloudWatch logs. It also removes the cloud_print_wrapper function and related decorators, and adds a new llm_messages_print_decorator that prints LLM messages before calling the decorated function.
source/lambda/online/common_logic/langchain_integration/chains/rag_chain.py 36 added, 9 removed The code changes involve importing the StrOutputParser from langchain_core, updating imports for Model and LLMChain, modifying the create_chain method to use StrOutputParser and handle streaming, and adding new classes for different LLM models like Claude 3.5, LLaMa, Mistral, Cohere, and Mixtral.
source/lambda/online/common_logic/langchain_integration/chains/tool_calling_chain_claude_xml.py 4 added, 4 removed This code change updates the imports for LLMChain and Model from a different module, modifies the intent_type of the Claude2ToolCallingChain class, and adjusts the default_model_kwargs for the same class.
source/lambda/online/common_logic/langchain_integration/chains/tool_calling_chain_api.py 177 added, 0 removed This code defines a base class Claude2ToolCallingChain and several subclasses for different language models to create chains that can call external tools using LangChain's tool integration. It includes methods for creating chat histories, binding tools with examples, and setting up system prompts with contextual information.
source/lambda/online/common_logic/common_utils/lambda_invoke_utils.py 49 added, 11 removed The code changes introduce a StateContext class to manage the state across threads, add support for AWS credentials from environment variables, handle Lambda response payload parsing, and improve error handling during Lambda invocation. It also includes minor refactoring and formatting changes.
source/lambda/online/common_logic/common_utils/constant.py 13 added, 3 removed The code changes include:
  1. Adding new task types: TOOL_CALLING_XML, TOOL_CALLING_API, MTK_RAG, and INTENTION_ALL_KNOWLEDGE_RETRIEVAL threshold.
  2. Adding new LLM model types: CLAUDE_3_5_HAIKU, CLAUDE_3_5_SONNET_V2, LLAMA3_1_70B_INSTRUCT, LLAMA3_2_90B_INSTRUCT, MISTRAL_LARGE_2407, and COHERE_COMMAND_R_PLUS.
  3. Renaming CHATGPT_35_TURBO to CHATGPT_35_TURBO_0125. |
    | source/lambda/online/common_logic/langchain_integration/chains/conversation_summary_chain.py | 50 added, 13 removed | The code changes involve importing RunnableLambda instead of RunnablePassthrough, updating import paths for Model and LLMChain, renaming classes Iternlm2Chat7BChatChain and Iternlm2Chat20BConversationSummaryChain to Internlm2Chat7BChatChain and Internlm2Chat20BConversationSummaryChain, adding support for enabling/disabling prefill in create_messages_chain, and introducing several new conversation summary chain classes for different models like Claude, Mixtral, Llama, and Cohere. |
    | source/lambda/online/common_logic/langchain_integration/chains/marketing_chains/mkt_conversation_summary.py | 4 added, 4 removed | The code changes involve renaming the class Iternlm2Chat7BChatChain to Internlm2Chat7BChatChain and updating the corresponding class names Iternlm2Chat7BMKTConversationSummaryChain and Iternlm2Chat20BMKTConversationSummaryChain. |
    | source/lambda/online/common_logic/langchain_integration/chains/marketing_chains/mkt_rag_chain.py | 5 added, 5 removed | The code changes involve fixing a typo in the import statement, changing the task type from RAG to MTK_RAG, renaming the class names from "Iternlm2Chat7BKnowledgeQaChain" to "Internlm2Chat7BKnowledgeQaChain" and "Iternlm2Chat20BKnowledgeQaChain" to "Internlm2Chat20BKnowledgeQaChain". |
    | source/lambda/online/common_logic/langchain_integration/chains/chat_chain.py | 39 added, 17 removed | The code changes involve updates to the LLMChain and Claude2ChatChain classes, including adding new model types like Claude 3.5 Sonnet, Llama 3.1/3.2 Instruct, Mistral Large, Cohere Command R+, and updating the ChatGPT-3.5 Turbo model ID. It also refactors the chain creation logic for streaming and non-streaming responses. |
    | source/lambda/online/common_logic/langchain_integration/chains/init.py | 206 added, 0 removed | This code defines a metaclass LLMChainMeta and a base class LLMChain for creating different types of language model chains. It provides a centralized way to register and retrieve specific chain implementations based on model ID and intent type. The code also includes functions to dynamically import various chain modules, such as chat chains, conversation summary chains, intention recognition chains, and others, based on the provided intent type. The mapping between intent types and module import functions is stored in the CHAIN_MODULE_LOAD_FN_MAP dictionary. |
    | source/lambda/online/common_logic/langchain_integration/chains/query_rewrite_chain.py | 15 added, 7 removed | This code change introduces new classes for query rewrite chains using different Anthropic models like Claude-3-Sonnet, Claude-3.5-Sonnet, Claude-3.5-Sonnet-V2, Claude-3.5-Haiku, and Internlm2Chat7B and Internlm2Chat20B models, along with some import and naming corrections. |
    | source/lambda/online/common_logic/langchain_integration/chains/translate_chain.py | 3 added, 3 removed | This code change renames the class Iternlm2Chat7BChatChain to Internlm2Chat7BChatChain and creates a new class Internlm2Chat20BTranslateChain that inherits from Internlm2Chat7BTranslateChain. |
    | source/lambda/online/common_logic/common_utils/prompt_utils.py | 176 added, 39 removed | The code changes involve updating the list of LLM model types to include additional models like CLAUDE_3_5_HAIKU, CLAUDE_3_5_SONNET_V2, LLAMA3_1_70B_INSTRUCT, MISTRAL_LARGE_2407, and COHERE_COMMAND_R_PLUS. It also registers new prompt templates for conversation summary, XML agent prompts, and API agent prompts to support these models. |
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request includes several changes related to the integration of the LangChain library and the refactoring of the project structure. The main changes are:

  1. Reorganization of the langchain_integration module and its submodules, including renaming and moving files.
  2. Addition of new files for various LangChain chains, such as conversation summary, query rewriting, and retail-specific chains.
  3. Modifications to existing utility files for handling prompts, responses, constants, and logging.
  4. Updates to infrastructure and deployment-related files.
  5. Removal of some image files that are no longer needed.

These changes aim to improve the overall organization and maintainability of the codebase, as well as introduce new features and functionalities through the integration of LangChain.

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: 25, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_tool_calling_chain_claude_xml.py 1 added, 1 removed The code change updates the import statement for the LLMChain module, changing from a relative import to an absolute import.
source/lambda/online/common_logic/langchain_integration/chains/retail_chains/auto_evaluation_chain.py 1 added, 1 removed The code change updates the import statement for the LLMChain class from a relative path to an absolute path.
source/lambda/job/dep/requirements.txt 2 added, 1 removed The code change adds the langchain_community library version 0.3.5 to the list of dependencies.
source/infrastructure/lib/knowledge-base/knowledge-base-stack.ts 1 added, 1 removed The code change updates the list of additional Python modules installed in the AWS Lambda function by adding the langchain_community==0.3.5 package.
.viperlightignore 1 added, 0 removed This commit adds a new test file for common functionality, updates test data, generates reports, modifies product information search, prepares test data, and updates the README.
source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_tool_calling_chain_json.py 1 added, 1 removed The code change updates the import path for the LLMChain module from a relative parent directory to the current directory.
source/lambda/online/common_logic/langchain_integration/chains/marketing_chains/init.py 4 added, 4 removed This code change fixes a typo by renaming "Iternlm2Chat7B" and "Iternlm2Chat20B" to "Internlm2Chat7B" and "Internlm2Chat20B" respectively.
source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_conversation_summary_chain.py 1 added, 1 removed This change updates the import path for the LLMChain module from a relative import to an absolute import within the same package.
source/lambda/online/common_logic/langchain_integration/chains/marketing_chains/mkt_conversation_summary.py 4 added, 4 removed This code change renames the class Iternlm2Chat7BChatChain to Internlm2Chat7BChatChain and updates related class names accordingly.
source/lambda/online/common_logic/common_utils/logger_utils.py 17 added, 13 removed The code changes introduce a new CloudStreamHandler class that replaces newline characters with carriage returns for better log formatting in CloudWatch, and remove the cloud_print_wrapper function. It also adds a new llm_messages_print_decorator function to print LLM messages before executing a decorated function.
source/lambda/online/common_logic/langchain_integration/chains/hyde_chain.py 6 added, 6 removed This code change renames some imports and class names related to LLM (Language Model) chains and models, and introduces new classes for Hyde chains with different model types (Internlm2Chat7BHydeChain and Internlm2Chat20BHydeChain) with specific meta-instructions.
source/lambda/online/common_logic/langchain_integration/chains/intention_chain.py 5 added, 5 removed The code changes involve refactoring imports, renaming classes, and adding a new class for a different model size (20B) while inheriting from the base class for the 7B model.
source/infrastructure/lib/chat/chat-stack.ts 20 added, 20 removed The code changes comment out the creation and usage of the lambdaOnlineFunctions Lambda function, which was previously responsible for various tasks related to online functions and utilities.
source/lambda/online/common_logic/langchain_integration/chains/query_rewrite_chain.py 15 added, 7 removed This code change introduces new classes for query rewriting using different Anthropic language models, including Claude 3.5 Sonnet, Claude 3.5 Sonnet V2, Claude 3.5 Haiku, InternLM2 Chat 7B, and InternLM2 Chat 20B. It also updates import statements and fixes some typos.
source/lambda/online/common_logic/langchain_integration/chains/marketing_chains/mkt_rag_chain.py 5 added, 5 removed The code changes update the class names from "Iternlm2Chat7BChatChain" to "Internlm2Chat7BChatChain", register the prompt template for the task type "LLMTaskType.MTK_RAG" instead of "LLMTaskType.RAG", and create two new classes "Internlm2Chat7BKnowledgeQaChain" and "Internlm2Chat20BKnowledgeQaChain" for knowledge-based question answering with different model sizes.
source/lambda/online/common_logic/langchain_integration/chains/conversation_summary_chain.py 50 added, 13 removed The code changes involve refactoring imports, removing unused imports, modifying class inheritance, adding new model types for conversation summary chains, enabling an option to include or exclude a prefill message in the conversation prompt template, and modifying how the conversation summary content is returned by stripping the prefill message.
source/lambda/online/common_logic/common_utils/pydantic_models.py 3 added, 2 removed The code changes include enabling the use of enum values in Pydantic models, allowing arbitrary data in some models, updating the type annotations for the 'tools' field in AgentConfig, and commenting out the 'tools_config' field in ChatbotConfig along with adding a method to update the LLM configuration.
source/lambda/job/dep/llm_bot_dep/sm_utils.py 8 added, 7 removed The code changes involve importing modules from the langchain_community package instead of langchain, updating type annotations for content_type and accepts variables, and changing the value assignment for the extra attribute in the Config class.
source/lambda/online/common_logic/common_utils/lambda_invoke_utils.py 49 added, 11 removed The code changes include the following:
  1. Added import statements for os and threading modules.

  2. Introduced a StateContext class to manage the current state in a thread-safe manner.

  3. Modified the LambdaInvoker class to use model_validator instead of root_validator, and handle region_name from environment variable.

  4. Updated invoke_with_lambda function to handle response body parsing.

  5. Added StateContext context manager in the wrapper function to set and clear the current state. |
    | source/lambda/online/common_logic/common_utils/response_utils.py | 0 added, 1 removed | The code change removes an empty line and modifies the logic to append the chunk to the answer_str variable instead of assigning it. |
    | source/lambda/online/common_logic/langchain_integration/chains/chat_chain.py | 41 added, 19 removed | This code change updates the implementation of various chat chains for different language models, including Claude, Mixtral, LLaMa, Mistral, Cohere, Baichuan, InternLM, Qwen, and ChatGPT. It introduces new chat chain classes for models like Claude 3.5 Sonnet V2, Claude 3.5 Haiku, LLaMa 3.1 70B Instruct, LLaMa 3.2 90B Instruct, Mistral Large 2407, and Cohere Command R Plus. It also refactors the create_chain method to use StrOutputParser and streamline the streaming and non-streaming behavior. |
    | source/lambda/online/common_logic/langchain_integration/chains/init.py | 206 added, 0 removed | This code defines a metaclass LLMChainMeta and a base class LLMChain for managing different types of language model chains. It provides a centralized way to register and retrieve specific chain implementations based on the model ID and intent type. The code also includes functions to dynamically import various chain modules for different tasks, such as chat, conversation summary, intent recognition, retrieval-augmented generation (RAG), translation, marketing-related chains, step-back prompting, query rewriting, tool calling, and auto-evaluation chains. |
    | source/lambda/online/common_logic/common_utils/constant.py | 14 added, 5 removed | The code changes include:

  6. Added new LLM task types: TOOL_CALLING_XML, TOOL_CALLING_API, MTK_RAG.

  7. Added new LLM model types: CLAUDE_3_5_HAIKU, CLAUDE_3_5_SONNET_V2, LLAMA3_1_70B_INSTRUCT, LLAMA3_2_90B_INSTRUCT, MISTRAL_LARGE_2407, COHERE_COMMAND_R_PLUS.

  8. Added new model type: CHATGPT_35_TURBO_0125.

  9. Added new threshold: INTENTION_ALL_KNOWLEDGE_RETRIEVAL. |
    | source/lambda/online/common_logic/langchain_integration/chains/rag_chain.py | 36 added, 9 removed | The code changes include:

  10. Importing StrOutputParser from langchain_core.output_parsers.

  11. Updating import paths for Model and LLMChain.

  12. Adding a StrOutputParser to the chain and handling streaming/non-streaming cases.

  13. Introducing new LLMChain classes for various models like Claude 3.5 (Sonnet and Haiku), LLaMa 3.1/3.2, Mistral Large, Cohere Command R+, and Mixtral 8x7b. |
    | source/lambda/online/common_logic/common_utils/prompt_utils.py | 176 added, 39 removed | The code changes:

  1. Imported BaseModel and Field from pydantic instead of langchain.pydantic_v1
  2. Added new LLM model types to the EXPORT_MODEL_IDS list
  3. Registered prompt templates for RAG, conversation summary, and XML/API-based tool calling tasks for various LLM models
  4. Added system prompts and guidelines for XML and API-based tool calling agents |

@11zhouxuan 11zhouxuan requested a review from NingLu November 12, 2024 08:10
@11zhouxuan 11zhouxuan changed the title Add other bedrock models refactor: Add other bedrock models Nov 13, 2024
from langchain.llms.sagemaker_endpoint import LLMContentHandler, SagemakerEndpoint
from langchain.embeddings import SagemakerEndpointEmbeddings, BedrockEmbeddings
from langchain.embeddings.sagemaker_endpoint import EmbeddingsContentHandler
from langchain_community.llms import SagemakerEndpoint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does glue job's requirements.txt need to be update as well?
langchain -> langchain_community

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, need to add "langchain_community" to it's requirements.txt

@@ -22,8 +22,11 @@ export const LLM_BOT_MODEL_LIST = [
];

export const LLM_BOT_COMMON_MODEL_LIST = [
'anthropic.claude-3-sonnet-20240229-v1:0',
'anthropic.claude-3-haiku-20240307-v1:0',
'anthropic.claude-3-5-sonnet-20240620-v1:0',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some user are still using claude 3,
we can provide them both claude 3 and claude 3.5
would you add claude 3 sonnet and haiku back?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified

@@ -2,6 +2,7 @@
import traceback
import uuid
from datetime import datetime, timezone
import traceback
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate with L2, two traceback imported

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


from common_logic.common_utils.chatbot_utils import ChatbotManager
from common_logic.common_utils.constant import (
IndexType,
LLMTaskType,
SceneType,
ToolRuningMode,
GUIDE_INTENTION_NOT_FOUND,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate with L13, keep only one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -179,4 +188,5 @@ class KBType(Enum):

class Threshold(ConstantBase):
QQ_IN_RAG_CONTEXT = 0.5
INTENTION_ALL_KNOWLEDGAE_RETRIEVE = 0.4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo issue,
KNOWLEDGE_RETRIEVAL

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good practice to add __ or _ in a folder name? never see this before in popular repos

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means the files should be retired, i have removed those files.



AGENT_SYSTEM_PROMPT_COHERE = """\
## Task & Context
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to have in the furture: move the prompt templates into a config or constant file, separate templates with codes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, good suggestion.

Claude2ChatChain,
Claude21ChatChain,
ClaudeInstanceChatChain,
Iternlm2Chat7BChatChain,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo issue
InternLM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.

@NingLu NingLu merged commit 114ed47 into dev Nov 13, 2024
6 checks passed
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.

2 participants