mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 19:37:36 +08:00
fix(dify runner): response message event incorrect when using agent app (#1325)
This commit is contained in:
committed by
GitHub
parent
8a6d9d76da
commit
446546b69f
2
.gitignore
vendored
2
.gitignore
vendored
@@ -38,5 +38,5 @@ botpy.log*
|
|||||||
/poc
|
/poc
|
||||||
/libs/wecom_api/test.py
|
/libs/wecom_api/test.py
|
||||||
/venv
|
/venv
|
||||||
/jp-tyo-churros-05.rockchin.top
|
|
||||||
test.py
|
test.py
|
||||||
|
/web_ui
|
||||||
@@ -164,12 +164,14 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
for image_id in image_ids
|
for image_id in image_ids
|
||||||
]
|
]
|
||||||
|
|
||||||
ignored_events = ["agent_message"]
|
ignored_events = []
|
||||||
|
|
||||||
inputs = {}
|
inputs = {}
|
||||||
|
|
||||||
inputs.update(query.variables)
|
inputs.update(query.variables)
|
||||||
|
|
||||||
|
pending_agent_message = ''
|
||||||
|
|
||||||
async for chunk in self.dify_client.chat_messages(
|
async for chunk in self.dify_client.chat_messages(
|
||||||
inputs=inputs,
|
inputs=inputs,
|
||||||
query=plain_text,
|
query=plain_text,
|
||||||
@@ -183,18 +185,23 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
|
|
||||||
if chunk["event"] in ignored_events:
|
if chunk["event"] in ignored_events:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if chunk['event'] == 'agent_message':
|
||||||
|
pending_agent_message += chunk['answer']
|
||||||
|
else:
|
||||||
|
if pending_agent_message.strip() != '':
|
||||||
|
pending_agent_message = pending_agent_message.replace('</details>Action:', '</details>')
|
||||||
|
yield llm_entities.Message(
|
||||||
|
role="assistant",
|
||||||
|
content=self._try_convert_thinking(pending_agent_message),
|
||||||
|
)
|
||||||
|
pending_agent_message = ''
|
||||||
|
|
||||||
if chunk["event"] == "agent_thought":
|
if chunk["event"] == "agent_thought":
|
||||||
|
|
||||||
if chunk['tool'] != '' and chunk['observation'] != '': # 工具调用结果,跳过
|
if chunk['tool'] != '' and chunk['observation'] != '': # 工具调用结果,跳过
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if chunk['thought'].strip() != '': # 文字回复内容
|
|
||||||
msg = llm_entities.Message(
|
|
||||||
role="assistant",
|
|
||||||
content=chunk["thought"],
|
|
||||||
)
|
|
||||||
yield msg
|
|
||||||
|
|
||||||
if chunk['tool']:
|
if chunk['tool']:
|
||||||
msg = llm_entities.Message(
|
msg = llm_entities.Message(
|
||||||
role="assistant",
|
role="assistant",
|
||||||
@@ -303,11 +310,11 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
|
|
||||||
msg = llm_entities.Message(
|
msg = llm_entities.Message(
|
||||||
role="assistant",
|
role="assistant",
|
||||||
content=chunk["data"]["outputs"][
|
content=self._try_convert_thinking(chunk["data"]["outputs"][
|
||||||
self.ap.provider_cfg.data["dify-service-api"]["workflow"][
|
self.ap.provider_cfg.data["dify-service-api"]["workflow"][
|
||||||
"output-key"
|
"output-key"
|
||||||
]
|
]
|
||||||
],
|
]),
|
||||||
)
|
)
|
||||||
|
|
||||||
yield msg
|
yield msg
|
||||||
|
|||||||
Reference in New Issue
Block a user