|
5 | 5 | import os |
6 | 6 | import ast |
7 | 7 |
|
8 | | -from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType |
| 8 | +from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType, CustomLogger |
9 | 9 | from comps.cores.mega.utils import handle_message |
10 | 10 | from comps.cores.proto.api_protocol import ( |
11 | 11 | ChatCompletionRequest, |
|
19 | 19 | from fastapi.responses import StreamingResponse |
20 | 20 | from langchain.prompts import PromptTemplate |
21 | 21 |
|
| 22 | +logger = CustomLogger("opea_dataprep_microservice") |
| 23 | +logflag = os.getenv("LOGFLAG", False) |
| 24 | + |
22 | 25 | MEGA_SERVICE_PORT = int(os.getenv("MEGA_SERVICE_PORT", 7778)) |
23 | 26 |
|
24 | 27 | LLM_SERVICE_HOST_IP = os.getenv("LLM_SERVICE_HOST_IP", "0.0.0.0") |
@@ -80,7 +83,7 @@ def align_inputs(self, inputs, cur_node, runtime_graph, llm_parameters_dict, **k |
80 | 83 | embedding = inputs['data'][0]['embedding'] |
81 | 84 | # Align the inputs for the retriever service |
82 | 85 | inputs = { |
83 | | - "index_name": llm_parameters_dict["key_index_name"], |
| 86 | + "index_name": llm_parameters_dict["index_name"], |
84 | 87 | "text": self.input_query, |
85 | 88 | "embedding": embedding |
86 | 89 | } |
@@ -198,14 +201,14 @@ async def handle_request(self, request: Request): |
198 | 201 | presence_penalty=chat_request.presence_penalty if chat_request.presence_penalty else 0.0, |
199 | 202 | repetition_penalty=chat_request.repetition_penalty if chat_request.repetition_penalty else 1.03, |
200 | 203 | stream=stream_opt, |
201 | | - key_index_name=chat_request.key_index_name |
| 204 | + index_name=chat_request.index_name |
202 | 205 | ) |
203 | 206 |
|
204 | 207 | # Initialize the initial inputs with the generated prompt |
205 | 208 | initial_inputs = {"query": prompt} |
206 | 209 |
|
207 | 210 | # Check if the key index name is provided in the parameters |
208 | | - if parameters.key_index_name: |
| 211 | + if parameters.index_name: |
209 | 212 | if agents_flag: |
210 | 213 | # Schedule the retriever microservice |
211 | 214 | result_ret, runtime_graph = await self.megaservice_retriever.schedule( |
@@ -248,11 +251,16 @@ async def handle_request(self, request: Request): |
248 | 251 | relevant_docs.append(doc) |
249 | 252 |
|
250 | 253 | # Update the initial inputs with the relevant documents |
251 | | - query = initial_inputs["query"] |
252 | | - initial_inputs = {} |
253 | | - initial_inputs["retrieved_docs"] = relevant_docs |
254 | | - initial_inputs["initial_query"] = query |
255 | | - megaservice = self.megaservice_llm |
| 254 | + if len(relevant_docs)>0: |
| 255 | + logger.info(f"[ CodeGenService - handle_request ] {len(relevant_docs)} relevant document\s found.") |
| 256 | + query = initial_inputs["query"] |
| 257 | + initial_inputs = {} |
| 258 | + initial_inputs["retrieved_docs"] = relevant_docs |
| 259 | + initial_inputs["initial_query"] = query |
| 260 | + |
| 261 | + else: |
| 262 | + logger.info("[ CodeGenService - handle_request ] Could not find any relevant documents. The query will be used as input to the LLM.") |
| 263 | + |
256 | 264 | else: |
257 | 265 | # Use the combined retriever and LLM microservice |
258 | 266 | megaservice = self.megaservice_retriever_llm |
|
0 commit comments