style: auto-format with black + isort + ruff + prettier [skip ci-format-check]
This commit is contained in:
@@ -88,8 +88,10 @@ def call_fast_json(
|
||||
"""
|
||||
t0 = time.time()
|
||||
import httpx
|
||||
|
||||
try:
|
||||
from packages.shared import get_shared_settings
|
||||
|
||||
settings = get_shared_settings()
|
||||
api_key = settings.doubao_api_key
|
||||
base_url = (settings.doubao_base_url or "https://ark.cn-beijing.volces.com/api/v3").rstrip("/")
|
||||
@@ -103,10 +105,13 @@ def call_fast_json(
|
||||
"model": use_model,
|
||||
"messages": [
|
||||
{"role": "system", "content": _FAST_SYSTEM},
|
||||
{"role": "user", "content": [
|
||||
{"type": "image_url", "image_url": {"url": img_url}},
|
||||
{"type": "text", "text": _FAST_USER},
|
||||
]},
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "image_url", "image_url": {"url": img_url}},
|
||||
{"type": "text", "text": _FAST_USER},
|
||||
],
|
||||
},
|
||||
],
|
||||
"temperature": 0.1,
|
||||
"max_tokens": max_tokens,
|
||||
@@ -129,15 +134,19 @@ def call_fast_json(
|
||||
)
|
||||
elapsed = time.time() - t0
|
||||
if resp.status_code != 200:
|
||||
logger.warning("[vision.v2] fast_json HTTP %d elapsed=%.1fs body=%s", resp.status_code, elapsed, resp.text[:200])
|
||||
logger.warning(
|
||||
"[vision.v2] fast_json HTTP %d elapsed=%.1fs body=%s", resp.status_code, elapsed, resp.text[:200]
|
||||
)
|
||||
# 如果400说明不支持thinking参数,降级重试一次
|
||||
if resp.status_code == 400 and "thinking" in resp.text.lower():
|
||||
payload.pop("thinking", None)
|
||||
payload.pop("reasoning_effort", None)
|
||||
t1 = time.time()
|
||||
resp = httpx.post(url,
|
||||
time.time()
|
||||
resp = httpx.post(
|
||||
url,
|
||||
headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"},
|
||||
json=payload, timeout=timeout,
|
||||
json=payload,
|
||||
timeout=timeout,
|
||||
)
|
||||
elapsed = time.time() - t0
|
||||
if resp.status_code != 200:
|
||||
@@ -151,9 +160,14 @@ def call_fast_json(
|
||||
logger.warning("[vision.v2] fast_json 返回 None elapsed=%.1fs", elapsed)
|
||||
return None
|
||||
usage = data.get("usage") or {}
|
||||
logger.info("[vision.v2] fast_json 直连完成 model=%s elapsed=%.1fs in=%d out=%d reasoning=%d",
|
||||
use_model, elapsed, usage.get("prompt_tokens",0), usage.get("completion_tokens",0),
|
||||
usage.get("reasoning_tokens",0))
|
||||
logger.info(
|
||||
"[vision.v2] fast_json 直连完成 model=%s elapsed=%.1fs in=%d out=%d reasoning=%d",
|
||||
use_model,
|
||||
elapsed,
|
||||
usage.get("prompt_tokens", 0),
|
||||
usage.get("completion_tokens", 0),
|
||||
usage.get("reasoning_tokens", 0),
|
||||
)
|
||||
elapsed = time.time() - t0
|
||||
if raw is None:
|
||||
logger.warning("[vision.v2] fast_json 返回 None elapsed=%.1fs model=%s", elapsed, use_model)
|
||||
|
||||
Reference in New Issue
Block a user