Преглед изворни кода

Merge branch 'master' of http://git.yangzhiqiang.tech/jiaqiang/tx_flow_analysis

* 'master' of http://git.yangzhiqiang.tech/jiaqiang/tx_flow_analysis:
  修改一个bug
  提示词优化,报告大纲生成
chaixuhong пре 4 дана
родитељ
комит
5d3c45a1a3
2 измењених фајлова са 53 додато и 34 уклоњено
  1. 36 23
      llmops/agents/outline_agent.py
  2. 17 11
      llmops/batch_runner_all.py

+ 36 - 23
llmops/agents/outline_agent.py

@@ -544,34 +544,35 @@ class OutlineGeneratorAgent:
 
         try:
             missing_prompt = ChatPromptTemplate.from_messages([
-                ("system", """
-                    你是一个专业的指标推荐专家,需要根据用户查询的关键词,识别出可能缺失的关键指标。
-                    
-                    强制要求:只能选择和{industry}相关的指标
+                ("system", f"""
+                    你是一个专业的{industry}行业指标推荐专家,需要根据用户查询的关键词,识别出可能缺失的关键指标。
+
+                    分析步骤:
+                    1. 从查询关键词中识别出用户关心的核心指标需求
+                    2. 检查已选择的指标,看看哪些关键词对应的指标还未被选择
+                    3. 从可用指标库中找到匹配的指标名称
+
+                    重要提示:
+                    - 关键词如"总收入"、"总支出"等直接对应具体的指标
+                    - 如果关键词在已选指标中不存在,就应该推荐对应的指标
+                    - 必须从可用指标库中选择完全匹配的指标名称
 
-                    请分析:
-                    1. 用户关心的分析维度(收入、支出、排名、趋势等)
-                    2. 已选择的指标
-                    3. 可用的指标库
-                    
-                    推荐一些重要的缺失指标,帮助完善分析报告。
-                    
                     返回格式:
                     只返回指标名称列表,用换行符分隔,不要其他解释。
-                    
+
                     示例:
-                    总收入分析
-                    支出占比统计
-                    交易对手排名"""),
-                                    ("human", """查询关键词:{keywords}
-                    
-                    已选择的指标:
+                    总收入
+                    总支出
+                    收入笔数"""),
+                                    ("human", """用户查询关键词:{keywords}
+
+                    当前已选择的指标:
                     {selected_metrics}
-                    
-                    可用指标库:
+
+                    系统可用指标库:
                     {available_metrics}
-                    
-                    请推荐一些重要的缺失指标。""")
+
+                    请从关键词中识别出还未被选择的指标,并从可用指标库中找到对应的指标名称。""")
                                 ])
 
             # 格式化输入
@@ -588,12 +589,24 @@ class OutlineGeneratorAgent:
 
             # 解析结果
             recommended_metrics = []
-            for line in result.content.strip().split('\n'):
+            content = result.content.strip()
+
+            # 处理可能的markdown代码块
+            if content.startswith('```') and content.endswith('```'):
+                content = content[3:-3].strip()
+                if content.startswith('json\n'):
+                    content = content[5:]
+
+            for line in content.split('\n'):
                 metric_name = line.strip()
+                # 移除可能的列表符号
+                metric_name = metric_name.lstrip('0123456789.-* ').strip()
+
                 if metric_name and metric_name not in selected_metric_names:
                     # 验证指标是否存在于可用指标库中
                     if any(m.get('name') == metric_name for m in available_metrics):
                         recommended_metrics.append(metric_name)
+                        print(f"✓ 识别到缺失指标: {metric_name}")
 
             print(f"📊 推荐缺失指标: {recommended_metrics}")
             return recommended_metrics

+ 17 - 11
llmops/batch_runner_all.py

@@ -167,17 +167,7 @@ async def run_batch(runs: int, question: str, industry: str, data_file: str):
         print("❌ 未找到API密钥,请检查config.py")
         return
 
-    try:
-        # 执行数据标准化
-        standard_file_path = await data_standardize()
-        print(f"标准化后文件:{standard_file_path}")
-        data_file = standard_file_path
-        # 标准化数据加载
-        data = DataManager.load_data_from_csv_file(data_file)
-        print(f"📊 数据加载成功: {len(data)} 条记录")
-    except Exception as e:
-        print(f"❌ 数据加载失败: {e}")
-        return
+
 
     # 运行结果统计
     successful_runs = 0
@@ -190,7 +180,23 @@ async def run_batch(runs: int, question: str, industry: str, data_file: str):
     # 逐个运行
     for i in range(1, runs + 1):
         run_id = str(i)
+
+        # 设置环境变量,让所有agent使用正确的文件夹
+        os.environ['FLOW_RUN_ID'] = run_id
+
         start_time = time.perf_counter()
+        try:
+            # 执行数据标准化
+            standard_file_path = await data_standardize()
+            print(f"标准化后文件:{standard_file_path}")
+            data_file = standard_file_path
+            # 标准化数据加载
+            data = DataManager.load_data_from_csv_file(data_file)
+            print(f"📊 数据加载成功: {len(data)} 条记录")
+        except Exception as e:
+            print(f"❌ 数据加载失败: {e}")
+            return
+
         # 单次执行
         result = await run_single_flow(run_id, question, industry, data, os.path.basename(data_file))
         end_time = time.perf_counter()