diff --git a/comps/cores/mega/gateway.py b/comps/cores/mega/gateway.py index a6a96bfecb..021e85d111 100644 --- a/comps/cores/mega/gateway.py +++ b/comps/cores/mega/gateway.py @@ -394,24 +394,25 @@ def read_text_from_file(self, file, save_file_name): return file_content - async def handle_request(self, request: Request, files: List[UploadFile] = File(...)): + async def handle_request(self, request: Request, files: List[UploadFile] = File(default=None)): data = await request.form() stream_opt = data.get("stream", True) chat_request = ChatCompletionRequest.parse_obj(data) file_summaries = [] - for file in files: - file_path = f"/tmp/{file.filename}" - - import aiofiles - - async with aiofiles.open(file_path, "wb") as f: - await f.write(await file.read()) - docs = self.read_text_from_file(file, file_path) - os.remove(file_path) - if isinstance(docs, list): - file_summaries.extend(docs) - else: - file_summaries.append(docs) + if files: + for file in files: + file_path = f"/tmp/{file.filename}" + + import aiofiles + + async with aiofiles.open(file_path, "wb") as f: + await f.write(await file.read()) + docs = self.read_text_from_file(file, file_path) + os.remove(file_path) + if isinstance(docs, list): + file_summaries.extend(docs) + else: + file_summaries.append(docs) if file_summaries: prompt = self._handle_message(chat_request.messages) + "\n".join(file_summaries)