| | |
| | | |
| | | 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, url, data, headers): |
| | | complete_response = "" |
| | | async for line in self.http_stream(url, data, headers): |
| | | # logger.error(line) |
| | | print(line) |
| | | if line.startswith("data:"): |
| | | complete_response = line.strip("data:").strip() |
| | | else: |
| | |
| | | logger.info("Invalid JSON data------------------") |
| | | # print(e) |
| | | |
| | | async def chat_sessions(self, url, data, headers): |
| | | |
| | | res = await self.http_post(url, data, headers) |
| | | if res.status_code == 200: |
| | | return res.json() |
| | | else: |
| | | return {} |
| | | |
| | | |
| | | |
| | | @staticmethod |
| | | async def request_data(question, session_id=""): |
| | | return { |
| | | "question": question, |
| | | "stream": True, |
| | | "session_id": session_id |
| | | } |
| | | |
| | | |
| | | |