From 63ad40b73643d92e2a8f9d3508ec5dbdd3cccadf Mon Sep 17 00:00:00 2001 From: bruce Date: Thu, 2 May 2024 22:32:50 +0800 Subject: [PATCH] :bug: fix error from cohere api :bug: fix cohere api errro :bug: fix error :bug: error --- gpt_server/routers/cohere.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gpt_server/routers/cohere.py b/gpt_server/routers/cohere.py index 9e5abb4..743fb4b 100644 --- a/gpt_server/routers/cohere.py +++ b/gpt_server/routers/cohere.py @@ -21,12 +21,16 @@ async def get_content(data): + signal = False async with aiohttp.ClientSession(headers=headers) as sess: async with sess.post(url, json=data) as res: async for chunk in res.content: if chunk: tmp = json.loads(chunk.decode("utf-8")) + if 'text' not in tmp: + continue if tmp["is_finished"]: + signal = True yield "[DONE]" else: yield json.dumps({ @@ -41,6 +45,8 @@ async def get_content(data): yield '{"choices":[{"index":0,"delta":{"content":"error from claude"}}]}' yield "[DONE]" break + if not signal: + yield "[DONE]" @router.post("/chat", status_code=200)