|
|
@@ -8,6 +8,14 @@ import io
|
|
|
import urllib.parse
|
|
|
from llmops.complete_agent_flow_rule import run_complete_agent_flow
|
|
|
from llmops.config import DEEPSEEK_API_KEY
|
|
|
+from llmops.agents.data_stardard import TransactionParserAgent
|
|
|
+from llmops.config import multimodal_api_url
|
|
|
+
|
|
|
+
|
|
|
+os.environ["LANGCHAIN_TRACING_V2"] = "false"
|
|
|
+os.environ["LANGCHAIN_API_KEY"] = ""
|
|
|
+# 禁用 LangGraph 的追踪
|
|
|
+os.environ["LANGSMITH_TRACING"] = "false"
|
|
|
|
|
|
# 初始化FastAPI应用
|
|
|
app = FastAPI(
|
|
|
@@ -93,12 +101,22 @@ async def dataset_classify(file: UploadFile = File(...), industry: str = Form(..
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 数据标准化agent
|
|
|
+standard_agent = TransactionParserAgent(
|
|
|
+ api_key=DEEPSEEK_API_KEY,
|
|
|
+ multimodal_api_url=multimodal_api_url
|
|
|
+)
|
|
|
+
|
|
|
@app.post("/api/report/gen")
|
|
|
async def gen_report(file: UploadFile = File(...), question: str = Form(...), industry: str = Form(...)):
|
|
|
"""
|
|
|
- 上传原始数据文件(格式CSV),输入问题和行业,生成对应的分析报告
|
|
|
+ 上传原始数据文件(格式支持pdf/img/csv),输入问题和行业,生成对应的分析报告
|
|
|
Args:
|
|
|
- file: 用户上传的CSV数据文件
|
|
|
+ file: 用户上传的数据文件
|
|
|
question: 用户问题
|
|
|
industry: 行业
|
|
|
Returns:
|
|
|
@@ -115,24 +133,40 @@ async def gen_report(file: UploadFile = File(...), question: str = Form(...), in
|
|
|
with open(full_path, "wb") as f:
|
|
|
f.write(file.file.read())
|
|
|
|
|
|
- # 读取文件内容,标准化文件
|
|
|
- data_set = DataManager.load_data_from_csv_file(full_path)
|
|
|
- # 执行测试
|
|
|
- result = await run_complete_agent_flow(
|
|
|
- question=question,
|
|
|
- industry=industry,
|
|
|
- data=data_set,
|
|
|
- file_name=file.filename,
|
|
|
- api_key=DEEPSEEK_API_KEY,
|
|
|
- session_id="direct-test"
|
|
|
- )
|
|
|
- print(result)
|
|
|
- return {
|
|
|
- "status": 0,
|
|
|
- "message": "success",
|
|
|
- "outline_draft": result["result"]["outline_draft"],
|
|
|
- "computed_metrics": result["result"]["computed_metrics"]
|
|
|
- }
|
|
|
+ # 数据标准化
|
|
|
+ result = await standard_agent.run_workflow_task(full_path)
|
|
|
+ if result["status"] == "success":
|
|
|
+ print(f"🎯 Workflow 任务完成!")
|
|
|
+ # 标准化后的文件
|
|
|
+ standard_file_path = result['file_path']
|
|
|
+ standard_file_name = os.path.basename(standard_file_path)
|
|
|
+ print(f"📂 文件全路径: {standard_file_path}, 文件名:{standard_file_name}")
|
|
|
+
|
|
|
+ # 读取文件内容,标准化文件
|
|
|
+ data_set = DataManager.load_data_from_csv_file(standard_file_path)
|
|
|
+ # 执行测试
|
|
|
+ result = await run_complete_agent_flow(
|
|
|
+ question=question,
|
|
|
+ industry=industry,
|
|
|
+ data=data_set,
|
|
|
+ file_name=standard_file_name,
|
|
|
+ api_key=DEEPSEEK_API_KEY,
|
|
|
+ session_id="direct-test"
|
|
|
+ )
|
|
|
+ print(result)
|
|
|
+ return {
|
|
|
+ "status": 0,
|
|
|
+ "message": "success",
|
|
|
+ "outline_draft": result["result"]["outline_draft"],
|
|
|
+ "computed_metrics": result["result"]["computed_metrics"]
|
|
|
+ }
|
|
|
+ else:
|
|
|
+ print(f"❌ 任务失败: {result['message']}")
|
|
|
+ return {
|
|
|
+ "status": 1,
|
|
|
+ "message": result['message'],
|
|
|
+ "report": {}
|
|
|
+ }
|
|
|
except Exception as e:
|
|
|
print(f"生成流水分析报告异常: {e}")
|
|
|
import traceback
|
|
|
@@ -144,9 +178,6 @@ async def gen_report(file: UploadFile = File(...), question: str = Form(...), in
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
if __name__ == "__main__":
|
|
|
import uvicorn
|
|
|
uvicorn.run("main:app", host="0.0.0.0", port=3699, reload=True)
|