Explorar o código

解决chat api进行非数据库查询时输出Based on general knowledge.

wangxq hai 1 mes
pai
achega
54e550cafb

+ 2 - 1
custompgvector/pgvector.py

@@ -670,7 +670,8 @@ class PG_VectorStore(VannaBase):
             
             
             # 检查过滤后结果是否为空
             # 检查过滤后结果是否为空
             if results and not filtered_results:
             if results and not filtered_results:
-                self.logger.warning(f"向量查询找到了 {len(results)} 条错误SQL示例,但全部被阈值过滤掉,问题: {question}")
+                self.logger.warning(f"向量查询找到了 {len(results)} 条错误SQL示例,但全部被阈值过滤掉.")
+                self.logger.warning(f"问题: {question}")
 
 
             return filtered_results
             return filtered_results
             
             

+ 3 - 5
test/custom_react_agent/agent.py

@@ -1044,18 +1044,16 @@ class CustomReactAgent:
 === DECISION RULES ===
 === DECISION RULES ===
 1. If the question involves data within the above business scope (service areas, branches, revenue, traffic flow, etc.), use the generate_sql tool
 1. If the question involves data within the above business scope (service areas, branches, revenue, traffic flow, etc.), use the generate_sql tool
 2. If the question is about general knowledge (like "when do lychees ripen?", weather, historical events, etc.), answer directly based on your knowledge WITHOUT using database tools
 2. If the question is about general knowledge (like "when do lychees ripen?", weather, historical events, etc.), answer directly based on your knowledge WITHOUT using database tools
-3. When answering general knowledge questions, clearly indicate that this is based on general knowledge, not database data
+3. When answering general knowledge questions, provide clear and helpful answers without any special prefixes
 
 
 === FALLBACK STRATEGY ===
 === FALLBACK STRATEGY ===
 When generate_sql returns an error message or when queries return no results:
 When generate_sql returns an error message or when queries return no results:
 1. First, check if the question is within the database scope described above
 1. First, check if the question is within the database scope described above
 2. For questions clearly OUTSIDE the database scope (world events, general knowledge, etc.):
 2. For questions clearly OUTSIDE the database scope (world events, general knowledge, etc.):
    - Provide the answer based on your knowledge immediately
    - Provide the answer based on your knowledge immediately
-   - CLEARLY indicate this is based on general knowledge, not database data
-   - Use format: "Based on general knowledge (not database data): [answer]"
+   - Give a direct, natural answer without any prefixes or disclaimers
 3. For questions within database scope but queries return no results:
 3. For questions within database scope but queries return no results:
-   - If it's a reasonable question that might have a general answer, provide it
-   - Still indicate the source: "Based on general knowledge (database had no results): [answer]"
+   - If it's a reasonable question that might have a general answer, provide it naturally
 4. For questions that definitely require specific database data:
 4. For questions that definitely require specific database data:
    - Acknowledge the limitation and suggest the data may not be available
    - Acknowledge the limitation and suggest the data may not be available
    - Do not attempt to guess or fabricate specific data
    - Do not attempt to guess or fabricate specific data

+ 4 - 1
test/custom_react_agent/config.py

@@ -10,9 +10,12 @@ PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(_
 
 
 # --- LLM 配置 ---
 # --- LLM 配置 ---
 # 在这里写死你的千问API Key
 # 在这里写死你的千问API Key
+# qwen-plus
+# qwen3-235b-a22b
+# qwen3-30b-a3b
 QWEN_API_KEY = "sk-db68e37f00974031935395315bfe07f0"
 QWEN_API_KEY = "sk-db68e37f00974031935395315bfe07f0"
 QWEN_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
 QWEN_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
-QWEN_MODEL = "qwen3-235b-a22b"
+QWEN_MODEL = "qwen3-30b-a3b"
 
 
 # --- Redis 配置 ---
 # --- Redis 配置 ---
 REDIS_URL = "redis://localhost:6379"
 REDIS_URL = "redis://localhost:6379"