refac
This commit is contained in:
@@ -3623,7 +3623,31 @@ async def non_streaming_chat_response_handler(response, ctx):
|
||||
# otherwise generate from response content
|
||||
response_output = response_data.get('output')
|
||||
if not response_output:
|
||||
response_output = [
|
||||
choice_message = choices[0].get('message', {})
|
||||
reasoning_content = choice_message.get('reasoning_content') or choice_message.get('reasoning')
|
||||
reasoning_details = choice_message.get('reasoning_details')
|
||||
response_output = []
|
||||
if reasoning_content or reasoning_details:
|
||||
reasoning_item = {
|
||||
'type': 'reasoning',
|
||||
'id': output_id('r'),
|
||||
'status': 'completed',
|
||||
'start_tag': '<think>',
|
||||
'end_tag': '</think>',
|
||||
'attributes': {'type': 'reasoning_content'},
|
||||
'content': (
|
||||
[{'type': 'output_text', 'text': reasoning_content}]
|
||||
if reasoning_content
|
||||
else []
|
||||
),
|
||||
'summary': None,
|
||||
}
|
||||
if reasoning_details:
|
||||
reasoning_item['reasoning_details'] = (
|
||||
reasoning_details if isinstance(reasoning_details, list) else [reasoning_details]
|
||||
)
|
||||
response_output.append(reasoning_item)
|
||||
response_output.append(
|
||||
{
|
||||
'type': 'message',
|
||||
'id': output_id('msg'),
|
||||
@@ -3631,7 +3655,7 @@ async def non_streaming_chat_response_handler(response, ctx):
|
||||
'role': 'assistant',
|
||||
'content': [{'type': 'output_text', 'text': content}],
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
await event_emitter(
|
||||
{
|
||||
@@ -4398,7 +4422,8 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
or delta.get('reasoning')
|
||||
or delta.get('thinking')
|
||||
)
|
||||
if reasoning_content:
|
||||
reasoning_details = delta.get('reasoning_details')
|
||||
if reasoning_content or reasoning_details:
|
||||
if not output or output[-1].get('type') != 'reasoning':
|
||||
reasoning_item = {
|
||||
'type': 'reasoning',
|
||||
@@ -4415,20 +4440,28 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
else:
|
||||
reasoning_item = output[-1]
|
||||
|
||||
# Append to reasoning content
|
||||
parts = reasoning_item.get('content', [])
|
||||
if parts and parts[-1].get('type') == 'output_text':
|
||||
parts[-1]['text'] += reasoning_content
|
||||
else:
|
||||
reasoning_item['content'] = [
|
||||
{
|
||||
'type': 'output_text',
|
||||
'text': reasoning_content,
|
||||
}
|
||||
]
|
||||
if reasoning_content:
|
||||
# Append to reasoning content
|
||||
parts = reasoning_item.get('content', [])
|
||||
if parts and parts[-1].get('type') == 'output_text':
|
||||
parts[-1]['text'] += reasoning_content
|
||||
else:
|
||||
reasoning_item['content'] = [
|
||||
{
|
||||
'type': 'output_text',
|
||||
'text': reasoning_content,
|
||||
}
|
||||
]
|
||||
|
||||
data = {'content': serialize_output(full_output())}
|
||||
delta_type = 'content'
|
||||
data = {'content': serialize_output(full_output())}
|
||||
delta_type = 'content'
|
||||
|
||||
if reasoning_details:
|
||||
reasoning_item.setdefault('reasoning_details', []).extend(
|
||||
reasoning_details
|
||||
if isinstance(reasoning_details, list)
|
||||
else [reasoning_details]
|
||||
)
|
||||
|
||||
if value:
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user