Skip to content

Commit

Permalink
Fix docsum crash issue for text summary case (opea-project#825)
Browse files Browse the repository at this point in the history
Signed-off-by: lvliang-intel <[email protected]>
  • Loading branch information
lvliang-intel authored Oct 25, 2024
1 parent fa2ea64 commit 49a8e35
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions comps/cores/mega/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 49a8e35

Please sign in to comment.