Skip to content

Commit 26d4ff1

Browse files
Spycshpre-commit-ci[bot]chensuyue
authored
add ChatQnA instructions for AIPC (#356)
* Add readme for ChatQnA on AIPC --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: chen, suyue <[email protected]>
1 parent 3bb2fee commit 26d4ff1

File tree

2 files changed

+415
-0
lines changed

2 files changed

+415
-0
lines changed

ChatQnA/docker/aipc/README.md

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# Build Mega Service of ChatQnA on AIPC
2+
3+
This document outlines the deployment process for a ChatQnA application utilizing the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline on AIPC. The steps include Docker image creation, container deployment via Docker Compose, and service execution to integrate microservices such as `embedding`, `retriever`, `rerank`, and `llm`.
4+
5+
## 🚀 Build Docker Images
6+
7+
First of all, you need to build Docker Images locally and install the python package of it.
8+
9+
```bash
10+
git clone https://github.com/opea-project/GenAIComps.git
11+
cd GenAIComps
12+
```
13+
14+
### 1. Build Embedding Image
15+
16+
```bash
17+
docker build --no-cache -t opea/embedding-tei:latest -f comps/embeddings/langchain/docker/Dockerfile .
18+
```
19+
20+
### 2. Build Retriever Image
21+
22+
```bash
23+
docker build --no-cache -t opea/retriever-redis:latest -f comps/retrievers/langchain/redis/docker/Dockerfile .
24+
```
25+
26+
### 3. Build Rerank Image
27+
28+
```bash
29+
docker build --no-cache -t opea/reranking-tei:latest -f comps/reranks/langchain/docker/Dockerfile .
30+
```
31+
32+
### 4. Build LLM Image
33+
34+
We use [Ollama](https://ollama.com/) as our LLM service for AIPC. Please pre-download Ollama on your PC.
35+
36+
```bash
37+
docker build --no-cache -t opea/llm-ollama:latest -f comps/llms/text-generation/ollama/Dockerfile .
38+
```
39+
40+
### 5. Build Dataprep Image
41+
42+
```bash
43+
docker build --no-cache -t opea/dataprep-redis:latest -f comps/dataprep/redis/langchain/docker/Dockerfile .
44+
cd ..
45+
```
46+
47+
### 6. Build MegaService Docker Image
48+
49+
To construct the Mega Service, we utilize the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline within the `chatqna.py` Python script. Build MegaService Docker image via below command:
50+
51+
```bash
52+
git clone https://github.com/opea-project/GenAIExamples.git
53+
cd GenAIExamples/ChatQnA/docker
54+
docker build --no-cache -t opea/chatqna:latest -f Dockerfile .
55+
cd ../../..
56+
```
57+
58+
### 7. Build UI Docker Image
59+
60+
Build frontend Docker image via below command:
61+
62+
```bash
63+
cd GenAIExamples/ChatQnA/docker/ui/
64+
docker build --no-cache -t opea/chatqna-ui:latest -f ./docker/Dockerfile .
65+
cd ../../../..
66+
```
67+
68+
Then run the command `docker images`, you will have the following 7 Docker Images:
69+
70+
1. `opea/dataprep-redis:latest`
71+
2. `opea/embedding-tei:latest`
72+
3. `opea/retriever-redis:latest`
73+
4. `opea/reranking-tei:latest`
74+
5. `opea/llm-ollama:latest`
75+
6. `opea/chatqna:latest`
76+
7. `opea/chatqna-ui:latest`
77+
78+
## 🚀 Start Microservices
79+
80+
### Setup Environment Variables
81+
82+
Since the `docker_compose.yaml` will consume some environment variables, you need to setup them in advance as below.
83+
84+
**Export the value of the public IP address of your AIPC to the `host_ip` environment variable**
85+
86+
> Change the External_Public_IP below with the actual IPV4 value
87+
88+
```
89+
export host_ip="External_Public_IP"
90+
```
91+
92+
For Linux users, please run `hostname -I | awk '{print $1}'`. For Windows users, please run `ipconfig | findstr /i "IPv4"` to get the external public ip.
93+
94+
**Export the value of your Huggingface API token to the `your_hf_api_token` environment variable**
95+
96+
> Change the Your_Huggingface_API_Token below with tyour actual Huggingface API Token value
97+
98+
```
99+
export your_hf_api_token="Your_Huggingface_API_Token"
100+
```
101+
102+
**Append the value of the public IP address to the no_proxy list**
103+
104+
```
105+
export your_no_proxy=${your_no_proxy},"External_Public_IP"
106+
```
107+
108+
```bash
109+
export no_proxy=${your_no_proxy}
110+
export http_proxy=${your_http_proxy}
111+
export https_proxy=${your_http_proxy}
112+
export EMBEDDING_MODEL_ID="BAAI/bge-base-en-v1.5"
113+
export RERANK_MODEL_ID="BAAI/bge-reranker-base"
114+
export TEI_EMBEDDING_ENDPOINT="http://${host_ip}:6006"
115+
export TEI_RERANKING_ENDPOINT="http://${host_ip}:8808"
116+
export REDIS_URL="redis://${host_ip}:6379"
117+
export INDEX_NAME="rag-redis"
118+
export HUGGINGFACEHUB_API_TOKEN=${your_hf_api_token}
119+
export MEGA_SERVICE_HOST_IP=${host_ip}
120+
export EMBEDDING_SERVICE_HOST_IP=${host_ip}
121+
export RETRIEVER_SERVICE_HOST_IP=${host_ip}
122+
export RERANK_SERVICE_HOST_IP=${host_ip}
123+
export LLM_SERVICE_HOST_IP=${host_ip}
124+
export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/chatqna"
125+
export DATAPREP_SERVICE_ENDPOINT="http://${host_ip}:6007/v1/dataprep"
126+
127+
export OLLAMA_ENDPOINT=http://${host_ip}:11434
128+
# On Windows PC, please use host.docker.internal instead of ${host_ip}
129+
#export OLLAMA_ENDPOINT=http://host.docker.internal:11434
130+
```
131+
132+
Note: Please replace with `host_ip` with you external IP address, do not use localhost.
133+
134+
### Start all the services Docker Containers
135+
136+
> Before running the docker compose command, you need to be in the folder that has the docker compose yaml file
137+
138+
```bash
139+
cd GenAIExamples/ChatQnA/docker/aipc/
140+
docker compose -f docker_compose.yaml up -d
141+
142+
# let ollama service runs
143+
ollama run llama3
144+
```
145+
146+
### Validate Microservices
147+
148+
1. TEI Embedding Service
149+
150+
```bash
151+
curl ${host_ip}:6006/embed \
152+
-X POST \
153+
-d '{"inputs":"What is Deep Learning?"}' \
154+
-H 'Content-Type: application/json'
155+
```
156+
157+
2. Embedding Microservice
158+
159+
```bash
160+
curl http://${host_ip}:6000/v1/embeddings\
161+
-X POST \
162+
-d '{"text":"hello"}' \
163+
-H 'Content-Type: application/json'
164+
```
165+
166+
3. Retriever Microservice
167+
To validate the retriever microservice, you need to generate a mock embedding vector of length 768 in Python script:
168+
169+
```bash
170+
your_embedding=$(python3 -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)")
171+
curl http://${host_ip}:7000/v1/retrieval \
172+
-X POST \
173+
-d '{"text":"What is the revenue of Nike in 2023?","embedding":"'"${your_embedding}"'"}' \
174+
-H 'Content-Type: application/json'
175+
```
176+
177+
4. TEI Reranking Service
178+
179+
```bash
180+
curl http://${host_ip}:8808/rerank \
181+
-X POST \
182+
-d '{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."]}' \
183+
-H 'Content-Type: application/json'
184+
```
185+
186+
5. Reranking Microservice
187+
188+
```bash
189+
curl http://${host_ip}:8000/v1/reranking\
190+
-X POST \
191+
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
192+
-H 'Content-Type: application/json'
193+
```
194+
195+
6. Ollama Service
196+
197+
```bash
198+
curl http://${host_ip}:11434/api/generate -d '{"model": "llama3", "prompt":"What is Deep Learning?"}'
199+
```
200+
201+
7. LLM Microservice
202+
203+
```bash
204+
curl http://${host_ip}:9000/v1/chat/completions\
205+
-X POST \
206+
-d '{"query":"What is Deep Learning?","max_new_tokens":17,"top_k":10,"top_p":0.95,"typical_p":0.95,"temperature":0.01,"repetition_penalty":1.03,"streaming":true}' \
207+
-H 'Content-Type: application/json'
208+
```
209+
210+
8. MegaService
211+
212+
```bash
213+
curl http://${host_ip}:8888/v1/chatqna -H "Content-Type: application/json" -d '{
214+
"messages": "What is the revenue of Nike in 2023?"
215+
}'
216+
```
217+
218+
9. Dataprep Microservice(Optional)
219+
220+
If you want to update the default knowledge base, you can use the following commands:
221+
222+
Update Knowledge Base via Local File Upload:
223+
224+
```bash
225+
curl -X POST "http://${host_ip}:6007/v1/dataprep" \
226+
-H "Content-Type: multipart/form-data" \
227+
-F "files=@./nke-10k-2023.pdf"
228+
```
229+
230+
This command updates a knowledge base by uploading a local file for processing. Update the file path according to your environment.
231+
232+
Add Knowledge Base via HTTP Links:
233+
234+
```bash
235+
curl -X POST "http://${host_ip}:6007/v1/dataprep" \
236+
-H "Content-Type: multipart/form-data" \
237+
-F 'link_list=["https://opea.dev"]'
238+
```
239+
240+
This command updates a knowledge base by submitting a list of HTTP links for processing.
241+
242+
## 🚀 Launch the UI
243+
244+
To access the frontend, open the following URL in your browser: http://{host_ip}:5173.

0 commit comments

Comments
 (0)