调整后台文字模型请求发送图片或者视频的方式base64,而不是现在的链接形式,增加后台配置

This commit is contained in:
2026-07-16 13:36:37 +08:00
parent 38040dfb0d
commit 4d872036b2
10 changed files with 198 additions and 60 deletions
@@ -36,7 +36,9 @@ def _load_refs(record: ChatGenerationTask) -> list[dict]:
return []
def _build_user_content(record: ChatGenerationTask) -> list[dict[str, Any]]:
async def _build_user_content(record: ChatGenerationTask, db: AsyncSession | None = None) -> list[dict[str, Any]]:
from app.utils.media import media_to_base64
if record.gen_type == "image":
params = f"图片参数:分辨率档位={record.image_size or '2K'},比例={record.image_proportion or '1:1'},像素={record.image_px or '2048x2048'}"
else:
@@ -54,7 +56,15 @@ def _build_user_content(record: ChatGenerationTask) -> list[dict[str, Any]]:
ref_url = ref.get("url") or ""
if not ref_url:
continue
url = _absolute_url(ref_url)
if db and await get_llm_media_as_base64(db):
if ref_type == "image":
url = await media_to_base64(ref_url, "image/png")
elif ref_type == "video":
url = await media_to_base64(ref_url, "video/mp4")
else:
continue
else:
url = _absolute_url(ref_url)
if ref_type == "image":
parts.append({"type": "image_url", "image_url": {"url": url}})
elif ref_type == "video":
@@ -94,7 +104,7 @@ async def build_prompt_with_chatapi(db: AsyncSession, record: ChatGenerationTask
"model": config.model_name,
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": _build_user_content(record)},
{"role": "user", "content": await _build_user_content(record, db)},
],
"max_tokens": config.max_tokens,
"temperature": config.temperature,