mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-27 16:04:21 +00:00
fix:The handling of the streaming tool calls has been fixed, but there are still bugs in the model's reply messages with thoughtfulness.
This commit is contained in:
@@ -289,30 +289,16 @@ class ModelScopeChatCompletions(requester.ProviderAPIRequester):
|
||||
# delta_content = re.sub(r'<think>.*?</think>', '', delta_content, flags=re.DOTALL)
|
||||
|
||||
# 处理工具调用增量
|
||||
delta_tool_calls = None
|
||||
if delta.get('tool_calls'):
|
||||
delta_tool_calls = []
|
||||
for tool_call in delta['tool_calls']:
|
||||
tc_id = tool_call.get('id')
|
||||
if tc_id:
|
||||
if tc_id not in tool_calls_map:
|
||||
# 新的工具调用
|
||||
tool_calls_map[tc_id] = llm_entities.ToolCall(
|
||||
id=tc_id,
|
||||
type=tool_call.get('type', 'function'),
|
||||
function=llm_entities.FunctionCall(
|
||||
name=tool_call.get('function', {}).get('name', ''),
|
||||
arguments=tool_call.get('function', {}).get('arguments', ''),
|
||||
),
|
||||
)
|
||||
delta_tool_calls.append(tool_calls_map[tc_id])
|
||||
else:
|
||||
# 追加函数参数
|
||||
func_args = tool_call.get('function', {}).get('arguments', '')
|
||||
if func_args:
|
||||
tool_calls_map[tc_id].function.arguments += func_args
|
||||
# 返回更新后的完整工具调用
|
||||
delta_tool_calls.append(tool_calls_map[tc_id])
|
||||
if tool_call['id'] and tool_call['function']['name']:
|
||||
tool_id = tool_call['id']
|
||||
tool_name = tool_call['function']['name']
|
||||
else:
|
||||
tool_call['id'] = tool_id
|
||||
tool_call['function']['name'] = tool_name
|
||||
if tool_call['type'] is None:
|
||||
tool_call['type'] = 'function'
|
||||
|
||||
# 跳过空的第一个 chunk(只有 role 没有内容)
|
||||
if chunk_idx == 0 and not delta_content and not reasoning_content and not delta.get('tool_calls'):
|
||||
@@ -323,7 +309,7 @@ class ModelScopeChatCompletions(requester.ProviderAPIRequester):
|
||||
chunk_data = {
|
||||
'role': role,
|
||||
'content': delta_content if delta_content else None,
|
||||
'tool_calls': delta_tool_calls if delta_tool_calls else None,
|
||||
'tool_calls': delta.get('tool_calls'),
|
||||
'is_final': bool(finish_reason),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user