feat(commentary): 双 provider 评论 — Angel(Agnes) + 美团大模型(LongCat)

- 新增 articles.commentary_meituan{_status,_model,_error} 4 列 + commentary_engine
- LlmSetting 加 meituan_api_key/base_url/chat_model/interval_sec/enabled/commentary_prompt
- 新 app/services/llm/providers.py 工厂,支持多 provider 客户端
- enrichment 流程改为 commentary_angel + commentary_meituan 并行(asyncio.gather),
  任一 provider 失败不影响另一个
- enrichment_loop 状态判定:任一 provider 状态不是 ok 都视为待 enrich
- alembic 0004_dual_commentary 迁移
- 前端 Feed 卡片 + ArticleDetail 详情页各加一条'美团评论'卡
- AdminLlmSettings 加美团 provider 配置卡(独立 api_key 编辑器,不回显明文)
- LlmSettingOut.meituan_api_key_set (bool) 替代直接回传 key
- 默认 URL https://api.longcat.chat/openai/v1 / 默认模型 LongCat-2.0-Preview
This commit is contained in:
xiaji
2026-06-12 19:00:00 +08:00
parent 3ab6e4c7d0
commit bc36a1fc38
15 changed files with 2746 additions and 48 deletions

View File

@@ -39,8 +39,9 @@ async def get_settings():
commentary_prompt=defaults["commentary_prompt"],
image_prompt_template=defaults["image_prompt_template"],
blocklist_tags=[],
meituan_api_key_set=False,
)
return LlmSettingOut.model_validate(row)
return LlmSettingOut.from_row(row)
@router.put("/settings", response_model=LlmSettingOut)
@@ -57,7 +58,7 @@ async def update_settings(body: LlmSettingUpdate):
setattr(row, k, v)
await session.commit()
await session.refresh(row)
return LlmSettingOut.model_validate(row)
return LlmSettingOut.from_row(row)
class ResetResponse(BaseModel):
@@ -110,6 +111,30 @@ async def test_connection():
return TestResponse(ok=False, configured=True, detail=f"{type(e).__name__}: {e}")
@router.post("/settings/test-meituan", response_model=TestResponse)
async def test_meituan_connection():
"""最小测试:发一个 'hi' chat 请求,确认美团大模型 LongCat 端点通。"""
from app.services.llm.providers import get_meituan_client
async with AsyncSessionLocal() as session:
row = (await session.execute(select(LlmSetting).where(LlmSetting.id == 1))).scalar_one_or_none()
if row is None:
return TestResponse(ok=False, configured=False, detail="美团 provider 未配置(api_key 空)")
client = get_meituan_client(row)
if client is None:
return TestResponse(ok=False, configured=False, detail="美团 MEITUAN_API_KEY 未配置")
try:
reply = await client.chat(
system="你是测试助手,只用 1 个词回答 OK 或 FAIL。",
user="ping",
temperature=0.0,
max_tokens=10,
)
return TestResponse(ok=True, configured=True, detail=f"reply={reply[:50]!r}")
except Exception as e:
return TestResponse(ok=False, configured=True, detail=f"{type(e).__name__}: {e}")
class EnrichTriggerResponse(BaseModel):
triggered: bool
detail: str = ""