mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-09 20:50:58 +00:00
fix:del some print ,and amend respback on stream judge ,and del in dingtalk this is_stream_output_supported() use
This commit is contained in:
@@ -185,8 +185,6 @@ class DashScopeAPIRunner(runner.RequestRunner):
|
||||
# 将参考资料替换到文本中
|
||||
pending_content = self._replace_references(pending_content, references_dict)
|
||||
|
||||
|
||||
|
||||
yield llm_entities.Message(
|
||||
role='assistant',
|
||||
content=pending_content,
|
||||
@@ -261,13 +259,11 @@ class DashScopeAPIRunner(runner.RequestRunner):
|
||||
role='assistant',
|
||||
content=pending_content,
|
||||
is_final=is_final,
|
||||
|
||||
)
|
||||
|
||||
# 保存当前会话的session_id用于下次对话的语境
|
||||
query.session.using_conversation.uuid = stream_output.get('session_id')
|
||||
|
||||
|
||||
else:
|
||||
for chunk in response:
|
||||
if chunk.get('status_code') != 200:
|
||||
|
||||
@@ -148,7 +148,6 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
||||
if mode == 'workflow':
|
||||
if chunk['event'] == 'node_finished':
|
||||
if not is_stream:
|
||||
|
||||
if chunk['data']['node_type'] == 'answer':
|
||||
yield llm_entities.Message(
|
||||
role='assistant',
|
||||
@@ -274,7 +273,6 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
||||
content=self._try_convert_thinking(pending_agent_message),
|
||||
)
|
||||
|
||||
|
||||
if chunk['event'] == 'agent_thought':
|
||||
if chunk['tool'] != '' and chunk['observation'] != '': # 工具调用结果,跳过
|
||||
continue
|
||||
|
||||
@@ -2,7 +2,6 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import copy
|
||||
from ssl import ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE
|
||||
import typing
|
||||
from .. import runner
|
||||
from ...core import entities as core_entities
|
||||
@@ -30,11 +29,14 @@ class LocalAgentRunner(runner.RequestRunner):
|
||||
|
||||
class ToolCallTracker:
|
||||
"""工具调用追踪器"""
|
||||
|
||||
def __init__(self):
|
||||
self.active_calls: dict[str,dict] = {}
|
||||
self.active_calls: dict[str, dict] = {}
|
||||
self.completed_calls: list[llm_entities.ToolCall] = []
|
||||
|
||||
async def run(self, query: core_entities.Query) -> typing.AsyncGenerator[llm_entities.Message | llm_entities.MessageChunk, None]:
|
||||
async def run(
|
||||
self, query: core_entities.Query
|
||||
) -> typing.AsyncGenerator[llm_entities.Message | llm_entities.MessageChunk, None]:
|
||||
"""运行请求"""
|
||||
pending_tool_calls = []
|
||||
|
||||
@@ -89,16 +91,14 @@ class LocalAgentRunner(runner.RequestRunner):
|
||||
|
||||
is_stream = query.adapter.is_stream_output_supported()
|
||||
try:
|
||||
# print(await query.adapter.is_stream_output_supported())
|
||||
is_stream = await query.adapter.is_stream_output_supported()
|
||||
|
||||
except AttributeError:
|
||||
is_stream = False
|
||||
# while True:
|
||||
# pass
|
||||
|
||||
if not is_stream:
|
||||
# 非流式输出,直接请求
|
||||
# print(123)
|
||||
|
||||
msg = await query.use_llm_model.requester.invoke_llm(
|
||||
query,
|
||||
query.use_llm_model,
|
||||
@@ -108,7 +108,6 @@ class LocalAgentRunner(runner.RequestRunner):
|
||||
)
|
||||
yield msg
|
||||
final_msg = msg
|
||||
print(final_msg)
|
||||
else:
|
||||
# 流式输出,需要处理工具调用
|
||||
tool_calls_map: dict[str, llm_entities.ToolCall] = {}
|
||||
@@ -122,27 +121,26 @@ class LocalAgentRunner(runner.RequestRunner):
|
||||
):
|
||||
assert isinstance(msg, llm_entities.MessageChunk)
|
||||
yield msg
|
||||
# if msg.tool_calls:
|
||||
# for tool_call in msg.tool_calls:
|
||||
# if tool_call.id not in tool_calls_map:
|
||||
# tool_calls_map[tool_call.id] = llm_entities.ToolCall(
|
||||
# id=tool_call.id,
|
||||
# type=tool_call.type,
|
||||
# function=llm_entities.FunctionCall(
|
||||
# name=tool_call.function.name if tool_call.function else '',
|
||||
# arguments=''
|
||||
# ),
|
||||
# )
|
||||
# if tool_call.function and tool_call.function.arguments:
|
||||
# # 流式处理中,工具调用参数可能分多个chunk返回,需要追加而不是覆盖
|
||||
# tool_calls_map[tool_call.id].function.arguments += tool_call.function.arguments
|
||||
if msg.tool_calls:
|
||||
for tool_call in msg.tool_calls:
|
||||
if tool_call.id not in tool_calls_map:
|
||||
tool_calls_map[tool_call.id] = llm_entities.ToolCall(
|
||||
id=tool_call.id,
|
||||
type=tool_call.type,
|
||||
function=llm_entities.FunctionCall(
|
||||
name=tool_call.function.name if tool_call.function else '',
|
||||
arguments=''
|
||||
),
|
||||
)
|
||||
if tool_call.function and tool_call.function.arguments:
|
||||
# 流式处理中,工具调用参数可能分多个chunk返回,需要追加而不是覆盖
|
||||
tool_calls_map[tool_call.id].function.arguments += tool_call.function.arguments
|
||||
final_msg = llm_entities.Message(
|
||||
role=msg.role,
|
||||
content=msg.all_content,
|
||||
tool_calls=list(tool_calls_map.values()),
|
||||
)
|
||||
|
||||
|
||||
pending_tool_calls = final_msg.tool_calls
|
||||
|
||||
req_messages.append(final_msg)
|
||||
@@ -193,8 +191,7 @@ class LocalAgentRunner(runner.RequestRunner):
|
||||
id=tool_call.id,
|
||||
type=tool_call.type,
|
||||
function=llm_entities.FunctionCall(
|
||||
name=tool_call.function.name if tool_call.function else '',
|
||||
arguments=''
|
||||
name=tool_call.function.name if tool_call.function else '', arguments=''
|
||||
),
|
||||
)
|
||||
if tool_call.function and tool_call.function.arguments:
|
||||
@@ -206,7 +203,6 @@ class LocalAgentRunner(runner.RequestRunner):
|
||||
tool_calls=list(tool_calls_map.values()),
|
||||
)
|
||||
else:
|
||||
print("非流式")
|
||||
# 处理完所有调用,再次请求
|
||||
msg = await query.use_llm_model.requester.invoke_llm(
|
||||
query,
|
||||
|
||||
Reference in New Issue
Block a user