feat: automate image pipeline and simplify gemini flow

This commit is contained in:
2026-03-08 23:42:18 +08:00
parent 3a78eb304a
commit 82284ce3fb
6 changed files with 660 additions and 520 deletions

View File

@@ -20,6 +20,13 @@ logger = logging.getLogger("cs_agent")
ANALYSIS_PROMPT = """你是一个电商图片处理评估专家。
客户需求如下:
{customer_requirement}
请结合客户需求和图片内容一起判断,不要只看图片本身。
如果客户明确说了“找原图/找图/素材/大图”,类型优先判断为“找原图/素材提取”类;
如果客户明确说了“修复/高清/清晰/放大”,类型优先判断为“高清修复”类。
请仔细分析这张图片,输出以下字段,每行一个,不要多余内容:
敏感内容: <yes|no>
@@ -101,7 +108,7 @@ class ImageAnalyzerService:
logger.debug(f"[ImageAnalyzer] 获取尺寸失败: {e}")
return (0, 0)
async def analyze(self, image_url: str) -> Dict[str, Any]:
async def analyze(self, image_url: str, customer_requirement: str = "") -> Dict[str, Any]:
"""
异步分析图片,返回结构化结果
@@ -133,7 +140,8 @@ class ImageAnalyzerService:
return self._fallback(image_url, "未配置 API Key")
# 缓存检查
cache_key = image_url
customer_requirement = str(customer_requirement or "").strip()
cache_key = f"{image_url}|{customer_requirement}"
now = time.monotonic()
cached = self._analysis_cache.get(cache_key)
if cached:
@@ -149,6 +157,9 @@ class ImageAnalyzerService:
try:
client = AsyncOpenAI(base_url=self.base_url, api_key=self.api_key)
prompt_text = ANALYSIS_PROMPT.format(
customer_requirement=customer_requirement or "未提供明确补充需求"
)
response = await asyncio.wait_for(
client.chat.completions.create(
model=self.vision_model,
@@ -156,7 +167,7 @@ class ImageAnalyzerService:
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": image_url}},
{"type": "text", "text": ANALYSIS_PROMPT}
{"type": "text", "text": prompt_text}
]
}],
max_tokens=500
@@ -170,6 +181,7 @@ class ImageAnalyzerService:
elapsed = time.monotonic() - start
result = self._parse_result(image_url, content)
result["customer_requirement"] = customer_requirement
result["elapsed"] = round(elapsed, 2)
# 获取尺寸
@@ -241,6 +253,7 @@ class ImageAnalyzerService:
return {
"url": url,
"customer_requirement": "",
"complexity": complexity,
"reason": extract("原因"),
"subject": extract("主体"),
@@ -280,6 +293,7 @@ class ImageAnalyzerService:
from datetime import datetime
return {
"url": url,
"customer_requirement": "",
"complexity": "normal",
"reason": reason,
"subject": "",