fix: streamline gemini flow and add e2e test

This commit is contained in:
2026-03-08 23:58:17 +08:00
parent 82284ce3fb
commit 2ab27eb914
3 changed files with 151 additions and 8 deletions

View File

@@ -24,7 +24,6 @@ GEMINI_API_KEY = os.getenv(
GEMINI_IMAGE_MODEL = os.getenv("GEMINI_IMAGE_MODEL", "gemini-3-pro-image-preview")
GEMINI_IMAGE_SIZE = os.getenv("GEMINI_IMAGE_SIZE", "2K")
GEMINI_PERSON_GENERATION = os.getenv("GEMINI_PERSON_GENERATION", "")
GEMINI_THINKING_LEVEL = os.getenv("GEMINI_THINKING_LEVEL", "MINIMAL")
class GeminiExtractV2Service(BaseService):
@@ -66,7 +65,6 @@ class GeminiExtractV2Service(BaseService):
) -> Dict:
valid_ratios = {"1:1", "9:16", "16:9", "3:4", "4:3", "3:2", "2:3", "5:4", "4:5"}
valid_sizes = {"1K", "2K", "4K"}
valid_thinking = {"MINIMAL", "LOW", "MEDIUM", "HIGH"}
image_config = {}
if aspect_ratio in valid_ratios:
@@ -82,10 +80,6 @@ class GeminiExtractV2Service(BaseService):
if image_config:
generation_config["imageConfig"] = image_config
thinking_val = (thinking_level or GEMINI_THINKING_LEVEL or "").upper().strip()
if thinking_val in valid_thinking:
generation_config["thinkingConfig"] = {"thinkingLevel": thinking_val}
return generation_config
@staticmethod

View File

@@ -18,6 +18,7 @@ load_dotenv()
# 图绘平台配置
TUHUI_BASE_URL = os.getenv("TUHUI_BASE_URL", "https://tuhui.cloud")
TUHUI_FALLBACK_BASE_URL = "https://tuhui.cloud"
TUHUI_DIRECT_BASE_URL = os.getenv("TUHUI_DIRECT_BASE_URL", "http://1.12.50.92:8002")
TUHUI_WEB_BASE_URL = os.getenv("TUHUI_WEB_BASE_URL", "https://tuhui.cloud").rstrip("/")
TUHUI_PHONE = os.getenv("TUHUI_PHONE", "17520145271") # 图绘账号手机号
TUHUI_PASSWORD = os.getenv("TUHUI_PASSWORD", "zuowei1216") # 图绘账号密码
@@ -59,7 +60,11 @@ class TuhuiUploadService:
def __init__(self):
self.base_url = TUHUI_BASE_URL.rstrip("/")
self.base_urls = []
for candidate in (TUHUI_FALLBACK_BASE_URL.rstrip("/"), self.base_url):
for candidate in (
TUHUI_FALLBACK_BASE_URL.rstrip("/"),
TUHUI_DIRECT_BASE_URL.rstrip("/"),
self.base_url,
):
if candidate and candidate not in self.base_urls:
self.base_urls.append(candidate)
if self.base_urls:
@@ -160,7 +165,7 @@ class TuhuiUploadService:
return TuhuiUploadResult(False, "", 0, message="登录失败")
# 准备上传数据
price = price or self.default_price
price = self.default_price if price is None else price
# 读取图片文件
if not os.path.exists(image_path):