修改聊天助手服务
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
|
@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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user