修改聊天助手服务

This commit is contained in:
haotian 2025-09-18 15:30:48 +08:00
parent c73d6c906a
commit 2eab89eea1
2 changed files with 21 additions and 15 deletions

View File

@ -205,7 +205,8 @@ async def converse_with_chat_assistant(
与聊天助手进行对话 与聊天助手进行对话
""" """
await RAGFlowService.converse_with_chat_assistant_services(converse_params) result = await RAGFlowService.converse_with_chat_assistant_services(converse_params)
return parse_result(result)

View File

@ -179,20 +179,25 @@ class RAGFlowService:
# 与助手聊天 # 与助手聊天
@classmethod @classmethod
async def converse_with_chat_assistant_services(cls, converse_params: ConverseWithChatAssistantModel): async def converse_with_chat_assistant_services(cls, converse_params: ConverseWithChatAssistantModel):
async with AsyncRAGFlowClient(RAGFlowConfig.RAGFLOW_BASE_URL, RAGFlowConfig.RAGFLOW_API_KEY) as client: if converse_params.stream:
result = await client.converse_with_chat_assistant(**(converse_params.model_dump())) async with AsyncRAGFlowClient(RAGFlowConfig.RAGFLOW_BASE_URL, RAGFlowConfig.RAGFLOW_API_KEY) as client:
result = await client.converse_with_chat_assistant(**(converse_params.model_dump()))
i = 0
async for t in result: i = 0
try: async for t in result:
answer = t["data"].get("answer", "") try:
answer = cls.clean_text(answer) answer = t["data"].get("answer", "")
print(repr(answer[i:])) answer = cls.clean_text(answer)
i = len(answer) print(repr(answer[i:]))
except Exception as e: i = len(answer)
print(e) except Exception as e:
print(t) print(e)
await asyncio.sleep(0.2) print(t)
await asyncio.sleep(0.2)
else:
async with AsyncRAGFlowClient(RAGFlowConfig.RAGFLOW_BASE_URL, RAGFlowConfig.RAGFLOW_API_KEY) as client:
result = await client.converse_with_chat_assistant(**(converse_params.model_dump()))
return result