| | |
| | | def _check_response(self, response: httpx.Response): |
| | | """检查响应并处理错误""" |
| | | if response.status_code not in [200, 201]: |
| | | raise Exception(f"Failed to fetch data from API: {response.text}") |
| | | # raise Exception(f"Failed to fetch data from API: {response.status_code}") |
| | | logger.error(f"Failed to fetch data from API:") |
| | | logger.error(response.status_code) |
| | | response_data = response.json() |
| | | return response_data |
| | | |
| | |
| | | url = f"{self.base_url}/exceltalk/upload/files" |
| | | params = {'chat_id': chat_id, 'is_col': '0'} |
| | | |
| | | async with httpx.AsyncClient() as client: |
| | | async with httpx.AsyncClient(timeout=300) as client: |
| | | response = await client.post( |
| | | url, |
| | | files=files, |
| | |
| | | if decoded_line.startswith("data:"): |
| | | decoded_line = decoded_line[5:] |
| | | answer = json.loads(decoded_line) |
| | | answer["type"] = "message" |
| | | yield answer |
| | | except GeneratorExit as e: |
| | | logger.error("------------except GeneratorExit as e:---------------------") |
| | | logger.error(e) |
| | | print(e) |
| | | yield {"message": "内部错误", "type": "close"} |
| | | finally: |
| | | # 在所有数据接收完毕后返回close |
| | | yield {"message": "", "type": "close"} |
| | | # finally: |
| | | # # 在所有数据接收完毕后返回close |
| | | # yield {"message": "", "type": "close"} |
| | | |
| | | else: |
| | | yield f"Error: {response.status_code}" |
| | | continue |
| | | # yield f"Error: {response.status_code}" |
| | | else: |
| | | # 在所有数据接收完毕后返回close |
| | | yield {"message": "", "type": "close"} |
| | | |
| | | async def questions_talk(self, question, chat_id: str): |
| | | logger.error("---------------questions_talk--------------------------") |