fix stream

This commit is contained in:
lvyb
2025-03-12 16:57:51 +08:00
parent f610174e61
commit 87474f7b2c

View File

@@ -123,18 +123,21 @@ async def openai_complete_if_cache(
async def inner(): async def inner():
try: try:
_content = ''
async for chunk in response: async for chunk in response:
content = chunk.choices[0].delta.content content = chunk.choices[0].delta.content
if content is None: if content is None:
continue continue
if r"\u" in content: if r"\u" in content:
content = safe_unicode_decode(content.encode("utf-8")) content = safe_unicode_decode(content.encode("utf-8"))
yield content _content += content
return _content
except Exception as e: except Exception as e:
logger.error(f"Error in stream response: {str(e)}") logger.error(f"Error in stream response: {str(e)}")
raise raise
return inner() response_content = await inner()
return response_content
else: else:
if ( if (