修改聊天助手服务
This commit is contained in:
parent
c73d6c906a
commit
2eab89eea1
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -179,20 +179,25 @@ class RAGFlowService:
|
||||
# 与助手聊天
|
||||
@classmethod
|
||||
async def converse_with_chat_assistant_services(cls, converse_params: ConverseWithChatAssistantModel):
|
||||
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:
|
||||
try:
|
||||
answer = t["data"].get("answer", "")
|
||||
answer = cls.clean_text(answer)
|
||||
print(repr(answer[i:]))
|
||||
i = len(answer)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print(t)
|
||||
await asyncio.sleep(0.2)
|
||||
if converse_params.stream:
|
||||
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:
|
||||
try:
|
||||
answer = t["data"].get("answer", "")
|
||||
answer = cls.clean_text(answer)
|
||||
print(repr(answer[i:]))
|
||||
i = len(answer)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user