From 90f8d588343abe5b81445270d8be9bea8d98bdbb Mon Sep 17 00:00:00 2001 From: Ning Date: Thu, 11 Apr 2024 15:56:23 +0800 Subject: [PATCH] fix: llm issue --- .../utils/llm_utils/llm_chains/__init__.py | 105 ++++++++++-------- source/panel/app.py | 4 +- source/panel/evaluator/README.md | 2 +- source/panel/evaluator/ui.py | 6 +- source/sample/script/README.md | 2 +- 5 files changed, 67 insertions(+), 52 deletions(-) diff --git a/source/lambda/executor/utils/llm_utils/llm_chains/__init__.py b/source/lambda/executor/utils/llm_utils/llm_chains/__init__.py index 90ecfd06..1aeef6b0 100644 --- a/source/lambda/executor/utils/llm_utils/llm_chains/__init__.py +++ b/source/lambda/executor/utils/llm_utils/llm_chains/__init__.py @@ -1,75 +1,90 @@ +from .llm_chain_base import LLMChain from .chat_chain import ( - Baichuan2Chat13B4BitsChatChain, Claude2ChatChain, - Claude3HaikuChatChain, - Claude3SonnetChatChain, Claude21ChatChain, ClaudeInstanceChatChain, Iternlm2Chat7BChatChain, Iternlm2Chat20BChatChain, + Baichuan2Chat13B4BitsChatChain, + Claude3HaikuChatChain, + Claude3SonnetChatChain ) + from .conversation_summary_chain import ( + Iternlm2Chat7BConversationSummaryChain, + ClaudeInstanceConversationSummaryChain, + Claude21ConversationSummaryChain, Claude3HaikuConversationSummaryChain, Claude3SonnetConversationSummaryChain, - Claude21ConversationSummaryChain, - ClaudeInstanceConversationSummaryChain, - Iternlm2Chat7BConversationSummaryChain, - Iternlm2Chat20BConversationSummaryChain, -) -from .hyde_chain import ( - Claude2HydeChain, - Claude3HaikuHydeChain, - Claude3SonnetHydeChain, - Claude21HydeChain, - ClaudeInstanceHydeChain, - Iternlm2Chat7BHydeChain, - Iternlm2Chat20BHydeChain, + Iternlm2Chat20BConversationSummaryChain ) + from .intention_chain import ( + Claude21IntentRecognitionChain, Claude2IntentRecognitionChain, + ClaudeInstanceIntentRecognitionChain, Claude3HaikuIntentRecognitionChain, Claude3SonnetIntentRecognitionChain, - Claude21IntentRecognitionChain, - ClaudeInstanceIntentRecognitionChain, Iternlm2Chat7BIntentRecognitionChain, Iternlm2Chat20BIntentRecognitionChain, + ) -from .llm_chain_base import LLMChain -from .mkt_conversation_summary import ( - Claude2MKTConversationSummaryChain, - Claude3HaikuMKTConversationSummaryChain, - Claude3SonnetMKTConversationSummaryChain, - Claude21MKTConversationSummaryChain, - ClaudeInstanceMKTConversationSummaryChain, - Iternlm2Chat7BMKTConversationSummaryChain, - Iternlm2Chat20BMKTConversationSummaryChain, -) -from .query_rewrite_chain import ( - Claude2QueryRewriteChain, - Claude3HaikuQueryRewriteChain, - Claude3SonnetQueryRewriteChain, - Claude21QueryRewriteChain, - ClaudeInstanceQueryRewriteChain, - Iternlm2Chat7BQueryRewriteChain, - Iternlm2Chat20BQueryRewriteChain, -) + from .rag_chain import ( - Baichuan2Chat13B4BitsKnowledgeQaChain, + Claude21RagLLMChain, Claude2RagLLMChain, + ClaudeInstanceRAGLLMChain, Claude3HaikuRAGLLMChain, Claude3SonnetRAGLLMChain, - Claude21RagLLMChain, - ClaudeInstanceRAGLLMChain, + Baichuan2Chat13B4BitsKnowledgeQaChain, Iternlm2Chat7BKnowledgeQaChain, - Iternlm2Chat20BKnowledgeQaChain, + Iternlm2Chat20BKnowledgeQaChain ) + + +from .translate_chain import ( + Iternlm2Chat7BTranslateChain, + Iternlm2Chat20BTranslateChain +) + + +from .mkt_conversation_summary import ( + Claude21MKTConversationSummaryChain, + ClaudeInstanceMKTConversationSummaryChain, + Claude2MKTConversationSummaryChain, + Claude3HaikuMKTConversationSummaryChain, + Claude3SonnetMKTConversationSummaryChain, + Iternlm2Chat7BMKTConversationSummaryChain, + Iternlm2Chat20BMKTConversationSummaryChain +) + from .stepback_chain import ( + Claude21StepBackChain, + ClaudeInstanceStepBackChain, Claude2StepBackChain, Claude3HaikuStepBackChain, Claude3SonnetStepBackChain, - Claude21StepBackChain, - ClaudeInstanceStepBackChain, Iternlm2Chat7BStepBackChain, - Iternlm2Chat20BStepBackChain, + Iternlm2Chat20BStepBackChain +) + + +from .hyde_chain import ( + Claude21HydeChain, + Claude2HydeChain, + Claude3HaikuHydeChain, + Claude3SonnetHydeChain, + ClaudeInstanceHydeChain, + Iternlm2Chat20BHydeChain, + Iternlm2Chat7BHydeChain +) + +from .query_rewrite_chain import ( + Claude21QueryRewriteChain, + Claude2QueryRewriteChain, + ClaudeInstanceQueryRewriteChain, + Claude3HaikuQueryRewriteChain, + Claude3SonnetQueryRewriteChain, + Iternlm2Chat20BQueryRewriteChain, + Iternlm2Chat7BQueryRewriteChain ) -from .translate_chain import Iternlm2Chat7BTranslateChain, Iternlm2Chat20BTranslateChain diff --git a/source/panel/app.py b/source/panel/app.py index 5de930ce..e0575c66 100644 --- a/source/panel/app.py +++ b/source/panel/app.py @@ -145,7 +145,7 @@ def pipeline_tab(): job_runs_container += (f" Duration: {job_run.get('ExecutionTime', 'N/A')} seconds\n") st.text_area('Running AWS Glue Jobs in total: ' + str(total_job_runs), value=job_runs_container, height=200, max_chars=None) - # sub pannel to query and search the embedding in AOS + # Sub panel to query and search the embedding in AOS st.subheader('Query and Search AOS') query = st.text_input('Input your query body here', value='{"aos_index": "chatbot-index", "query": {"operation": "match_all", "match_all": {}}}') # send button to trigger the request sending to the endpoint with query as request body @@ -203,7 +203,7 @@ def main(): elif page == "LLM Bot": llm_bot_tab() - # using libary and OpenAI for local testing, comment for now + # using library and OpenAI for local testing, comment for now # if pdf is not None: # pdf_reader = PdfReader(pdf) diff --git a/source/panel/evaluator/README.md b/source/panel/evaluator/README.md index 3376819f..5721c028 100644 --- a/source/panel/evaluator/README.md +++ b/source/panel/evaluator/README.md @@ -1,4 +1,4 @@ -Excute the following commands to setup local Amazon Open Search running on docker. +Execute the following commands to setup local Amazon Open Search running on docker. ''' docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:latest ''' diff --git a/source/panel/evaluator/ui.py b/source/panel/evaluator/ui.py index 0fb6ace1..5b4824c9 100644 --- a/source/panel/evaluator/ui.py +++ b/source/panel/evaluator/ui.py @@ -177,7 +177,7 @@ def run_evaluation(chain, retriever, eval_set, grade_prompt, retriever_type, num start_time = time.time() # Get docs - if retriever_type == "Faiss retriver": + if retriever_type == "Faiss retriever": docs = retriever.similarity_search(query=data["question"],k=num_neighbors,filter=metadata_filter) elif retriever_type == "CSDC retriever": docs = retriever.similarity_search(query=data["question"],k=num_neighbors,filter=metadata_filter) @@ -231,7 +231,7 @@ def run_evaluation(chain, retriever, eval_set, grade_prompt, retriever_type, num index=1) retriever_type = st.radio("`Choose retriever`", - ("Faiss retriver", + ("Faiss retriever", "CSDC retriever",), index=0) @@ -288,7 +288,7 @@ def run_evaluation(chain, retriever, eval_set, grade_prompt, retriever_type, num # Make LLM llm = make_llm(model) - # Make retriver + # Make retriever retriever = make_retriever(retriever_type,embeddings) # Make chain diff --git a/source/sample/script/README.md b/source/sample/script/README.md index 59a122ce..8346b8ad 100644 --- a/source/sample/script/README.md +++ b/source/sample/script/README.md @@ -22,7 +22,7 @@ aws ec2 describe-key-pairs --query 'KeyPairs[*].{Name:KeyName}' --output text aws ec2 run-instances --image-id ami-01cb61d12413ba783 --count 1 --instance-type t2.micro --key-name us-west-2 --security-group-ids sg-0ceb6e950b89e8f69 --subnet-id subnet-b42915ff --user-data file://nginx.sh --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=ec2Endpoint}]' --query 'Instances[*].{ID:InstanceId,IP:PublicIpAddress}' --output text ``` -## 2.2. lanuch the flask app +## 2.2. launch the flask app ```bash export FLASK_APP=app.py # Replace 'app.py' with the name of your Flask app file if it's different