diff --git a/controller/GraphController.py b/controller/GraphController.py index f70c951..7c8032f 100644 --- a/controller/GraphController.py +++ b/controller/GraphController.py @@ -209,31 +209,75 @@ def health(): return {"status": "ok", "drug_cached": redis_get(DRUG_TREE_KEY) is not None} +# @app.post("/api/analyze") +# async def analyze(request): +# # 假设前端传入 JSON: {"text": "病例文本..."} +# body = request.json() +# input_text = body.get("text", "").strip() +# +# if not input_text: +# return jsonify({"error": "缺少 text 字段"}), 400 +# client = httpx.AsyncClient(base_url="http://192.168.50.113:8088") +# # 调用实体关系抽取服务 +# response = await client.post( +# "/extract_entities_and_relations", +# json={"text": input_text} +# ) +# print(response) +# if response.status_code == 200: +# result = response.json() +# return jsonify(result) +# else: +# return jsonify({ +# "error": "实体抽取服务返回错误", +# "status": response.status_code, +# "detail": response.text +# }), response.status_code + + +# 全局 client(可复用) +client = httpx.AsyncClient(base_url="http://192.168.50.113:8088") + @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: - # 假设前端传入 JSON: {"text": "病例文本..."} - body = request.json() - input_text = body.get("text", "").strip() - - if not input_text: - return jsonify({"error": "缺少 text 字段"}), 400 - client = httpx.AsyncClient(base_url="http://192.168.50.113:8088") - # 调用实体关系抽取服务 - response = await client.post( + # 直接转发到大模型服务(假设它返回 { "task_id": "xxx" }) + resp = await client.post( "/extract_entities_and_relations", - json={"text": input_text} + json={"text": input_text}, + timeout=1800.0 # 30分钟 ) - print(response) - if response.status_code == 200: - result = response.json() - return jsonify(result) + 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": "实体抽取服务返回错误", - "status": response.status_code, - "detail": response.text - }), response.status_code + "error": "提交失败", + "detail": resp.text + }), resp.status_code + except Exception as e: + return jsonify({"error": str(e)}), 500 + +@app.get("/api/analyze/status") +async def get_status(): + try: + # 直接转发状态查询到大模型服务 + resp = await client.get( + "/status", + timeout=5.0 + ) + return jsonify(resp.json()), resp.status_code + except httpx.ReadTimeout: + return jsonify({"error": "状态查询超时"}), 500 except Exception as e: return jsonify({"error": str(e)}), 500 \ No newline at end of file diff --git a/util/neo4j_utils.py b/util/neo4j_utils.py index 00ede2c..79b5206 100644 --- a/util/neo4j_utils.py +++ b/util/neo4j_utils.py @@ -320,10 +320,8 @@ class Neo4jUtil: raise RuntimeError( f"查询邻居节点时发生数据库错误: {str(e)}" ) from e # 使用 'from e' 保留原始异常链 - print(raw_results) + neighbors = [] - print("Ssssssssss") - print(len(raw_results)) for row in raw_results: source = dict(row["sourceProps"]) source.update({"id": row["sourceId"], "label": row["sourceLabel"]}) @@ -339,8 +337,7 @@ class Neo4jUtil: "target": target, "relationship": relationship }) - print(relationship) - print(neighbors) + return neighbors # def find_neighbors_with_relationships( # self, diff --git a/vue/src/App.vue b/vue/src/App.vue index aea1aa5..651fe04 100644 --- a/vue/src/App.vue +++ b/vue/src/App.vue @@ -10,10 +10,10 @@ export default { \ No newline at end of file diff --git a/vue/src/api/builder.js b/vue/src/api/builder.js index 627d2d6..2c9f715 100644 --- a/vue/src/api/builder.js +++ b/vue/src/api/builder.js @@ -13,3 +13,9 @@ export function analyze(data) { data }); } +export function getAIStatus() { + return request({ + url: '/api/analyze/status', + method: 'get', + }); +} \ No newline at end of file diff --git a/vue/src/assets/logo1.png b/vue/src/assets/logo1.png new file mode 100644 index 0000000..581cd7a Binary files /dev/null and b/vue/src/assets/logo1.png differ diff --git a/vue/src/components/Menu.vue b/vue/src/components/Menu.vue index 4f5799d..fc27f62 100644 --- a/vue/src/components/Menu.vue +++ b/vue/src/components/Menu.vue @@ -1,10 +1,13 @@