You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

45 lines
1.4 KiB

import json
import traceback
import httpx
from robyn import jsonify, Response
from app import app
from controller.client import client
@app.post("/api/qa/analyze")
async def analyze(request):
body = request.json()
input_text = body.get("text", "").strip()
if not input_text:
return jsonify({"error": "缺少 text 字段"}), 400
try:
# 直接转发到大模型服务(假设它返回 { "task_id": "xxx" })
resp = await client.post(
"/getEntity",
json={"text": input_text},
timeout=1800.0 # 30分钟
)
if resp.status_code == 202 or resp.status_code == 200:
resp_json = resp.json()
resp_json_data = resp_json.get("data",{})
resp_json_data = json.loads(resp_json_data)
entities = resp_json_data.get("entities", [])
return Response(
status_code=200,
description=jsonify(entities),
headers={"Content-Type": "text/plain; charset=utf-8"}
)
else:
return jsonify({
"error": "提交失败",
"detail": resp.text
}), resp.status_code
except Exception as e:
error_trace = traceback.format_exc()
print("❌ 发生异常:")
print(error_trace)
return jsonify({"error": str(e),"traceback": error_trace}), 500