fix stream

This commit is contained in:
zrguo
2025-03-17 11:41:55 +08:00
parent a9bd318d98
commit adba09f6c2

View File

@@ -123,21 +123,18 @@ 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"))
_content += content yield 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
response_content = await inner() return inner()
return response_content
else: else:
if ( if (