This commit is contained in:
Timothy Jaeryang Baek
2026-07-27 04:11:48 -04:00
parent 977c793062
commit 8ab44ed3b1
+31 -14
View File
@@ -4100,6 +4100,30 @@ async def streaming_chat_response_handler(response, ctx):
def full_output():
return prior_output + output if prior_output else output
def get_message_error_content(error):
if isinstance(error, HTTPException):
error = error.detail
elif isinstance(error, dict):
error = error.get('detail', error)
else:
error = str(error)
return error if isinstance(error, (str, dict)) else str(error)
async def emit_message_error(error_content):
if save_to_chat:
await Chats.upsert_message_to_chat_by_id_and_message_id(
metadata['chat_id'],
metadata['message_id'],
{'error': {'content': error_content}},
)
await event_emitter(
{
'type': 'chat:message:error',
'data': {'error': {'content': error_content}},
}
)
reasoning_tags_param = metadata.get('params', {}).get('reasoning_tags')
DETECT_REASONING_TAGS = reasoning_tags_param is not False
@@ -5290,7 +5314,9 @@ async def streaming_chat_response_handler(response, ctx):
else:
break
except Exception as e:
log.debug(e)
error_content = get_message_error_content(e)
log.exception('Tool-call continuation failed: %s', error_content)
await emit_message_error(error_content)
break
if (
@@ -5300,18 +5326,7 @@ async def streaming_chat_response_handler(response, ctx):
):
log.warning('Tool-call iteration limit reached (%s)', max_tool_call_iterations)
error_content = f'Tool-call limit reached ({max_tool_call_iterations} iterations).'
if save_to_chat:
await Chats.upsert_message_to_chat_by_id_and_message_id(
metadata['chat_id'],
metadata['message_id'],
{'error': {'content': error_content}},
)
await event_emitter(
{
'type': 'chat:message:error',
'data': {'error': {'content': error_content}},
}
)
await emit_message_error(error_content)
if DETECT_CODE_INTERPRETER:
MAX_RETRIES = 5
@@ -5483,7 +5498,9 @@ async def streaming_chat_response_handler(response, ctx):
else:
break
except Exception as e:
log.debug(e)
error_content = get_message_error_content(e)
log.exception('Code interpreter continuation failed: %s', error_content)
await emit_message_error(error_content)
break
# Mark all in-progress items as completed