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.
63 lines
2.1 KiB
63 lines
2.1 KiB
import json
|
|
import traceback
|
|
from util.neo4j_utils import Neo4jUtil, neo4j_client
|
|
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", [])
|
|
print(entities)
|
|
data = []
|
|
for name in entities:
|
|
neighbors =neo4j_client.find_neighbors_with_relationshipsAI(
|
|
node_label=None,
|
|
direction="both",
|
|
node_properties={"name": name},
|
|
rel_type=None
|
|
)
|
|
data.append({
|
|
name:neighbors
|
|
})
|
|
resp = await client.post(
|
|
"/question_agent",
|
|
json={"neo4j_data": [],
|
|
"text": input_text},
|
|
timeout=1800.0 # 30分钟
|
|
)
|
|
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:
|
|
error_trace = traceback.format_exc()
|
|
print("❌ 发生异常:")
|
|
print(error_trace)
|
|
|
|
return jsonify({"error": str(e),"traceback": error_trace}), 500
|