|
|
@@ -48,22 +48,24 @@ from llmops.agents.rules_engine_metric_calculation_agent import RulesEngineMetri
|
|
|
from llmops.agents.data_manager import DataManager
|
|
|
import os
|
|
|
from llmops.agents.data_classify_agent import data_classify
|
|
|
-from llmops.config import DEEPSEEK_API_KEY, multimodal_api_url
|
|
|
-from llmops.agents.data_stardard import data_standize
|
|
|
+from llmops.config import DEEPSEEK_API_KEY, multimodal_api_url, LLM_API_KEY, LLM_BASE_URL, LLM_MODEL_NAME
|
|
|
+from llmops.agents.data_stardard import data_standardize
|
|
|
|
|
|
class CompleteAgentFlow:
|
|
|
"""完整的智能体工作流"""
|
|
|
|
|
|
- def __init__(self, api_key: str, base_url: str = "https://api.deepseek.com"):
|
|
|
+ def __init__(self, api_key: str, base_url: str = "https://api.deepseek.com", model_name: str = "deepseek-chat"):
|
|
|
"""
|
|
|
初始化完整的工作流
|
|
|
|
|
|
Args:
|
|
|
api_key: DeepSeek API密钥
|
|
|
base_url: DeepSeek API基础URL
|
|
|
+ model_name: 模型名称
|
|
|
"""
|
|
|
self.api_key = api_key
|
|
|
self.base_url = base_url
|
|
|
+ self.model_name = model_name
|
|
|
|
|
|
# 初始规则引擎智能体
|
|
|
self.rules_engine_agent = RulesEngineMetricCalculationAgent(api_key, base_url)
|
|
|
@@ -187,7 +189,9 @@ class CompleteAgentFlow:
|
|
|
question=state["question"],
|
|
|
industry=state["industry"],
|
|
|
current_state=state,
|
|
|
- api_key=self.api_key
|
|
|
+ api_key=self.api_key,
|
|
|
+ base_url=self.base_url,
|
|
|
+ model_name=self.model_name
|
|
|
)
|
|
|
|
|
|
# 更新状态
|
|
|
@@ -225,6 +229,8 @@ class CompleteAgentFlow:
|
|
|
industry=state["industry"],
|
|
|
sample_data=state["data_set"][:3], # 使用前3个样本
|
|
|
api_key=self.api_key,
|
|
|
+ base_url=self.base_url,
|
|
|
+ model_name=self.model_name,
|
|
|
max_retries=3, # 最多重试5次
|
|
|
retry_delay=3.0 # 每次重试间隔3秒
|
|
|
)
|
|
|
@@ -287,9 +293,10 @@ class CompleteAgentFlow:
|
|
|
print("📝 正在对数据进行标准化处理...")
|
|
|
|
|
|
# 数据标准化处理
|
|
|
- result = await data_standize(
|
|
|
+ result = await data_standardize(
|
|
|
api_key=self.api_key,
|
|
|
base_url=self.base_url,
|
|
|
+ model_name=self.model_name,
|
|
|
multimodal_api_url=multimodal_api_url,
|
|
|
input_file_path=state["original_file_path"]
|
|
|
)
|
|
|
@@ -675,7 +682,7 @@ async def run_complete_agent_flow(question: str, industry: str, data: List[Dict[
|
|
|
|
|
|
|
|
|
# 便捷函数
|
|
|
-async def run_flow(question: str, industry: str, original_file_path: str, api_key: str, session_id: str = None, use_rules_engine_only: bool = False, use_traditional_engine_only: bool = False) -> Dict[str, Any]:
|
|
|
+async def run_flow(question: str, industry: str, original_file_path: str, api_key: str, base_url: str, model_name: str, session_id: str = None, use_rules_engine_only: bool = False, use_traditional_engine_only: bool = False) -> Dict[str, Any]:
|
|
|
"""
|
|
|
运行完整智能体工作流的便捷函数
|
|
|
|
|
|
@@ -684,6 +691,8 @@ async def run_flow(question: str, industry: str, original_file_path: str, api_ke
|
|
|
data: 数据集
|
|
|
original_file_path: 原始文件路径(pdf/img/csv)
|
|
|
api_key: API密钥
|
|
|
+ base_url: LLM base url
|
|
|
+ model_name: LLM model name
|
|
|
session_id: 会话ID
|
|
|
use_rules_engine_only: 是否只使用规则引擎指标计算
|
|
|
use_traditional_engine_only: 是否只使用传统引擎指标计算
|
|
|
@@ -691,7 +700,7 @@ async def run_flow(question: str, industry: str, original_file_path: str, api_ke
|
|
|
Returns:
|
|
|
工作流结果
|
|
|
"""
|
|
|
- workflow = CompleteAgentFlow(api_key)
|
|
|
+ workflow = CompleteAgentFlow(api_key, base_url, model_name)
|
|
|
return await workflow.run_workflow(question, industry, original_file_path, session_id, use_rules_engine_only, use_traditional_engine_only)
|
|
|
|
|
|
|
|
|
@@ -709,10 +718,6 @@ async def main():
|
|
|
print("🚀 执行CompleteAgentFlow系统测试")
|
|
|
print("=" * 50)
|
|
|
|
|
|
- if not DEEPSEEK_API_KEY:
|
|
|
- print("❌ 未找到API密钥")
|
|
|
- return
|
|
|
-
|
|
|
# 行业
|
|
|
industry = "农业"
|
|
|
|
|
|
@@ -721,12 +726,16 @@ async def main():
|
|
|
curr_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
file_path = os.path.join(curr_dir, "..", "data_files", file_name)
|
|
|
|
|
|
+ print(f"使用LLM:{LLM_MODEL_NAME}")
|
|
|
+
|
|
|
# 执行测试
|
|
|
result = await run_flow(
|
|
|
question="请生成一份详细的农业经营贷流水分析报告,需要包含:1.总收入和总支出统计 2.收入笔数和支出笔数 3.各类型收入支出占比分析 4.交易对手收入支出TOP3排名 5.按月份的收入支出趋势分析 6.账户数量和交易时间范围统计 7.资金流入流出月度统计等全面指标",
|
|
|
industry = industry,
|
|
|
original_file_path=file_path,
|
|
|
- api_key=DEEPSEEK_API_KEY,
|
|
|
+ api_key=LLM_API_KEY,
|
|
|
+ base_url=LLM_BASE_URL,
|
|
|
+ model_name=LLM_MODEL_NAME,
|
|
|
session_id="direct-test"
|
|
|
)
|
|
|
|