Skip to content

Commit 8164406

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent e2c605f commit 8164406

File tree

9 files changed

+136
-123
lines changed

9 files changed

+136
-123
lines changed

CodeGen/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ The workflow falls into the following architecture:
2020

2121
The CodeGen example is implemented using the component-level microservices defined in [GenAIComps](https://github.com/opea-project/GenAIComps). The flow chart below shows the information flow between different microservices for this example.
2222

23-
2423
```mermaid
2524
---
2625
config:
@@ -155,11 +154,13 @@ cd GenAIExamples/CodeGen/docker_compose/intel/hpu/gaudi
155154
```
156155

157156
TGI service:
157+
158158
```bash
159159
docker compose --profile codegen-gaudi-tgi up -d
160160
```
161161

162162
vLLM service:
163+
163164
```bash
164165
docker compose --profile codegen-gaudi-vllm up -d
165166
```
@@ -175,16 +176,17 @@ cd GenAIExamples/CodeGen/docker_compose/intel/cpu/xeon
175176
```
176177

177178
TGI service:
179+
178180
```bash
179181
docker compose --profile codegen-xeon-tgi up -d
180182
```
181183

182184
vLLM service:
185+
183186
```bash
184187
docker compose --profile codegen-xeon-vllm up -d
185188
```
186189

187-
188190
Refer to the [Xeon Guide](./docker_compose/intel/cpu/xeon/README.md) for more instructions on building docker images from source.
189191

190192
### Deploy CodeGen on Kubernetes using Helm Chart

CodeGen/codegen.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4+
import ast
45
import asyncio
56
import os
6-
import ast
77

8-
from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType, CustomLogger
8+
from comps import CustomLogger, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType
99
from comps.cores.mega.utils import handle_message
1010
from comps.cores.proto.api_protocol import (
1111
ChatCompletionRequest,
@@ -30,21 +30,21 @@
3030
TEI_EMBEDDING_HOST_IP = os.getenv("TEI_EMBEDDING_HOST_IP", "0.0.0.0")
3131
EMBEDDER_PORT = int(os.getenv("EMBEDDER_PORT", 6000))
3232

33-
grader_prompt = """You are a grader assessing relevance of a retrieved document to a user question. \n
33+
grader_prompt = """You are a grader assessing relevance of a retrieved document to a user question. \n
3434
Here is the user question: {question} \n
3535
Here is the retrieved document: \n\n {document} \n\n
3636
37-
If the document contains keywords related to the user question, grade it as relevant.
38-
It does not need to be a stringent test. The goal is to filter out erroneous retrievals.
37+
If the document contains keywords related to the user question, grade it as relevant.
38+
It does not need to be a stringent test. The goal is to filter out erroneous retrievals.
3939
Rules:
40-
- Do not return the question, the provided document or explanation.
41-
- if this document is relevant to the question, return 'yes' otherwise return 'no'.
40+
- Do not return the question, the provided document or explanation.
41+
- if this document is relevant to the question, return 'yes' otherwise return 'no'.
4242
- Do not include any other details in your response.
4343
"""
4444

45+
4546
def align_inputs(self, inputs, cur_node, runtime_graph, llm_parameters_dict, **kwargs):
46-
"""
47-
Aligns the inputs based on the service type of the current node.
47+
"""Aligns the inputs based on the service type of the current node.
4848
4949
Parameters:
5050
- self: Reference to the current instance of the class.
@@ -57,25 +57,21 @@ def align_inputs(self, inputs, cur_node, runtime_graph, llm_parameters_dict, **k
5757
Returns:
5858
- inputs: The aligned inputs for the current node.
5959
"""
60-
60+
6161
# Check if the current service type is EMBEDDING
6262
if self.services[cur_node].service_type == ServiceType.EMBEDDING:
6363
# Store the input query for later use
6464
self.input_query = inputs["query"]
6565
# Set the input for the embedding service
6666
inputs["input"] = inputs["query"]
67-
67+
6868
# Check if the current service type is RETRIEVER
6969
if self.services[cur_node].service_type == ServiceType.RETRIEVER:
7070
# Extract the embedding from the inputs
71-
embedding = inputs['data'][0]['embedding']
71+
embedding = inputs["data"][0]["embedding"]
7272
# Align the inputs for the retriever service
73-
inputs = {
74-
"index_name": llm_parameters_dict["index_name"],
75-
"text": self.input_query,
76-
"embedding": embedding
77-
}
78-
73+
inputs = {"index_name": llm_parameters_dict["index_name"], "text": self.input_query, "embedding": embedding}
74+
7975
return inputs
8076

8177

@@ -90,9 +86,7 @@ def __init__(self, host="0.0.0.0", port=8000):
9086
self.endpoint = str(MegaServiceEndpoint.CODE_GEN)
9187

9288
def add_remote_service(self):
93-
"""
94-
Adds remote microservices to the service orchestrators and defines the flow between them.
95-
"""
89+
"""Adds remote microservices to the service orchestrators and defines the flow between them."""
9690

9791
# Define the embedding microservice
9892
embedding = MicroService(
@@ -137,8 +131,7 @@ def add_remote_service(self):
137131
self.megaservice_llm.add(llm)
138132

139133
async def read_streaming_response(self, response: StreamingResponse):
140-
"""
141-
Reads the streaming response from a StreamingResponse object.
134+
"""Reads the streaming response from a StreamingResponse object.
142135
143136
Parameters:
144137
- self: Reference to the current instance of the class.
@@ -153,8 +146,7 @@ async def read_streaming_response(self, response: StreamingResponse):
153146
return body.decode("utf-8") # Decode the accumulated byte string to a regular string
154147

155148
async def handle_request(self, request: Request):
156-
"""
157-
Handles the incoming request, processes it through the appropriate microservices,
149+
"""Handles the incoming request, processes it through the appropriate microservices,
158150
and returns the response.
159151
160152
Parameters:
@@ -189,7 +181,7 @@ async def handle_request(self, request: Request):
189181
presence_penalty=chat_request.presence_penalty if chat_request.presence_penalty else 0.0,
190182
repetition_penalty=chat_request.repetition_penalty if chat_request.repetition_penalty else 1.03,
191183
stream=stream_opt,
192-
index_name=chat_request.index_name
184+
index_name=chat_request.index_name,
193185
)
194186

195187
# Initialize the initial inputs with the generated prompt
@@ -237,18 +229,20 @@ async def handle_request(self, request: Request):
237229
if r["choices"][0]["text"] == "yes":
238230
# Append the document to the relevant_docs list
239231
relevant_docs.append(doc)
240-
232+
241233
# Update the initial inputs with the relevant documents
242-
if len(relevant_docs)>0:
234+
if len(relevant_docs) > 0:
243235
logger.info(f"[ CodeGenService - handle_request ] {len(relevant_docs)} relevant document\s found.")
244236
query = initial_inputs["query"]
245237
initial_inputs = {}
246238
initial_inputs["retrieved_docs"] = relevant_docs
247239
initial_inputs["initial_query"] = query
248-
240+
249241
else:
250-
logger.info("[ CodeGenService - handle_request ] Could not find any relevant documents. The query will be used as input to the LLM.")
251-
242+
logger.info(
243+
"[ CodeGenService - handle_request ] Could not find any relevant documents. The query will be used as input to the LLM."
244+
)
245+
252246
else:
253247
# Use the combined retriever and LLM microservice
254248
megaservice = self.megaservice_retriever_llm
@@ -301,4 +295,4 @@ def start(self):
301295
if __name__ == "__main__":
302296
chatqna = CodeGenService(port=MEGA_SERVICE_PORT)
303297
chatqna.add_remote_service()
304-
chatqna.start()
298+
chatqna.start()

CodeGen/docker_compose/intel/cpu/xeon/README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export https_proxy=${your_https_proxy}
111111
```
112112

113113
## Start the Docker Containers for All Services
114+
114115
Find the corresponding [compose.yaml](./docker_compose/intel/cpu/xeon/compose.yaml). User could start CodeGen based on TGI or vLLM service:
115116

116117
```bash
@@ -132,8 +133,8 @@ Then run the command `docker images`, you will have the following Docker images:
132133
- `opea/dataprep`
133134
- `opea/embedding`
134135
- `opea/llm-textgen`
135-
- `opea/retriever`
136-
- `redis/redis-stack`
136+
- `opea/retriever`
137+
- `redis/redis-stack`
137138

138139
#### vLLM service:
139140

@@ -150,8 +151,8 @@ Then run the command `docker images`, you will have the following Docker images:
150151
- `opea/dataprep`
151152
- `opea/embedding`
152153
- `opea/llm-textgen`
153-
- `opea/retriever`
154-
- `redis/redis-stack`
154+
- `opea/retriever`
155+
- `redis/redis-stack`
155156
- `opea/vllm`
156157

157158
### Validate the MicroServices and MegaService
@@ -177,16 +178,16 @@ Then run the command `docker images`, you will have the following Docker images:
177178

178179
3. Dataprep Microservice
179180

180-
Make sure to replace the file name placeholders with your correct file name
181+
Make sure to replace the file name placeholders with your correct file name
181182

182-
```bash
183-
curl http://${host_ip}:6007/v1/dataprep/ingest \
184-
-X POST \
185-
-H "Content-Type: multipart/form-data" \
186-
-F "files=@./file1.pdf" \
187-
-F "files=@./file2.txt" \
188-
-F "index_name=my_API_document"
189-
```
183+
```bash
184+
curl http://${host_ip}:6007/v1/dataprep/ingest \
185+
-X POST \
186+
-H "Content-Type: multipart/form-data" \
187+
-F "files=@./file1.pdf" \
188+
-F "files=@./file2.txt" \
189+
-F "index_name=my_API_document"
190+
```
190191

191192
4. MegaService
192193

@@ -196,16 +197,16 @@ Then run the command `docker images`, you will have the following Docker images:
196197
-d '{"messages": "Implement a high-level API for a TODO list application. The API takes as input an operation request and updates the TODO list in place. If the request is invalid, raise an exception."}'
197198
```
198199

199-
CodeGen service with RAG and Agents activated based on an index.
200-
201-
```bash
202-
curl http://${host_ip}:7778/v1/codegen \
203-
-H "Content-Type: application/json" \
204-
-d '{"agents_flag": "True", "index_name": "my_API_document", "messages": "Implement a high-level API for a TODO list application. The API takes as input an operation request and updates the TODO list in place. If the request is invalid, raise an exception."}'
205-
```
206-
200+
CodeGen service with RAG and Agents activated based on an index.
201+
202+
```bash
203+
curl http://${host_ip}:7778/v1/codegen \
204+
-H "Content-Type: application/json" \
205+
-d '{"agents_flag": "True", "index_name": "my_API_document", "messages": "Implement a high-level API for a TODO list application. The API takes as input an operation request and updates the TODO list in place. If the request is invalid, raise an exception."}'
206+
```
207207

208208
## 🚀 Launch the Gradio Based UI (Recommended)
209+
209210
To access the Gradio frontend URL, follow the steps in [this README](../../../../ui/gradio/README.md)
210211

211212
Code Generation Tab
@@ -222,7 +223,6 @@ Here is an example of running a query in the Gradio UI using an Index:
222223

223224
![project-screenshot](../../../../assets/img/codegen_gradio_ui_query.png)
224225

225-
226226
## 🚀 Launch the Svelte Based UI (Optional)
227227

228228
To access the frontend, open the following URL in your browser: `http://{host_ip}:5173`. By default, the UI runs on port 5173 internally. If you prefer to use a different host port to access the frontend, you can modify the port mapping in the `compose.yaml` file as shown below:

CodeGen/docker_compose/intel/cpu/xeon/compose.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
14
services:
25

36
tgi-service:
@@ -132,7 +135,7 @@ services:
132135
http_proxy: ${http_proxy}
133136
https_proxy: ${https_proxy}
134137
REDIS_URL: ${REDIS_URL}
135-
REDIS_HOST: ${host_ip}
138+
REDIS_HOST: ${host_ip}
136139
INDEX_NAME: ${INDEX_NAME}
137140
HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
138141
LOGFLAG: true
@@ -197,4 +200,4 @@ services:
197200
restart: unless-stopped
198201
networks:
199202
default:
200-
driver: bridge
203+
driver: bridge

CodeGen/docker_compose/intel/hpu/gaudi/README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ cd GenAIExamples/CodeGen/docker_compose/intel/hpu/gaudi
112112
```
113113

114114
TGI service:
115+
115116
```bash
116117
docker compose --profile codegen-gaudi-tgi up -d
117118
```
118119

119120
vLLM service:
121+
120122
```bash
121123
docker compose --profile codegen-gaudi-vllm up -d
122124
```
@@ -146,16 +148,16 @@ Refer to the [Gaudi Guide](./docker_compose/intel/hpu/gaudi/README.md) to build
146148

147149
3. Dataprep Microservice
148150

149-
Make sure to replace the file name placeholders with your correct file name
151+
Make sure to replace the file name placeholders with your correct file name
150152

151-
```bash
152-
curl http://${host_ip}:6007/v1/dataprep/ingest \
153-
-X POST \
154-
-H "Content-Type: multipart/form-data" \
155-
-F "files=@./file1.pdf" \
156-
-F "files=@./file2.txt" \
157-
-F "index_name=my_API_document"
158-
```
153+
```bash
154+
curl http://${host_ip}:6007/v1/dataprep/ingest \
155+
-X POST \
156+
-H "Content-Type: multipart/form-data" \
157+
-F "files=@./file1.pdf" \
158+
-F "files=@./file2.txt" \
159+
-F "index_name=my_API_document"
160+
```
159161

160162
4. MegaService
161163

@@ -165,15 +167,16 @@ Refer to the [Gaudi Guide](./docker_compose/intel/hpu/gaudi/README.md) to build
165167
-d '{"messages": "Implement a high-level API for a TODO list application. The API takes as input an operation request and updates the TODO list in place. If the request is invalid, raise an exception."}'
166168
```
167169

168-
CodeGen service with RAG and Agents activated based on an index.
169-
170-
```bash
171-
curl http://${host_ip}$:7778/v1/codegen \
172-
-H "Content-Type: application/json" \
173-
-d '{"agents_flag": "True", "index_name": "my_API_document", "messages": "Implement a high-level API for a TODO list application. The API takes as input an operation request and updates the TODO list in place. If the request is invalid, raise an exception."}'
174-
```
170+
CodeGen service with RAG and Agents activated based on an index.
171+
172+
```bash
173+
curl http://${host_ip}$:7778/v1/codegen \
174+
-H "Content-Type: application/json" \
175+
-d '{"agents_flag": "True", "index_name": "my_API_document", "messages": "Implement a high-level API for a TODO list application. The API takes as input an operation request and updates the TODO list in place. If the request is invalid, raise an exception."}'
176+
```
175177

176178
## 🚀 Launch the Gradio Based UI (Recommended)
179+
177180
To access the Gradio frontend URL, follow the steps in [this README](../../../../ui/gradio/README.md)
178181

179182
Code Generation Tab
@@ -190,7 +193,6 @@ Here is an example of running a query in the Gradio UI using an Index:
190193

191194
![project-screenshot](../../../../assets/img/codegen_gradio_ui_query.png)
192195

193-
194196
## 🚀 Launch the Svelte Based UI (Optional)
195197

196198
To access the frontend, open the following URL in your browser: `http://{host_ip}:5173`. By default, the UI runs on port 5173 internally. If you prefer to use a different host port to access the frontend, you can modify the port mapping in the `compose.yaml` file as shown below:
@@ -300,4 +302,3 @@ For example:
300302
- Ask question and get answer
301303

302304
![qna](../../../../assets/img/codegen_qna.png)
303-

CodeGen/docker_compose/intel/hpu/gaudi/compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ services:
151151
http_proxy: ${http_proxy}
152152
https_proxy: ${https_proxy}
153153
REDIS_URL: ${REDIS_URL}
154-
REDIS_HOST: ${host_ip}
154+
REDIS_HOST: ${host_ip}
155155
INDEX_NAME: ${INDEX_NAME}
156156
HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
157157
LOGFLAG: true
@@ -216,4 +216,4 @@ services:
216216
restart: unless-stopped
217217
networks:
218218
default:
219-
driver: bridge
219+
driver: bridge

0 commit comments

Comments
 (0)