From bde5797004bfb040003c1495027c4ae99d8f9f9a Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期二, 31 十二月 2024 16:59:05 +0800 Subject: [PATCH] tmp --- app/service/v2/app_driver/chat_dialog.py | 20 ++++++++++ app/service/v2/app_driver/chat_basic.py | 5 ++ app/service/v2/app_driver/chat_workflow.py | 0 app/service/v2/app_driver/chat_agent.py | 0 app/service/v2/app_driver/chat_base.py | 40 ++++++++++++++++++++ 5 files changed, 65 insertions(+), 0 deletions(-) diff --git a/app/service/v2/app_driver/chat_agent.py b/app/service/v2/app_driver/chat_agent.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/service/v2/app_driver/chat_agent.py diff --git a/app/service/v2/app_driver/chat_base.py b/app/service/v2/app_driver/chat_base.py new file mode 100644 index 0000000..baacbc9 --- /dev/null +++ b/app/service/v2/app_driver/chat_base.py @@ -0,0 +1,40 @@ +import httpx +from pycparser.ply.yacc import token + + +class ChatBase: + + @staticmethod + async def http_stream(url, data, headers, timeout=300): + async with httpx.AsyncClient(timeout=timeout) as client: + + async with client.stream("POST", url, json=data, headers=headers) as response: + if response.status_code == 200: + try: + async for answer in response.aiter_text(): + yield answer + except GeneratorExit as e: + print(e) + return + else: + yield f"Error: {response.status_code}" + + @staticmethod + async def http_post(url, data, headers, timeout=300): + async with httpx.AsyncClient(timeout=timeout) as client: + response = client.post(url, json=data, headers=headers) + return response + + @staticmethod + async def http_get(url, params, headers, timeout=300): + async with httpx.AsyncClient(timeout=timeout) as client: + response = client.get(url, params=params, headers=headers) + return response + + @staticmethod + async def get_headers(token): + headers = { + # 'Content-Type': 'application/json', + 'Authorization': f'Bearer {token}' + } + diff --git a/app/service/v2/app_driver/chat_basic.py b/app/service/v2/app_driver/chat_basic.py new file mode 100644 index 0000000..c6bc298 --- /dev/null +++ b/app/service/v2/app_driver/chat_basic.py @@ -0,0 +1,5 @@ + + +class ChatDialog: + def __init__(self, token): + self.token = token diff --git a/app/service/v2/app_driver/chat_dialog.py b/app/service/v2/app_driver/chat_dialog.py new file mode 100644 index 0000000..0ad7c3c --- /dev/null +++ b/app/service/v2/app_driver/chat_dialog.py @@ -0,0 +1,20 @@ +from app.service.v2.app_driver.chat_base import ChatBase + + +class ChatDialog(ChatBase): + + + def __init__(self, token): + self.token = token + + + async def get_headers(self): + return { + 'Content-Type': 'application/json', + 'Authorization': f'Bearer {self.token}' + } + + + async def chat_completions(self): + async for rag_response in self.http_stream(token, chat_id, chat_history): + ... \ No newline at end of file diff --git a/app/service/v2/app_driver/chat_workflow.py b/app/service/v2/app_driver/chat_workflow.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/service/v2/app_driver/chat_workflow.py -- Gitblit v1.8.0