Skip to content

Commit

Permalink
Merge branch 'main' into refine_component_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
chensuyue authored Jan 6, 2025
2 parents 44ccc7b + cf90932 commit 0a85882
Show file tree
Hide file tree
Showing 63 changed files with 101 additions and 107 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker/compose/agent-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# this file should be run in the root of the repo
services:
agent-langchain:
agent:
build:
dockerfile: comps/agent/langchain/Dockerfile
image: ${REGISTRY:-opea}/agent-langchain:${TAG:-latest}
dockerfile: comps/agent/src/Dockerfile
image: ${REGISTRY:-opea}/agent:${TAG:-latest}
12 changes: 2 additions & 10 deletions .github/workflows/docker/compose/embeddings-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

# this file should be run in the root of the repo
services:
embedding-tei:
embedding:
build:
dockerfile: comps/embeddings/src/Dockerfile
image: ${REGISTRY:-opea}/embedding-tei:${TAG:-latest}
image: ${REGISTRY:-opea}/embedding:${TAG:-latest}
embedding-multimodal-clip:
build:
dockerfile: comps/embeddings/src/integrations/dependency/clip/Dockerfile
Expand All @@ -15,15 +15,7 @@ services:
build:
dockerfile: comps/embeddings/src/integrations/dependency/bridgetower/Dockerfile
image: ${REGISTRY:-opea}/embedding-multimodal-bridgetower:${TAG:-latest}
embedding-multimodal:
build:
dockerfile: comps/embeddings/src/Dockerfile
image: ${REGISTRY:-opea}/embedding-multimodal:${TAG:-latest}
embedding-multimodal-bridgetower-gaudi:
build:
dockerfile: comps/embeddings/src/integrations/dependency/bridgetower/Dockerfile.intel_hpu
image: ${REGISTRY:-opea}/embedding-multimodal-bridgetower-gaudi:${TAG:-latest}
embedding-predictionguard:
build:
dockerfile: comps/embeddings/src/Dockerfile
image: ${REGISTRY:-opea}/embedding-predictionguard:${TAG:-latest}
8 changes: 2 additions & 6 deletions .github/workflows/docker/compose/llms-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

# this file should be run in the root of the repo
services:
llm-tgi:
llm-textgen:
build:
dockerfile: comps/llms/src/text-generation/Dockerfile
image: ${REGISTRY:-opea}/llm-tgi:${TAG:-latest}
image: ${REGISTRY:-opea}/llm-textgen:${TAG:-latest}
llm-ollama:
build:
dockerfile: comps/llms/text-generation/ollama/langchain/Dockerfile
Expand All @@ -19,10 +19,6 @@ services:
build:
dockerfile: comps/llms/faq-generation/tgi/langchain/Dockerfile
image: ${REGISTRY:-opea}/llm-faqgen-tgi:${TAG:-latest}
llm-vllm:
build:
dockerfile: comps/llms/src/text-generation/Dockerfile
image: ${REGISTRY:-opea}/llm-vllm:${TAG:-latest}
llm-native:
build:
dockerfile: comps/llms/text-generation/native/langchain/Dockerfile
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/docker/compose/reranks-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@

# this file should be run in the root of the repo
services:
reranking-tei:
reranking:
build:
dockerfile: comps/reranks/src/Dockerfile
image: ${REGISTRY:-opea}/reranking-tei:${TAG:-latest}
reranking-videoqna:
build:
dockerfile: comps/reranks/src/Dockerfile # TODO. need to update
image: ${REGISTRY:-opea}/reranking-videoqna:${TAG:-latest}
reranking-fastrag:
build:
dockerfile: comps/reranks/src/Dockerfile # TODO. need to update
image: ${REGISTRY:-opea}/reranking-fastrag:${TAG:-latest}
image: ${REGISTRY:-opea}/reranking:${TAG:-latest}
24 changes: 19 additions & 5 deletions .github/workflows/scripts/check_duplicated_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import yaml

images = {}
dockerfiles = {}
errors = []


def check_docker_compose_build_definition(file_path):
Expand All @@ -30,18 +32,26 @@ def check_docker_compose_build_definition(file_path):
if not os.path.exists(dockerfile):
# dockerfile not exists in the current repo context, assume it's in 3rd party context
dockerfile = os.path.normpath(os.path.join(context, build.get("dockerfile", "")))
item = {"file_path": file_path, "service": service, "dockerfile": dockerfile}
item = {"file_path": file_path, "service": service, "dockerfile": dockerfile, "image": image}
if image in images and dockerfile != images[image]["dockerfile"]:
print("ERROR: !!! Found Conflicts !!!")
print(f"Image: {image}, Dockerfile: {dockerfile}, defined in Service: {service}, File: {file_path}")
print(
errors.append(
f"ERROR: !!! Found Conflicts !!!\n"
f"Image: {image}, Dockerfile: {dockerfile}, defined in Service: {service}, File: {file_path}\n"
f"Image: {image}, Dockerfile: {images[image]['dockerfile']}, defined in Service: {images[image]['service']}, File: {images[image]['file_path']}"
)
sys.exit(1)
else:
# print(f"Add Image: {image} Dockerfile: {dockerfile}")
images[image] = item

if dockerfile in dockerfiles and image != dockerfiles[dockerfile]["image"]:
errors.append(
f"WARNING: Different images using the same Dockerfile\n"
f"Dockerfile: {dockerfile}, Image: {image}, defined in Service: {service}, File: {file_path}\n"
f"Dockerfile: {dockerfile}, Image: {dockerfiles[dockerfile]['image']}, defined in Service: {dockerfiles[dockerfile]['service']}, File: {dockerfiles[dockerfile]['file_path']}"
)
else:
dockerfiles[dockerfile] = item


def parse_arg():
parser = argparse.ArgumentParser(
Expand All @@ -55,6 +65,10 @@ def main():
args = parse_arg()
for file_path in args.files:
check_docker_compose_build_definition(file_path)
if errors:
for error in errors:
print(error)
sys.exit(1)
print("SUCCESS: No Conlicts Found.")
return 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ COPY comps /home/user/comps

RUN pip install --no-cache-dir --upgrade pip setuptools && \
if [ ${ARCH} = "cpu" ]; then \
pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r /home/user/comps/agent/langchain/requirements.txt; \
pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu -r /home/user/comps/agent/src/requirements.txt; \
else \
pip install --no-cache-dir -r /home/user/comps/agent/langchain/requirements.txt; \
pip install --no-cache-dir -r /home/user/comps/agent/src/requirements.txt; \
fi

ENV PYTHONPATH=$PYTHONPATH:/home/user

USER root

RUN mkdir -p /home/user/comps/agent/langchain/status && chown -R user /home/user/comps/agent/langchain/status
RUN mkdir -p /home/user/comps/agent/src/status && chown -R user /home/user/comps/agent/src/status

USER user

WORKDIR /home/user/comps/agent/langchain/
WORKDIR /home/user/comps/agent/src/

ENTRYPOINT ["python", "agent.py"]
14 changes: 7 additions & 7 deletions comps/agent/langchain/README.md → comps/agent/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ We currently support the following types of agents. Please refer to the example
1. ReAct: use `react_langchain` or `react_langgraph` or `react_llama` as strategy. First introduced in this seminal [paper](https://arxiv.org/abs/2210.03629). The ReAct agent engages in "reason-act-observe" cycles to solve problems. Please refer to this [doc](https://python.langchain.com/v0.2/docs/how_to/migrate_agent/) to understand the differences between the langchain and langgraph versions of react agents. See table below to understand the validated LLMs for each react strategy.
2. RAG agent: use `rag_agent` or `rag_agent_llama` strategy. This agent is specifically designed for improving RAG performance. It has the capability to rephrase query, check relevancy of retrieved context, and iterate if context is not relevant. See table below to understand the validated LLMs for each rag agent strategy.
3. Plan and execute: `plan_execute` strategy. This type of agent first makes a step-by-step plan given a user request, and then execute the plan sequentially (or in parallel, to be implemented in future). If the execution results can solve the problem, then the agent will output an answer; otherwise, it will replan and execute again.
4. SQL agent: use `sql_agent_llama` or `sql_agent` strategy. This agent is specifically designed and optimized for answering questions aabout data in SQL databases. Users need to specify `db_name` and `db_path` for the agent to access the SQL database. For more technical details read descriptions [here](src/strategy/sqlagent/README.md).
4. SQL agent: use `sql_agent_llama` or `sql_agent` strategy. This agent is specifically designed and optimized for answering questions aabout data in SQL databases. Users need to specify `db_name` and `db_path` for the agent to access the SQL database. For more technical details read descriptions [here](integrations/strategy/sqlagent/README.md).

**Note**:

Expand Down Expand Up @@ -60,7 +60,7 @@ Examples of how to register tools can be found in [Section 4](#-4-provide-your-o

```bash
cd GenAIComps/ # back to GenAIComps/ folder
docker build -t opea/agent-langchain:latest -f comps/agent/langchain/Dockerfile . --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy
docker build -t opea/agent:latest -f comps/agent/src/Dockerfile . --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy
```

#### 2.2.1 Start Agent microservices with TGI
Expand All @@ -78,7 +78,7 @@ docker run -d --runtime=habana --name "comps-tgi-gaudi-service" -p 8080:80 -v ./
docker logs comps-tgi-gaudi-service

# Agent: react_llama strategy
docker run -d --runtime=runc --name="comps-langchain-agent-endpoint" -v $WORKPATH/comps/agent/langchain/tools:/home/user/comps/agent/langchain/tools -p 9090:9090 --ipc=host -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} -e ip_address=${ip_address} -e strategy=react_llama -e llm_endpoint_url=http://${ip_address}:8080 -e llm_engine=tgi -e recursion_limit=15 -e require_human_feedback=false -e tools=/home/user/comps/agent/langchain/tools/custom_tools.yaml opea/agent-langchain:latest
docker run -d --runtime=runc --name="comps-langchain-agent-endpoint" -v $WORKPATH/comps/agent/langchain/tools:/home/user/comps/agent/langchain/tools -p 9090:9090 --ipc=host -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} -e ip_address=${ip_address} -e strategy=react_llama -e llm_endpoint_url=http://${ip_address}:8080 -e llm_engine=tgi -e recursion_limit=15 -e require_human_feedback=false -e tools=/home/user/comps/agent/langchain/tools/custom_tools.yaml opea/agent:latest

# check status
docker logs comps-langchain-agent-endpoint
Expand All @@ -105,7 +105,7 @@ docker run -d --runtime=habana --rm --name "comps-vllm-gaudi-service" -p 8080:80
docker logs comps-vllm-gaudi-service

# Agent
docker run -d --runtime=runc --name="comps-langchain-agent-endpoint" -v $WORKPATH/comps/agent/langchain/tools:/home/user/comps/agent/langchain/tools -p 9090:9090 --ipc=host -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} -e ip_address=${ip_address} -e strategy=react_llama -e llm_endpoint_url=http://${ip_address}:8080 -e llm_engine=vllm -e recursion_limit=15 -e require_human_feedback=false -e tools=/home/user/comps/agent/langchain/tools/custom_tools.yaml opea/agent-langchain:latest
docker run -d --runtime=runc --name="comps-langchain-agent-endpoint" -v $WORKPATH/comps/agent/langchain/tools:/home/user/comps/agent/langchain/tools -p 9090:9090 --ipc=host -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} -e ip_address=${ip_address} -e strategy=react_llama -e llm_endpoint_url=http://${ip_address}:8080 -e llm_engine=vllm -e recursion_limit=15 -e require_human_feedback=false -e tools=/home/user/comps/agent/langchain/tools/custom_tools.yaml opea/agent:latest

# check status
docker logs comps-langchain-agent-endpoint
Expand All @@ -114,7 +114,7 @@ docker logs comps-langchain-agent-endpoint
> debug mode
>
> ```bash
> docker run --rm --runtime=runc --name="comps-langchain-agent-endpoint" -v ./comps/agent/langchain/:/home/user/comps/agent/langchain/ -p 9090:9090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} -e ip_address=${ip_address} -e strategy=react_llama -e llm_endpoint_url=http://${ip_address}:8080 -e llm_engine=vllm -e recursion_limit=15 -e require_human_feedback=false -e tools=/home/user/comps/agent/langchain/tools/custom_tools.yaml opea/agent-langchain:latest
> docker run --rm --runtime=runc --name="comps-langchain-agent-endpoint" -v ./comps/agent/langchain/:/home/user/comps/agent/langchain/ -p 9090:9090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} -e ip_address=${ip_address} -e strategy=react_llama -e llm_endpoint_url=http://${ip_address}:8080 -e llm_engine=vllm -e recursion_limit=15 -e require_human_feedback=false -e tools=/home/user/comps/agent/langchain/tools/custom_tools.yaml opea/agent:latest
> ```
## 🚀 3. Validate Microservice
Expand Down Expand Up @@ -189,7 +189,7 @@ def opea_rag_query(query):

```bash
# Agent
docker run -d --runtime=runc --name="comps-langchain-agent-endpoint" -v my_tools:/home/user/comps/agent/langchain/tools -p 9090:9090 --ipc=host -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} -e ip_address=${ip_address} -e strategy=react_llama -e llm_endpoint_url=http://${ip_address}:8080 -e llm_engine=tgi -e recursive_limit=15 -e require_human_feedback=false -e tools=/home/user/comps/agent/langchain/tools/custom_tools.yaml opea/agent-langchain:latest
docker run -d --runtime=runc --name="comps-langchain-agent-endpoint" -v my_tools:/home/user/comps/agent/langchain/tools -p 9090:9090 --ipc=host -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} -e ip_address=${ip_address} -e strategy=react_llama -e llm_endpoint_url=http://${ip_address}:8080 -e llm_engine=tgi -e recursive_limit=15 -e require_human_feedback=false -e tools=/home/user/comps/agent/langchain/tools/custom_tools.yaml opea/agent:latest
```

- validate with my_tools
Expand All @@ -205,5 +205,5 @@ data: [DONE]

## 5. Customize agent strategy

For advanced developers who want to implement their own agent strategies, you can add a separate folder in `src\strategy`, implement your agent by inherit the `BaseAgent` class, and add your strategy into the `src\agent.py`. The architecture of this agent microservice is shown in the diagram below as a reference.
For advanced developers who want to implement their own agent strategies, you can add a separate folder in `integrations\strategy`, implement your agent by inherit the `BaseAgent` class, and add your strategy into the `integrations\agent.py`. The architecture of this agent microservice is shown in the diagram below as a reference.
![Architecture Overview](agent_arch.jpg)
8 changes: 4 additions & 4 deletions comps/agent/langchain/agent.py → comps/agent/src/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
sys.path.append(comps_path)

from comps import CustomLogger, GeneratedDoc, LLMParamsDoc, ServiceType, opea_microservices, register_microservice
from comps.agent.langchain.src.agent import instantiate_agent
from comps.agent.langchain.src.global_var import assistants_global_kv, threads_global_kv
from comps.agent.langchain.src.thread import instantiate_thread_memory, thread_completion_callback
from comps.agent.langchain.src.utils import get_args
from comps.agent.src.integrations.agent import instantiate_agent
from comps.agent.src.integrations.global_var import assistants_global_kv, threads_global_kv
from comps.agent.src.integrations.thread import instantiate_thread_memory, thread_completion_callback
from comps.agent.src.integrations.utils import get_args
from comps.cores.proto.api_protocol import (
AssistantsObject,
ChatCompletionRequest,
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
6 changes: 3 additions & 3 deletions comps/agent/langchain/test.py → comps/agent/src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import pandas as pd
import requests
from src.utils import get_args
from integrations.utils import get_args


def test_agent_local(args):
from src.agent import instantiate_agent
from integrations.agent import instantiate_agent

if args.q == 0:
df = pd.DataFrame({"query": ["What is the Intel OPEA Project?"]})
Expand Down Expand Up @@ -148,7 +148,7 @@ def process_request(api, query, is_stream=False):


def test_ut(args):
from src.tools import get_tools_descriptions
from integrations.tools import get_tools_descriptions

tools = get_tools_descriptions("tools/custom_tools.py")
for tool in tools:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json

import requests
from src.utils import get_args
from integrations.utils import get_args


def test_assistants_http(args):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
timeout: 6s
retries: 18
start_period: 30s
embedding-multimodal:
embedding:
image: opea/embedding:latest
container_name: embedding-multimodal-bridgetower-server
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
timeout: 6s
retries: 18
start_period: 30s
embedding-multimodal:
embedding:
image: opea/embedding:latest
container_name: embedding-multimodal-bridgetower-server
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
services:
embedding:
image: opea/embedding:latest
container_name: embedding-predictionguard
container_name: embedding
ports:
- "6000:6000"
ipc: host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
retries: 18
embedding:
image: opea/embedding:latest
container_name: embedding-tei-server
container_name: embedding-server
ports:
- "6000:6000"
ipc: host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
ipc: host
command: --model $LLM_MODEL --tensor-parallel-size 1 --host 0.0.0.0 --port 80
llm:
image: opea/llm-vllm:latest
image: opea/llm-textgen:latest
container_name: llm-vllm-gaudi-server
depends_on:
- vllm-service
Expand Down
4 changes: 2 additions & 2 deletions comps/llms/src/text-generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export LLM_MODEL_ID=${your_hf_llm_model}

```bash
cd ../../../../
docker build -t opea/llm-tgi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/llms/src/text-generation/Dockerfile .
docker build -t opea/llm-textgen:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/llms/src/text-generation/Dockerfile .
```

To start a docker container, you have two options:
Expand All @@ -54,7 +54,7 @@ You can choose one as needed.
### 2.3 Run Docker with CLI (Option A)

```bash
docker run -d --name="llm-tgi-server" -p 9000:9000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT -e HF_TOKEN=$HF_TOKEN opea/llm-tgi:latest
docker run -d --name="llm-tgi-server" -p 9000:9000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT -e HF_TOKEN=$HF_TOKEN opea/llm-textgen:latest
```

### 2.4 Run Docker with Docker Compose (Option B)
Expand Down
4 changes: 2 additions & 2 deletions comps/llms/text-generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ docker run -d \
-e https_proxy=$https_proxy \
-e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT \
-e HF_TOKEN=$HF_TOKEN \
opea/llm-tgi:latest
opea/llm-textgen:latest
```

#### 2.3.2 vLLM
Expand All @@ -218,7 +218,7 @@ docker run \
-e vLLM_LLM_ENDPOINT=$vLLM_LLM_ENDPOINT \
-e HF_TOKEN=$HF_TOKEN \
-e LLM_MODEL=$LLM_MODEL \
opea/llm-vllm:latest
opea/llm-textgen:latest
```

### 2.4 Run Docker with Docker Compose (Option B)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
ipc: host
command: --model $LLM_MODEL --tensor-parallel-size 1 --host 0.0.0.0 --port 80
llm:
image: opea/llm-vllm:latest
image: opea/llm-textgen:latest
container_name: llm-vllm-gaudi-server
depends_on:
- vllm-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ docker run -d --rm \
-e HUGGINGFACEHUB_API_TOKEN=$HUGGINGFACEHUB_API_TOKEN \
-e LLM_MODEL=$LLM_MODEL \
-e LOGFLAG=$LOGFLAG \
opea/llm-vllm:latest
opea/llm-textgen:latest
2 changes: 1 addition & 1 deletion comps/reranks/deployment/docker_compose/rerank_tei.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
command: --model-id ${RERANK_MODEL_ID} --hf-api-token ${HF_TOKEN}
reranking:
image: opea/reranking:latest
container_name: reranking-tei-server
container_name: reranking-server
ports:
- "8000:8000"
ipc: host
Expand Down
Loading

0 comments on commit 0a85882

Please sign in to comment.