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.
 
 
 
 

36 lines
1.1 KiB

# 全局 client(可复用)
import httpx
from robyn import jsonify, Response
from app import app
from controller import client
@app.post("/api/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(
"/extract_entities_and_relations",
json={"text": input_text},
timeout=1800.0 # 30分钟
)
print(resp)
if resp.status_code == 202 or resp.status_code == 200:
return Response(
status_code=200,
description=jsonify(resp.json()),
headers={"Content-Type": "text/plain; charset=utf-8"}
)
else:
return jsonify({
"error": "提交失败",
"detail": resp.text
}), resp.status_code
except Exception as e:
return jsonify({"error": str(e)}), 500