feat: support query rewrite for first sentence #436
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)
Description
This pull request includes modifications to various files in the
common_logic
andlangchain_integration
directories. The changes primarily involve refactoring and optimizing the existing codebase, with a focus on improving code readability, maintainability, and performance.Several utility functions and classes have been updated to enhance their functionality and address potential issues or inefficiencies. Additionally, some of the LangChain integration components, such as chains and chat models, have been modified to align with the latest best practices and requirements.
One file,
source/lambda/online/common_logic/langchain_integration/chains/stepback_chain.py
, has encountered an error during the changes. This issue will need to be addressed and resolved before merging the pull request.Type of change
File Stats Summary
File number involved in this PR: 29, unfold to see the details:
The file changes summary is as follows:
get_chain
function, which is a minor formatting adjustment.Internlm2Chat7BMKTConversationSummaryChain
andClaude2MKTConversationSummaryChain
for summarizing conversations, along with modifications to the prompt creation and chain creation methods.Claude2AutoEvaluationChain
that inherits fromClaude2ChatChain
, and creating subclasses for different Claude model variants to perform auto-evaluation tasks.QueryRewriteConfig
class that inherits fromLLMConfig
and adds arewrite_first_message
boolean field. TheQueryProcessConfig
class now usesQueryRewriteConfig
instead ofLLMConfig
for theconversation_query_rewrite_config
field. Additionally, logging statements are added to theupdate_retrievers
method, and input validation is added for thetask_name
parameter.Added a new exception class
WebsocketClientError
.Fixed indentation in the
write_chat_history_to_ddb
function.Formatted the return dictionaries in
api_response
andstream_response
functions.Added type hints for function parameters.
Handled a potential
KeyError
by usingevent_body.get("stream", True)
inprocess_response
. || source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_conversation_summary_chain.py | 28 added, 24 removed | This code defines several chains for summarizing retail conversations using different language models. It imports necessary modules, defines templates for prompts, and creates custom chains that inherit from base LLMChain classes. The chains are designed to process chat histories and generate summaries tailored for retail scenarios. |
| source/lambda/online/common_logic/langchain_integration/chains/rag_chain.py | 24 added, 24 removed | This code change introduces several new classes for different language models and RAG (Retrieval-Augmented Generation) chains, including Baichuan2Chat13B4BitsChatChain, Qwen2Instruct7BChatChain, GLM4Chat9BChatChain, and their respective RAG chain implementations. It also adds new Claude and Llama model variants for specific tasks like sonnet generation and instruction following. |
| source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_tool_calling_chain_claude_xml.py | 79 added, 83 removed | The code changes appear to be related to formatting, imports, and modifications to the Claude2RetailToolCallingChain and Mixtral8x7bRetailToolCallingChain classes. Specifically:
Formatting changes to imports and string literals.
Modifications to the parse_function_calls_from_ai_message method in Mixtral8x7bRetailToolCallingChain.
Addition of chat_history_to_string and generate_chat_history methods in Mixtral8x7bRetailToolCallingChain.
Changes to default model parameters for Mixtral8x7bRetailToolCallingChain. |
| source/lambda/online/common_logic/langchain_integration/chains/tool_calling_chain_claude_xml.py | 59 added, 56 removed | The code changes include:
Minor formatting and import changes.
Updating the SYSTEM_MESSAGE_PROMPT string to use f-strings and improve readability.
Adding type hints to function parameters and return values.
Refactoring the format_fewshot_examples function for better code structure.
Adding docstrings to some functions for better documentation. |
| source/lambda/online/common_logic/langchain_integration/chains/intention_chain.py | 6 added, 4 removed | The code changes involve importing LLMModelType and LLMTaskType from common_logic.common_utils.constant, fixing a typo in the variable name exmaple_template, and formatting the string interpolation in create_few_shot_example_string to improve readability. |
| source/lambda/online/common_logic/langchain_integration/chains/conversation_summary_chain.py | 45 added, 43 removed | The code changes involve importing necessary modules, defining classes for conversation summary chains with different language models (e.g., InternLM2Chat, Claude, Cohere, Qwen2Instruct, GLM), and creating methods for generating prompts, formatting conversations, and creating message chains. |
| source/lambda/online/common_logic/common_utils/websocket_utils.py | 3 added, 2 removed | The code changes involve adding a blank line for readability, reformatting the boto3 client initialization for better code style, and removing an unnecessary blank line at the end of the file. |
| source/lambda/online/common_logic/langchain_integration/chains/retail_chains/retail_tool_calling_chain_json.py | 101 added, 104 removed | The code changes appear to be related to creating a tool-calling chain for a retail chatbot assistant. The main modifications include:
Importing a new chat chain class
Qwen2Instruct7BChatChain
.Adding new classes
GLM4Chat9BRetailToolCallingChain
,Qwen2Instruct72BRetailToolCallingChain
,Qwen2Instruct7BRetailToolCallingChain
, andQwen15Instruct32BRetailToolCallingChain
for different language models.Defining methods to convert OpenAI function tools to GLM format, format few-shot examples, create system prompts, and create chat histories.
Implementing logic to parse function calls from AI messages and create chains with specific model configurations. |