From 319e3e93bbb4807da58db2ac72bb8f3029738dd7 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期二, 03 十二月 2024 13:48:40 +0800 Subject: [PATCH] dify报告合并 --- app/service/difyService.py | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/app/service/difyService.py b/app/service/difyService.py index 78daa44..93bc62b 100644 --- a/app/service/difyService.py +++ b/app/service/difyService.py @@ -154,6 +154,33 @@ f.write(response.content) + async def workflow(self, token: str, user_id: int, inputs: dict): + + target_url = f"{self.base_url}/v1/workflows/run" + data = { + "inputs": inputs, + "response_mode": "streaming", + "user": str(user_id), + "files":[] + } + + async with httpx.AsyncClient(timeout=1800) as client: + headers = { + 'Content-Type': 'application/json', + 'Authorization': f'Bearer {token}' + } + async with client.stream("POST", target_url, data=json.dumps(data), headers=headers) as response: + if response.status_code == 200: + try: + async for answer in response.aiter_text(): + # print(f"response of ragflow chat: {answer}") + yield answer + except GeneratorExit as e: + print(e) + return + else: + yield f"Error: {response.status_code}" + if __name__ == "__main__": -- Gitblit v1.8.0