From 23423fb0de7a6a7fa83083e000c1e7884672537c Mon Sep 17 00:00:00 2001 From: Ethan-Zhang Date: Fri, 21 Nov 2025 14:14:01 +0800 Subject: [PATCH] Fix: use or query for llm api --- apps/services/llm.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/services/llm.py b/apps/services/llm.py index 2a1fbcba3a..92cb8a1a92 100644 --- a/apps/services/llm.py +++ b/apps/services/llm.py @@ -193,11 +193,21 @@ class LLMManager: # 构建查询条件:包含用户模型和系统模型 base_query = {"$or": [{"user_sub": user_sub}, {"user_sub": ""}]} + if llm_id: - base_query["llm_id"] = llm_id + base_query["_id"] = llm_id + if model_type: # 支持type字段既可以是字符串也可以是数组 - base_query["type"] = model_type + # 使用 $or 来匹配字符串或数组中包含指定类型的情况 + type_query = { + "$or": [ + {"type": model_type}, # 匹配字符串格式: type = "chat" + {"type": {"$in": [model_type]}} # 匹配数组格式: type = ["chat", "function_call"] + ] + } + # 将 type 条件与现有查询条件合并 + base_query = {"$and": [base_query, type_query]} result = await llm_collection.find(base_query).sort({"created_at": 1}).to_list(length=None) -- Gitee