diff --git a/b/cntoai/sync_model_to_llm.dspy b/b/cntoai/sync_model_to_llm.dspy index 917f0cf..6602670 100644 --- a/b/cntoai/sync_model_to_llm.dspy +++ b/b/cntoai/sync_model_to_llm.dspy @@ -170,7 +170,11 @@ async def sync_model_to_llm(ns={}): async def upsert_llm(sor, item): llm_data = build_llm_data(item) - exist_llm = await sor.R('llm', {'model': item.get('model')}) + # 厂商 id 是 llm 表主键,优先按 id 更新,避免模型名称变化后重复插入主键 + exist_llm = await sor.R('llm', {'id': llm_data.get('id')}) + if not exist_llm: + # 兼容历史数据:相同 model 可能已使用其他本地主键 + exist_llm = await sor.R('llm', {'model': item.get('model')}) if exist_llm: llm_data['id'] = exist_llm[0].get('id') await sor.U('llm', llm_data)