mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-21 09:47:13 +00:00
Merge pull request #1376 from RockChinQ/devin/1746754093-fix-chunk-reference-bug
fix: initialize chunk variable before reference in difysvapi.py
This commit is contained in:
@@ -115,6 +115,8 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
|
|
||||||
inputs.update(query.variables)
|
inputs.update(query.variables)
|
||||||
|
|
||||||
|
chunk = None # 初始化chunk变量,防止在没有响应时引用错误
|
||||||
|
|
||||||
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,
|
||||||
@@ -145,6 +147,9 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
)
|
)
|
||||||
basic_mode_pending_chunk = ''
|
basic_mode_pending_chunk = ''
|
||||||
|
|
||||||
|
if chunk is None:
|
||||||
|
raise errors.DifyAPIError("Dify API 没有返回任何响应,请检查网络连接和API配置")
|
||||||
|
|
||||||
query.session.using_conversation.uuid = chunk["conversation_id"]
|
query.session.using_conversation.uuid = chunk["conversation_id"]
|
||||||
|
|
||||||
async def _agent_chat_messages(
|
async def _agent_chat_messages(
|
||||||
@@ -172,6 +177,8 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
|
|
||||||
pending_agent_message = ''
|
pending_agent_message = ''
|
||||||
|
|
||||||
|
chunk = None # 初始化chunk变量,防止在没有响应时引用错误
|
||||||
|
|
||||||
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,
|
||||||
@@ -235,6 +242,9 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
if chunk['event'] == 'error':
|
if chunk['event'] == 'error':
|
||||||
raise errors.DifyAPIError("dify 服务错误: " + chunk['message'])
|
raise errors.DifyAPIError("dify 服务错误: " + chunk['message'])
|
||||||
|
|
||||||
|
if chunk is None:
|
||||||
|
raise errors.DifyAPIError("Dify API 没有返回任何响应,请检查网络连接和API配置")
|
||||||
|
|
||||||
query.session.using_conversation.uuid = chunk["conversation_id"]
|
query.session.using_conversation.uuid = chunk["conversation_id"]
|
||||||
|
|
||||||
async def _workflow_messages(
|
async def _workflow_messages(
|
||||||
|
|||||||
Reference in New Issue
Block a user