|
|
@@ -20,7 +20,8 @@ from applications.config import (
|
|
|
from applications.resource import get_resource_manager
|
|
|
from applications.search import HybridSearch
|
|
|
from applications.utils.chat import RAGChatAgent
|
|
|
-from applications.utils.mysql import Dataset, Contents, ContentChunks, ChatResult, Books
|
|
|
+from applications.utils.milvus import async_insert_chunk
|
|
|
+from applications.utils.mysql import Dataset, Contents, ContentChunks, ChatResult, Books, DeconstructionWhat
|
|
|
from applications.api.qwen import QwenClient
|
|
|
from applications.utils.oss.oss_client import OSSClient
|
|
|
from applications.utils.task.async_task import (
|
|
|
@@ -578,3 +579,37 @@ async def process_book():
|
|
|
asyncio.create_task(handle_books())
|
|
|
# 返回立即响应
|
|
|
return jsonify({"status": "success", "message": "任务已提交后台处理"}), 200
|
|
|
+
|
|
|
+
|
|
|
+@server_bp.route("/what/add", methods=["POST"])
|
|
|
+async def test():
|
|
|
+ body = await request.get_json()
|
|
|
+ resource = get_resource_manager()
|
|
|
+ deconstruction_what_mapper = DeconstructionWhat(resource.mysql_client)
|
|
|
+ content_id = f"what-{uuid.uuid4()}"
|
|
|
+ await deconstruction_what_mapper.insert_deconstruction_what_contents(content_id,
|
|
|
+ json.dumps(body, ensure_ascii=False))
|
|
|
+ target = body.get("帖子包含元素")
|
|
|
+ res = []
|
|
|
+ for data in target:
|
|
|
+ what = data.get("what")
|
|
|
+ desc = data.get("描述")
|
|
|
+ res.append({"what": what, "desc": json.dumps(desc, ensure_ascii=False)})
|
|
|
+ children = data.get("子节点元素")
|
|
|
+ for child in children:
|
|
|
+ child_what = child.get("what")
|
|
|
+ child_desc = child.get("描述")
|
|
|
+ res.append({"what": child_what, "desc": json.dumps(child_desc, ensure_ascii=False)})
|
|
|
+ for data in res:
|
|
|
+ doc_id = f"doc-{uuid.uuid4()}"
|
|
|
+ deconstruction_what_mapper = DeconstructionWhat(resource.mysql_client)
|
|
|
+ await deconstruction_what_mapper.insert_deconstruction_what(content_id, doc_id, data.get("what"), data.get("desc"))
|
|
|
+ what_embedding = await get_basic_embedding(text=data.get("what"), model=DEFAULT_MODEL)
|
|
|
+ data = {
|
|
|
+ "doc_id": doc_id,
|
|
|
+ "vector_text": what_embedding
|
|
|
+ }
|
|
|
+ res = await async_insert_chunk(resource.what_milvus_client, data)
|
|
|
+ if res:
|
|
|
+ await deconstruction_what_mapper.update_deconstruction_what_embedding_status(doc_id)
|
|
|
+ return jsonify({"status_code": 200, "detail": "success"})
|