From b4acf278db581ce5e70b513407b70db2d9b29b23 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期二, 07 一月 2025 17:33:32 +0800
Subject: [PATCH] 报告生成
---
app/api/files.py | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/app/api/files.py b/app/api/files.py
index dca7d3c..92ee599 100644
--- a/app/api/files.py
+++ b/app/api/files.py
@@ -10,6 +10,7 @@
from app.api import Response, get_current_user, ResponseList
from app.config.config import settings
+from app.config.const import DOCUMENT_TO_REPORT_TITLE, IMAGE_TO_TEXT
from app.models.agent_model import AgentType, AgentModel
from app.models.base_model import get_db
from app.models.user_model import UserModel
@@ -17,6 +18,7 @@
from app.service.bisheng import BishengService
from app.service.common.api_token import DfTokenDao
from app.service.difyService import DifyService
+from app.service.files import read_file
from app.service.ragflow import RagflowService
from app.service.service_token import get_ragflow_token, get_bisheng_token
import urllib.parse
@@ -99,7 +101,7 @@
elif agent.agent_type == AgentType.DIFY:
dify_service = DifyService(base_url=settings.dify_base_url)
if agent.type == "imageTalk":
- token = DfTokenDao(db).get_token_by_id("image_and_text_conversion")
+ token = DfTokenDao(db).get_token_by_id(IMAGE_TO_TEXT)
if not token:
raise HTTPException(status_code=500, detail="鑾峰彇token澶辫触锛宨mage_and_text_conversion锛�")
file = file[0]
@@ -112,8 +114,8 @@
data = await dify_service.upload(token, file.filename, file_content, current_user.id)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
- elif agent.type == "reportWorkflow":
- token = DfTokenDao(db).get_token_by_id("document_to_report")
+ elif agent.type == "reportWorkflow" or agent.type == "documentIa":
+ token = DfTokenDao(db).get_token_by_id(DOCUMENT_TO_REPORT_TITLE)
if not token:
raise HTTPException(status_code=500, detail="鑾峰彇token澶辫触锛宒ocument_to_report锛�")
result = []
@@ -123,7 +125,11 @@
except Exception as e:
return Response(code=400, msg=str(e))
try:
- file_upload = await dify_service.upload(token, f.filename, file_content, current_user.id)
+ filename = f.filename
+ file_upload = await dify_service.upload(token, filename, file_content, current_user.id)
+ print(file_upload)
+ tokens = await read_file(file_content, filename, f.content_type)
+ file_upload["tokens"] = tokens
result.append(file_upload)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
--
Gitblit v1.8.0