| File was renamed from aigc-director/aigc-claw/backend/tool/llm_gemini.py |
| | |
| | | |
| | | import os |
| | | import time |
| | | import logging |
| | | from openai import OpenAI |
| | | from typing import List |
| | | |
| | | logger = logging.getLogger(__name__) |
| | | |
| | | |
| | | class Gemini: |
| | | """ |
| | |
| | | |
| | | # 检查响应类型 |
| | | if isinstance(response, str): |
| | | print(f"Gemini 返回字符串响应: {response}") |
| | | logger.error("Gemini returned a string response: %s", response) |
| | | raise Exception(f"API 返回错误: {response}") |
| | | |
| | | if response.choices and len(response.choices) > 0: |
| | | return response.choices[0].message.content |
| | | |
| | | except Exception as e: |
| | | print(f"Gemini 请求错误: {e}") |
| | | logger.warning("Gemini request failed: %s", e) |
| | | attempts += 1 |
| | | if attempts < self.max_attempts: |
| | | time.sleep(10) |