瀏覽代碼

fix(langgraph): 菜单生成切换非推理模型(agnes-2.5-flash)并加max_tokens=3000,耗时从60-96s降至~13s;容器内存限制6g→8g解决ChromaDB启动OOM

Xiaogang Liao 11 小時之前
父節點
當前提交
41d94f5ff2
共有 2 個文件被更改,包括 6 次插入7 次删除
  1. 4 5
      cfc-langgraph/app/api/meal.py
  2. 2 2
      cfc-langgraph/docker-compose.yml

+ 4 - 5
cfc-langgraph/app/api/meal.py

@@ -30,7 +30,7 @@ MENU_GENERATE_TEMPLATE = """请为{participant_count}人生成{date}的一日三
 {constraints_text}
 
 请返回 JSON 格式:
-{{"meals": [{{"type": "breakfast", "name": "早餐", "dishes": [{{"name": "菜品名", "ingredients": [{{"name": "食材", "grams": 100}}], "cooking_method": "做法一句话", "nutrition": {{"calories": 200}}}]}}]}}
+{{"meals": [{{"type": "breakfast", "name": "早餐", "dishes": [{{"name": "菜品名", "ingredients": [{{"name": "食材", "grams": 100}}], "cooking_method": "做法一句话", "nutrition": {{"calories": 200}}}}]}}]}}
 
 要求:
 1. 早/午/晚各至少1-2道菜
@@ -140,14 +140,13 @@ async def generate_menu(req: MenuGenerateRequest):
                 constraints_text=constraints_text,
             )
 
-        # max_tokens=1200:menu/generate 完整输出约 800-1200 token(已去掉 protein/carbs/fat/notes),
-        # 避免 LLM 写满 3000+ token 导致 60s+ 超时;实测 1000 token ≈ 17s,1200 兜底安全
         llm = ChatOpenAI(
-            model=settings.llm_model,
+            # agnes-2.5-flash:非推理模型,菜单生成 11s(deepseek 推理型会占满 token 导致 content 为空)
+            model="agnes-2.5-flash",
             api_key=settings.llm_api_key,
             base_url=settings.llm_base_url,
             temperature=0.7,
-            max_tokens=1200,
+            max_tokens=3000,
         )
 
         response = llm.invoke([

+ 2 - 2
cfc-langgraph/docker-compose.yml

@@ -21,7 +21,7 @@ services:
       retries: 3
 
   langgraph-svc:
-    image: cfc-langgraph-langgraph-svc:v9
+    image: cfc-langgraph-langgraph-svc:v10.3
     build:
       context: .
       dockerfile: Dockerfile
@@ -44,7 +44,7 @@ services:
       - cfc-net
     restart: unless-stopped
     # 内存硬限制:防止 ChromaDB/搜索任务异常膨胀吃满宿主机内存导致整机 OOM
-    mem_limit: 6g
+    mem_limit: 8g
     healthcheck:
       test: ["CMD", "python", "-c", "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:9000/health', timeout=5).status==200 else 1)"]
       interval: 30s