From 5eb3d2869fc646c3529037321f1a1ad4ba19160e Mon Sep 17 00:00:00 2001 From: minmin-intel Date: Sun, 3 Nov 2024 17:17:19 -0800 Subject: [PATCH] Update AgentQnA example for v1.1 release (#885) Signed-off-by: minmin-intel Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- AgentQnA/README.md | 76 +++++++++++++------ .../docker_compose/intel/cpu/xeon/README.md | 3 + .../intel/cpu/xeon/compose_openai.yaml | 8 +- .../cpu/xeon/launch_agent_service_openai.sh | 2 +- .../intel/hpu/gaudi/compose.yaml | 39 ++-------- .../gaudi/launch_agent_service_tgi_gaudi.sh | 16 +--- .../intel/hpu/gaudi/launch_tgi_gaudi.sh | 25 ++++++ .../intel/hpu/gaudi/tgi_gaudi.yaml | 30 ++++++++ ..._build_images.sh => step1_build_images.sh} | 0 ..._tool.sh => step2_start_retrieval_tool.sh} | 0 ...ep3_ingest_data_and_validate_retrieval.sh} | 0 ...step4_launch_and_validate_agent_openai.sh} | 0 ...=> step4_launch_and_validate_agent_tgi.sh} | 31 ++++++-- AgentQnA/tests/test.py | 25 ++++++ AgentQnA/tests/test_compose_on_gaudi.sh | 24 ++++-- AgentQnA/tools/supervisor_agent_tools.yaml | 2 +- AgentQnA/tools/worker_agent_tools.py | 35 ++++++--- 17 files changed, 212 insertions(+), 104 deletions(-) create mode 100644 AgentQnA/docker_compose/intel/cpu/xeon/README.md create mode 100644 AgentQnA/docker_compose/intel/hpu/gaudi/launch_tgi_gaudi.sh create mode 100644 AgentQnA/docker_compose/intel/hpu/gaudi/tgi_gaudi.yaml rename AgentQnA/tests/{1_build_images.sh => step1_build_images.sh} (100%) rename AgentQnA/tests/{2_start_retrieval_tool.sh => step2_start_retrieval_tool.sh} (100%) rename AgentQnA/tests/{3_ingest_data_and_validate_retrieval.sh => step3_ingest_data_and_validate_retrieval.sh} (100%) rename AgentQnA/tests/{4_launch_and_validate_agent_openai.sh => step4_launch_and_validate_agent_openai.sh} (100%) rename AgentQnA/tests/{4_launch_and_validate_agent_tgi.sh => step4_launch_and_validate_agent_tgi.sh} (64%) create mode 100644 AgentQnA/tests/test.py diff --git a/AgentQnA/README.md b/AgentQnA/README.md index e6cfaf7c9..9c351a856 100644 --- a/AgentQnA/README.md +++ b/AgentQnA/README.md @@ -81,17 +81,13 @@ flowchart LR 3. Hierarchical agent can further improve performance. Expert worker agents, such as retrieval agent, knowledge graph agent, SQL agent, etc., can provide high-quality output for different aspects of a complex query, and the supervisor agent can aggregate the information together to provide a comprehensive answer. -### Roadmap +## Deployment with docker -- v0.9: Worker agent uses open-source websearch tool (duckduckgo), agents use OpenAI GPT-4o-mini as llm backend. -- v1.0: Worker agent uses OPEA retrieval megaservice as tool. -- v1.0 or later: agents use open-source llm backend. -- v1.1 or later: add safeguards +1. Build agent docker image -## Getting started + Note: this is optional. The docker images will be automatically pulled when running the docker compose commands. This step is only needed if pulling images failed. -1. Build agent docker image
- First, clone the opea GenAIComps repo + First, clone the opea GenAIComps repo. ``` export WORKDIR= @@ -106,35 +102,63 @@ flowchart LR docker build -t opea/agent-langchain:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/agent/langchain/Dockerfile . ``` -2. Launch tool services
- In this example, we will use some of the mock APIs provided in the Meta CRAG KDD Challenge to demonstrate the benefits of gaining additional context from mock knowledge graphs. - - ``` - docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0 - ``` - -3. Set up environment for this example
- First, clone this repo +2. Set up environment for this example
+ First, clone this repo. ``` cd $WORKDIR git clone https://github.com/opea-project/GenAIExamples.git ``` - Second, set up env vars + Second, set up env vars. ``` export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/ - # optional: OPANAI_API_KEY + # for using open-source llms + export HUGGINGFACEHUB_API_TOKEN= + export HF_CACHE_DIR= #so that no need to redownload every time + + # optional: OPANAI_API_KEY if you want to use OpenAI models export OPENAI_API_KEY= ``` -4. Launch agent services
- The configurations of the supervisor agent and the worker agent are defined in the docker-compose yaml file. We currently use openAI GPT-4o-mini as LLM, and we plan to add support for llama3.1-70B-instruct (served by TGI-Gaudi) in a subsequent release. - To use openai llm, run command below. +3. Deploy the retrieval tool (i.e., DocIndexRetriever mega-service) + + First, launch the mega-service. + + ``` + cd $WORKDIR/GenAIExamples/AgentQnA/retrieval_tool + bash launch_retrieval_tool.sh + ``` + + Then, ingest data into the vector database. Here we provide an example. You can ingest your own data. + + ``` + bash run_ingest_data.sh + ``` + +4. Launch other tools.
+ In this example, we will use some of the mock APIs provided in the Meta CRAG KDD Challenge to demonstrate the benefits of gaining additional context from mock knowledge graphs. + + ``` + docker run -d -p=8080:8000 docker.io/aicrowd/kdd-cup-24-crag-mock-api:v0 + ``` + +5. Launch agent services
+ We provide two options for `llm_engine` of the agents: 1. open-source LLMs, 2. OpenAI models via API calls. + + To use open-source LLMs on Gaudi2, run commands below. + + ``` + cd $WORKDIR/GenAIExamples/AgentQnA/docker_compose/intel/hpu/gaudi + bash launch_tgi_gaudi.sh + bash launch_agent_service_tgi_gaudi.sh + ``` + + To use OpenAI models, run commands below. ``` - cd docker_compose/intel/cpu/xeon + cd $WORKDIR/GenAIExamples/AgentQnA/docker_compose/intel/cpu/xeon bash launch_agent_service_openai.sh ``` @@ -143,10 +167,12 @@ flowchart LR First look at logs of the agent docker containers: ``` -docker logs docgrader-agent-endpoint +# worker agent +docker logs rag-agent-endpoint ``` ``` +# supervisor agent docker logs react-agent-endpoint ``` @@ -170,4 +196,4 @@ curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: app ## How to register your own tools with agent -You can take a look at the tools yaml and python files in this example. For more details, please refer to the "Provide your own tools" section in the instructions [here](https://github.com/opea-project/GenAIComps/tree/main/comps/agent/langchain/README.md#5-customize-agent-strategy). +You can take a look at the tools yaml and python files in this example. For more details, please refer to the "Provide your own tools" section in the instructions [here](https://github.com/opea-project/GenAIComps/tree/main/comps/agent/langchain/README.md). diff --git a/AgentQnA/docker_compose/intel/cpu/xeon/README.md b/AgentQnA/docker_compose/intel/cpu/xeon/README.md new file mode 100644 index 000000000..852a0476c --- /dev/null +++ b/AgentQnA/docker_compose/intel/cpu/xeon/README.md @@ -0,0 +1,3 @@ +# Deployment on Xeon + +We deploy the retrieval tool on Xeon. For LLMs, we support OpenAI models via API calls. For instructions on using open-source LLMs, please refer to the deployment guide [here](../../../../README.md). diff --git a/AgentQnA/docker_compose/intel/cpu/xeon/compose_openai.yaml b/AgentQnA/docker_compose/intel/cpu/xeon/compose_openai.yaml index bac5bbc62..837f2a087 100644 --- a/AgentQnA/docker_compose/intel/cpu/xeon/compose_openai.yaml +++ b/AgentQnA/docker_compose/intel/cpu/xeon/compose_openai.yaml @@ -2,11 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 services: - worker-docgrader-agent: + worker-rag-agent: image: opea/agent-langchain:latest - container_name: docgrader-agent-endpoint + container_name: rag-agent-endpoint volumes: - - ${WORKDIR}/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/ - ${TOOLSET_PATH}:/home/user/tools/ ports: - "9095:9095" @@ -36,8 +35,9 @@ services: supervisor-react-agent: image: opea/agent-langchain:latest container_name: react-agent-endpoint + depends_on: + - worker-rag-agent volumes: - - ${WORKDIR}/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/ - ${TOOLSET_PATH}:/home/user/tools/ ports: - "9090:9090" diff --git a/AgentQnA/docker_compose/intel/cpu/xeon/launch_agent_service_openai.sh b/AgentQnA/docker_compose/intel/cpu/xeon/launch_agent_service_openai.sh index 6c2094cc8..f35e60fd1 100644 --- a/AgentQnA/docker_compose/intel/cpu/xeon/launch_agent_service_openai.sh +++ b/AgentQnA/docker_compose/intel/cpu/xeon/launch_agent_service_openai.sh @@ -7,7 +7,7 @@ export recursion_limit_worker=12 export recursion_limit_supervisor=10 export model="gpt-4o-mini-2024-07-18" export temperature=0 -export max_new_tokens=512 +export max_new_tokens=4096 export OPENAI_API_KEY=${OPENAI_API_KEY} export WORKER_AGENT_URL="http://${ip_address}:9095/v1/chat/completions" export RETRIEVAL_TOOL_URL="http://${ip_address}:8889/v1/retrievaltool" diff --git a/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml index 5200f757e..6a9d0b465 100644 --- a/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml +++ b/AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml @@ -2,37 +2,9 @@ # SPDX-License-Identifier: Apache-2.0 services: - tgi-server: - image: ghcr.io/huggingface/tgi-gaudi:2.0.5 - container_name: tgi-server - ports: - - "8085:80" - volumes: - - ${HF_CACHE_DIR}:/data - environment: - no_proxy: ${no_proxy} - http_proxy: ${http_proxy} - https_proxy: ${https_proxy} - HUGGING_FACE_HUB_TOKEN: ${HUGGINGFACEHUB_API_TOKEN} - HF_HUB_DISABLE_PROGRESS_BARS: 1 - HF_HUB_ENABLE_HF_TRANSFER: 0 - HABANA_VISIBLE_DEVICES: all - OMPI_MCA_btl_vader_single_copy_mechanism: none - PT_HPU_ENABLE_LAZY_COLLECTIVES: true - ENABLE_HPU_GRAPH: true - LIMIT_HPU_GRAPH: true - USE_FLASH_ATTENTION: true - FLASH_ATTENTION_RECOMPUTE: true - runtime: habana - cap_add: - - SYS_NICE - ipc: host - command: --model-id ${LLM_MODEL_ID} --max-input-length 4096 --max-total-tokens 8192 --sharded true --num-shard ${NUM_SHARDS} - worker-docgrader-agent: + worker-rag-agent: image: opea/agent-langchain:latest - container_name: docgrader-agent-endpoint - depends_on: - - tgi-server + container_name: rag-agent-endpoint volumes: # - ${WORKDIR}/GenAIExamples/AgentQnA/docker_image_build/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/ - ${TOOLSET_PATH}:/home/user/tools/ @@ -41,7 +13,7 @@ services: ipc: host environment: ip_address: ${ip_address} - strategy: rag_agent + strategy: rag_agent_llama recursion_limit: ${recursion_limit_worker} llm_engine: tgi HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN} @@ -66,8 +38,7 @@ services: image: opea/agent-langchain:latest container_name: react-agent-endpoint depends_on: - - tgi-server - - worker-docgrader-agent + - worker-rag-agent volumes: # - ${WORKDIR}/GenAIExamples/AgentQnA/docker_image_build/GenAIComps/comps/agent/langchain/:/home/user/comps/agent/langchain/ - ${TOOLSET_PATH}:/home/user/tools/ @@ -76,7 +47,7 @@ services: ipc: host environment: ip_address: ${ip_address} - strategy: react_langgraph + strategy: react_llama recursion_limit: ${recursion_limit_supervisor} llm_engine: tgi HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN} diff --git a/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh b/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh index f4154fb22..966a03797 100644 --- a/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh +++ b/AgentQnA/docker_compose/intel/hpu/gaudi/launch_agent_service_tgi_gaudi.sh @@ -15,7 +15,7 @@ export LLM_MODEL_ID="meta-llama/Meta-Llama-3.1-70B-Instruct" export NUM_SHARDS=4 export LLM_ENDPOINT_URL="http://${ip_address}:8085" export temperature=0.01 -export max_new_tokens=512 +export max_new_tokens=4096 # agent related environment variables export TOOLSET_PATH=$WORKDIR/GenAIExamples/AgentQnA/tools/ @@ -27,17 +27,3 @@ export RETRIEVAL_TOOL_URL="http://${ip_address}:8889/v1/retrievaltool" export CRAG_SERVER=http://${ip_address}:8080 docker compose -f compose.yaml up -d - -sleep 5s -echo "Waiting tgi gaudi ready" -n=0 -until [[ "$n" -ge 100 ]] || [[ $ready == true ]]; do - docker logs tgi-server &> tgi-gaudi-service.log - n=$((n+1)) - if grep -q Connected tgi-gaudi-service.log; then - break - fi - sleep 5s -done -sleep 5s -echo "Service started successfully" diff --git a/AgentQnA/docker_compose/intel/hpu/gaudi/launch_tgi_gaudi.sh b/AgentQnA/docker_compose/intel/hpu/gaudi/launch_tgi_gaudi.sh new file mode 100644 index 000000000..75b2a9c7f --- /dev/null +++ b/AgentQnA/docker_compose/intel/hpu/gaudi/launch_tgi_gaudi.sh @@ -0,0 +1,25 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# LLM related environment variables +export HF_CACHE_DIR=${HF_CACHE_DIR} +ls $HF_CACHE_DIR +export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} +export LLM_MODEL_ID="meta-llama/Meta-Llama-3.1-70B-Instruct" +export NUM_SHARDS=4 + +docker compose -f tgi_gaudi.yaml up -d + +sleep 5s +echo "Waiting tgi gaudi ready" +n=0 +until [[ "$n" -ge 100 ]] || [[ $ready == true ]]; do + docker logs tgi-server &> tgi-gaudi-service.log + n=$((n+1)) + if grep -q Connected tgi-gaudi-service.log; then + break + fi + sleep 5s +done +sleep 5s +echo "Service started successfully" diff --git a/AgentQnA/docker_compose/intel/hpu/gaudi/tgi_gaudi.yaml b/AgentQnA/docker_compose/intel/hpu/gaudi/tgi_gaudi.yaml new file mode 100644 index 000000000..cd5dd202d --- /dev/null +++ b/AgentQnA/docker_compose/intel/hpu/gaudi/tgi_gaudi.yaml @@ -0,0 +1,30 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +services: + tgi-server: + image: ghcr.io/huggingface/tgi-gaudi:2.0.5 + container_name: tgi-server + ports: + - "8085:80" + volumes: + - ${HF_CACHE_DIR}:/data + environment: + no_proxy: ${no_proxy} + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + HUGGING_FACE_HUB_TOKEN: ${HUGGINGFACEHUB_API_TOKEN} + HF_HUB_DISABLE_PROGRESS_BARS: 1 + HF_HUB_ENABLE_HF_TRANSFER: 0 + HABANA_VISIBLE_DEVICES: all + OMPI_MCA_btl_vader_single_copy_mechanism: none + PT_HPU_ENABLE_LAZY_COLLECTIVES: true + ENABLE_HPU_GRAPH: true + LIMIT_HPU_GRAPH: true + USE_FLASH_ATTENTION: true + FLASH_ATTENTION_RECOMPUTE: true + runtime: habana + cap_add: + - SYS_NICE + ipc: host + command: --model-id ${LLM_MODEL_ID} --max-input-length 4096 --max-total-tokens 8192 --sharded true --num-shard ${NUM_SHARDS} diff --git a/AgentQnA/tests/1_build_images.sh b/AgentQnA/tests/step1_build_images.sh similarity index 100% rename from AgentQnA/tests/1_build_images.sh rename to AgentQnA/tests/step1_build_images.sh diff --git a/AgentQnA/tests/2_start_retrieval_tool.sh b/AgentQnA/tests/step2_start_retrieval_tool.sh similarity index 100% rename from AgentQnA/tests/2_start_retrieval_tool.sh rename to AgentQnA/tests/step2_start_retrieval_tool.sh diff --git a/AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh b/AgentQnA/tests/step3_ingest_data_and_validate_retrieval.sh similarity index 100% rename from AgentQnA/tests/3_ingest_data_and_validate_retrieval.sh rename to AgentQnA/tests/step3_ingest_data_and_validate_retrieval.sh diff --git a/AgentQnA/tests/4_launch_and_validate_agent_openai.sh b/AgentQnA/tests/step4_launch_and_validate_agent_openai.sh similarity index 100% rename from AgentQnA/tests/4_launch_and_validate_agent_openai.sh rename to AgentQnA/tests/step4_launch_and_validate_agent_openai.sh diff --git a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh b/AgentQnA/tests/step4_launch_and_validate_agent_tgi.sh similarity index 64% rename from AgentQnA/tests/4_launch_and_validate_agent_tgi.sh rename to AgentQnA/tests/step4_launch_and_validate_agent_tgi.sh index f7b36da2a..fde46e0d5 100644 --- a/AgentQnA/tests/4_launch_and_validate_agent_tgi.sh +++ b/AgentQnA/tests/step4_launch_and_validate_agent_tgi.sh @@ -17,6 +17,12 @@ if [ ! -d "$HF_CACHE_DIR" ]; then fi ls $HF_CACHE_DIR +function start_tgi(){ + echo "Starting tgi-gaudi server" + cd $WORKDIR/GenAIExamples/AgentQnA/docker_compose/intel/hpu/gaudi + bash launch_tgi_gaudi.sh + +} function start_agent_and_api_server() { echo "Starting CRAG server" @@ -25,6 +31,7 @@ function start_agent_and_api_server() { echo "Starting Agent services" cd $WORKDIR/GenAIExamples/AgentQnA/docker_compose/intel/hpu/gaudi bash launch_agent_service_tgi_gaudi.sh + sleep 10 } function validate() { @@ -43,18 +50,22 @@ function validate() { function validate_agent_service() { echo "----------------Test agent ----------------" - local CONTENT=$(http_proxy="" curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{ - "query": "Tell me about Michael Jackson song thriller" - }') - local EXIT_CODE=$(validate "$CONTENT" "Thriller" "react-agent-endpoint") - docker logs docgrader-agent-endpoint + # local CONTENT=$(http_proxy="" curl http://${ip_address}:9095/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{ + # "query": "Tell me about Michael Jackson song thriller" + # }') + export agent_port="9095" + local CONTENT=$(python3 $WORKDIR/GenAIExamples/AgentQnA/tests/test.py) + local EXIT_CODE=$(validate "$CONTENT" "Thriller" "rag-agent-endpoint") + docker logs rag-agent-endpoint if [ "$EXIT_CODE" == "1" ]; then exit 1 fi - local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{ - "query": "Tell me about Michael Jackson song thriller" - }') + # local CONTENT=$(http_proxy="" curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{ + # "query": "Tell me about Michael Jackson song thriller" + # }') + export agent_port="9090" + local CONTENT=$(python3 $WORKDIR/GenAIExamples/AgentQnA/tests/test.py) local EXIT_CODE=$(validate "$CONTENT" "Thriller" "react-agent-endpoint") docker logs react-agent-endpoint if [ "$EXIT_CODE" == "1" ]; then @@ -64,6 +75,10 @@ function validate_agent_service() { } function main() { + echo "==================== Start TGI ====================" + start_tgi + echo "==================== TGI started ====================" + echo "==================== Start agent ====================" start_agent_and_api_server echo "==================== Agent started ====================" diff --git a/AgentQnA/tests/test.py b/AgentQnA/tests/test.py new file mode 100644 index 000000000..f0ef93441 --- /dev/null +++ b/AgentQnA/tests/test.py @@ -0,0 +1,25 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import os + +import requests + + +def generate_answer_agent_api(url, prompt): + proxies = {"http": ""} + payload = { + "query": prompt, + } + response = requests.post(url, json=payload, proxies=proxies) + answer = response.json()["text"] + return answer + + +if __name__ == "__main__": + ip_address = os.getenv("ip_address", "localhost") + agent_port = os.getenv("agent_port", "9095") + url = f"http://{ip_address}:{agent_port}/v1/chat/completions" + prompt = "Tell me about Michael Jackson song thriller" + answer = generate_answer_agent_api(url, prompt) + print(answer) diff --git a/AgentQnA/tests/test_compose_on_gaudi.sh b/AgentQnA/tests/test_compose_on_gaudi.sh index efe1aeeec..5f7e899dc 100644 --- a/AgentQnA/tests/test_compose_on_gaudi.sh +++ b/AgentQnA/tests/test_compose_on_gaudi.sh @@ -19,7 +19,6 @@ function stop_crag() { function stop_agent_docker() { cd $WORKPATH/docker_compose/intel/hpu/gaudi/ - # docker compose -f compose.yaml down container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2) for container_name in $container_list; do cid=$(docker ps -aq --filter "name=$container_name") @@ -28,11 +27,21 @@ function stop_agent_docker() { done } +function stop_tgi(){ + cd $WORKPATH/docker_compose/intel/hpu/gaudi/ + container_list=$(cat tgi_gaudi.yaml | grep container_name | cut -d':' -f2) + for container_name in $container_list; do + cid=$(docker ps -aq --filter "name=$container_name") + echo "Stopping container $container_name" + if [[ ! -z "$cid" ]]; then docker rm $cid -f && sleep 1s; fi + done + +} + function stop_retrieval_tool() { echo "Stopping Retrieval tool" local RETRIEVAL_TOOL_PATH=$WORKPATH/../DocIndexRetriever cd $RETRIEVAL_TOOL_PATH/docker_compose/intel/cpu/xeon/ - # docker compose -f compose.yaml down container_list=$(cat compose.yaml | grep container_name | cut -d':' -f2) for container_name in $container_list; do cid=$(docker ps -aq --filter "name=$container_name") @@ -43,25 +52,26 @@ function stop_retrieval_tool() { echo "workpath: $WORKPATH" echo "=================== Stop containers ====================" stop_crag +stop_tgi stop_agent_docker stop_retrieval_tool cd $WORKPATH/tests echo "=================== #1 Building docker images====================" -bash 1_build_images.sh +bash step1_build_images.sh echo "=================== #1 Building docker images completed====================" echo "=================== #2 Start retrieval tool====================" -bash 2_start_retrieval_tool.sh +bash step2_start_retrieval_tool.sh echo "=================== #2 Retrieval tool started====================" echo "=================== #3 Ingest data and validate retrieval====================" -bash 3_ingest_data_and_validate_retrieval.sh +bash step3_ingest_data_and_validate_retrieval.sh echo "=================== #3 Data ingestion and validation completed====================" echo "=================== #4 Start agent and API server====================" -bash 4_launch_and_validate_agent_tgi.sh +bash step4_launch_and_validate_agent_tgi.sh echo "=================== #4 Agent test passed ====================" echo "=================== #5 Stop agent and API server====================" @@ -70,4 +80,6 @@ stop_agent_docker stop_retrieval_tool echo "=================== #5 Agent and API server stopped====================" +echo y | docker system prune + echo "ALL DONE!" diff --git a/AgentQnA/tools/supervisor_agent_tools.yaml b/AgentQnA/tools/supervisor_agent_tools.yaml index 58110e529..4b53cc9f9 100644 --- a/AgentQnA/tools/supervisor_agent_tools.yaml +++ b/AgentQnA/tools/supervisor_agent_tools.yaml @@ -25,7 +25,7 @@ get_billboard_rank_date: args_schema: rank: type: int - description: song name + description: the rank of interest, for example 1 for top 1 date: type: str description: date diff --git a/AgentQnA/tools/worker_agent_tools.py b/AgentQnA/tools/worker_agent_tools.py index 1dfdb8409..fded38ec3 100644 --- a/AgentQnA/tools/worker_agent_tools.py +++ b/AgentQnA/tools/worker_agent_tools.py @@ -12,16 +12,31 @@ def search_knowledge_base(query: str) -> str: print(url) proxies = {"http": ""} payload = { - "text": query, + "messages": query, } response = requests.post(url, json=payload, proxies=proxies) print(response) - docs = response.json()["documents"] - context = "" - for i, doc in enumerate(docs): - if i == 0: - context = doc - else: - context += "\n" + doc - print(context) - return context + if "documents" in response.json(): + docs = response.json()["documents"] + context = "" + for i, doc in enumerate(docs): + if i == 0: + context = doc + else: + context += "\n" + doc + # print(context) + return context + elif "text" in response.json(): + return response.json()["text"] + elif "reranked_docs" in response.json(): + docs = response.json()["reranked_docs"] + context = "" + for i, doc in enumerate(docs): + if i == 0: + context = doc["text"] + else: + context += "\n" + doc["text"] + # print(context) + return context + else: + return "Error parsing response from the knowledge base."