From cbb634f9c133c726a00faf8199ba8954e18d4b05 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 15 十月 2024 14:33:45 +0800 Subject: [PATCH] 智能体列表增加排序和类型字段 --- app/service/ragflow.py | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/service/ragflow.py b/app/service/ragflow.py index 5fbe175..934af1a 100644 --- a/app/service/ragflow.py +++ b/app/service/ragflow.py @@ -51,8 +51,32 @@ # 妫�鏌ュ搷搴旂姸鎬佺爜 if response.status_code == 200: # 娴佸紡璇诲彇鍝嶅簲 - async for answer in response.aiter_text(): - yield answer + try: + async for answer in response.aiter_text(): + yield answer + except GeneratorExit as e: + print(e) + return else: yield f"Error: {response.status_code}" + async def get_chat_sessions(self, token: str, dialog_id: str) -> list: + url = f"{self.base_url}/v1/conversation/list?dialog_id={dialog_id}" + headers = { + "Authorization": token + } + async with httpx.AsyncClient() as client: + response = await client.get(url, headers=headers) + if response.status_code != 200: + raise Exception(f"Failed to fetch data from Ragflow API: {response.text}") + + data = response.json().get("data", []) + result = [ + { + "id": item["id"], + "name": item["name"], + "updated_time": item["update_time"] + } + for item in data + ] + return result -- Gitblit v1.8.0