10 changed files with 121 additions and 52 deletions
@ -0,0 +1,36 @@ |
|||||
|
# 全局 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 |
||||
@ -0,0 +1,45 @@ |
|||||
|
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 |
||||
@ -0,0 +1,13 @@ |
|||||
|
# controller/__init__.py |
||||
|
|
||||
|
# 导入所有控制器模块(触发其初始化) |
||||
|
from .BuilderController import * |
||||
|
from .GraphController import * |
||||
|
from .LoginController import * |
||||
|
from .QAController import * |
||||
|
|
||||
|
# 可选:如果控制器里定义了 blueprint,也可以在这里统一导出 |
||||
|
# from .BuilderController import builder_bp |
||||
|
# from .GraphController import graph_bp |
||||
|
|
||||
|
# from .LoginController import login_bp |
||||
@ -0,0 +1,15 @@ |
|||||
|
|
||||
|
// src/api/graph.js
|
||||
|
import request from '@/utils/request'; |
||||
|
|
||||
|
/** |
||||
|
* 获取测试图谱数据(固定返回 Disease 及其所有关系) |
||||
|
* 后端接口:GET /test (无参数) |
||||
|
*/ |
||||
|
export function qaAnalyze(data) { |
||||
|
return request({ |
||||
|
url: '/api/qa/analyze', |
||||
|
method: 'post', |
||||
|
data |
||||
|
}); |
||||
|
} |
||||
Loading…
Reference in new issue