Преглед на файлове

langgraph调整,.env 文件我没上传

李宇 преди 1 месец
родител
ревизия
5ae69cae7f

+ 1 - 1
cfc-langgraph/app/agents/intent_classifier.py

@@ -38,7 +38,7 @@ class IntentClassifier:
             model=settings.llm_model,
             api_key=settings.llm_api_key,
             base_url=settings.llm_base_url,
-            temperature=0.1,
+            temperature=settings.llm_temperature,
             max_tokens=20,
         )
 

+ 6 - 1
cfc-langgraph/app/api/adapter.py

@@ -1,5 +1,5 @@
 from fastapi import APIRouter, HTTPException
-from pydantic import BaseModel
+from pydantic import BaseModel, ConfigDict
 from typing import Optional
 from app.graphs.chat_graph import create_chat_graph
 from app.graphs.analysis_graph import create_analysis_graph
@@ -16,6 +16,8 @@ class DifyMessage(BaseModel):
     content: str
 
 class DifyChatRequest(BaseModel):
+    # 前端 userId/conversationId 可能为数字,允许 int/float 自动转 str,避免 422
+    model_config = ConfigDict(coerce_numbers_to_str=True)
     query: str = ""
     user: str = "anonymous"
     conversation_id: str = ""
@@ -26,10 +28,13 @@ class DifyChatRequest(BaseModel):
     bot_name: str = "AI管家"
 
 class DifyAnalysisRequest(BaseModel):
+    # 前端 userId 可能为数字,允许 int/float 自动转 str,避免 422
+    model_config = ConfigDict(coerce_numbers_to_str=True)
     report_id: Optional[int] = None
     user_id: Optional[str] = None
     focus: Optional[str] = None
     messages: list[DifyMessage] = []
+    inputs: dict = {}
 
 class DifyChoice(BaseModel):
     index: int

+ 2 - 0
cfc-langgraph/app/config.py

@@ -7,6 +7,8 @@ class Settings(BaseSettings):
     llm_api_key: str
     llm_base_url: str = "https://api.deepseek.com/v1"
     llm_model: str = "deepseek-chat"
+    # 部分模型(如 kimi-k2.6)仅允许 temperature=1,统一从配置读取便于切换模型时调整
+    llm_temperature: float = 1.0
 
     # Embedding
     embedding_api_key: Optional[str] = None

+ 1 - 1
cfc-langgraph/app/graphs/analysis_graph.py

@@ -38,7 +38,7 @@ def create_analysis_graph():
         model=settings.llm_model,
         api_key=settings.llm_api_key,
         base_url=settings.llm_base_url,
-        temperature=0.3,
+        temperature=settings.llm_temperature,
     )
     llm_with_tools = llm.bind_tools([
         get_report_detail,

+ 1 - 1
cfc-langgraph/app/graphs/chat_graph.py

@@ -52,7 +52,7 @@ def create_chat_graph():
         model=settings.llm_model,
         api_key=settings.llm_api_key,
         base_url=settings.llm_base_url,
-        temperature=0.7,
+        temperature=settings.llm_temperature,
     )
     
     # 初始化嵌入模型用于记忆存储

+ 1 - 1
cfc-langgraph/app/graphs/health_butler_graph.py

@@ -53,7 +53,7 @@ def create_health_butler_graph():
         model=settings.llm_model,
         api_key=settings.llm_api_key,
         base_url=settings.llm_base_url,
-        temperature=0.7,
+        temperature=settings.llm_temperature,
     )
 
     # 嵌入和检索

+ 1 - 1
cfc-langgraph/app/graphs/recommend_graph.py

@@ -38,7 +38,7 @@ class RecommendAgent:
             model=settings.llm_model,
             api_key=settings.llm_api_key,
             base_url=settings.llm_base_url,
-            temperature=0.3,
+            temperature=settings.llm_temperature,
         )
         self.tools = [
             search_product_by_keyword,