refac
This commit is contained in:
1 parent
977c793062
commit
8ab44ed3b1
1 file changed
+31
-14
@@ -4100,6 +4100,30 @@ async def streaming_chat_response_handler(response, ctx):
|
|||||||
def full_output():
|
def full_output():
|
||||||
return prior_output + output if prior_output else 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')
|
reasoning_tags_param = metadata.get('params', {}).get('reasoning_tags')
|
||||||
DETECT_REASONING_TAGS = reasoning_tags_param is not False
|
DETECT_REASONING_TAGS = reasoning_tags_param is not False
|
||||||
|
|
||||||
@@ -5290,7 +5314,9 @@ async def streaming_chat_response_handler(response, ctx):
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
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
|
break
|
||||||
|
|
||||||
if (
|
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)
|
log.warning('Tool-call iteration limit reached (%s)', max_tool_call_iterations)
|
||||||
error_content = f'Tool-call limit reached ({max_tool_call_iterations} iterations).'
|
error_content = f'Tool-call limit reached ({max_tool_call_iterations} iterations).'
|
||||||
if save_to_chat:
|
await emit_message_error(error_content)
|
||||||
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}},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if DETECT_CODE_INTERPRETER:
|
if DETECT_CODE_INTERPRETER:
|
||||||
MAX_RETRIES = 5
|
MAX_RETRIES = 5
|
||||||
@@ -5483,7 +5498,9 @@ async def streaming_chat_response_handler(response, ctx):
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
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
|
break
|
||||||
|
|
||||||
# Mark all in-progress items as completed
|
# Mark all in-progress items as completed
|
||||||
|
|||||||
Reference in new issue
Block a user