|
@@ -13,6 +13,7 @@ from applications.utils.oss.oss_client import OSSClient
|
|
|
from applications.utils.pdf.book_extract import book_extract
|
|
|
from applications.utils.spider.study import study
|
|
|
|
|
|
+
|
|
|
async def handle_books():
|
|
|
try:
|
|
|
# 获取资源管理器和客户端
|
|
@@ -26,7 +27,9 @@ async def handle_books():
|
|
|
for book in books:
|
|
|
book_id = book.get("book_id")
|
|
|
# 获取提取状态
|
|
|
- extract_status = (await books_mapper.select_book_extract_status(book_id))[0].get("extract_status")
|
|
|
+ extract_status = (await books_mapper.select_book_extract_status(book_id))[
|
|
|
+ 0
|
|
|
+ ].get("extract_status")
|
|
|
|
|
|
if extract_status == 0:
|
|
|
# 更新提取状态为处理中
|
|
@@ -45,10 +48,16 @@ async def handle_books():
|
|
|
# 提取书籍内容
|
|
|
res = await book_extract(book_path, book_id)
|
|
|
if res:
|
|
|
- content_list = res.get("results", {}).get(book_id, {}).get("content_list", [])
|
|
|
+ content_list = (
|
|
|
+ res.get("results", {})
|
|
|
+ .get(book_id, {})
|
|
|
+ .get("content_list", [])
|
|
|
+ )
|
|
|
if content_list:
|
|
|
# 更新提取结果
|
|
|
- await books_mapper.update_book_extract_result(book_id, content_list)
|
|
|
+ await books_mapper.update_book_extract_result(
|
|
|
+ book_id, content_list
|
|
|
+ )
|
|
|
|
|
|
# 创建文档 ID
|
|
|
doc_id = f"doc-{uuid.uuid4()}"
|
|
@@ -91,12 +100,8 @@ async def process_question(question, query_text, rag_chat_agent):
|
|
|
study_task_id = study(question)["task_id"]
|
|
|
|
|
|
qwen_client = QwenClient()
|
|
|
- llm_search = qwen_client.search_and_chat(
|
|
|
- user_prompt=question
|
|
|
- )
|
|
|
- decision = await rag_chat_agent.make_decision(
|
|
|
- question, chat_result, llm_search
|
|
|
- )
|
|
|
+ llm_search = qwen_client.search_and_chat(user_prompt=question)
|
|
|
+ decision = await rag_chat_agent.make_decision(question, chat_result, llm_search)
|
|
|
|
|
|
# 构建返回的数据
|
|
|
data = {
|
|
@@ -128,16 +133,16 @@ async def process_question(question, query_text, rag_chat_agent):
|
|
|
|
|
|
|
|
|
async def query_search(
|
|
|
- query_text,
|
|
|
- filters=None,
|
|
|
- search_type="",
|
|
|
- anns_field="vector_text",
|
|
|
- search_params=BASE_MILVUS_SEARCH_PARAMS,
|
|
|
- _source=False,
|
|
|
- es_size=10000,
|
|
|
- sort_by=None,
|
|
|
- milvus_size=20,
|
|
|
- limit=10,
|
|
|
+ query_text,
|
|
|
+ filters=None,
|
|
|
+ search_type="",
|
|
|
+ anns_field="vector_text",
|
|
|
+ search_params=BASE_MILVUS_SEARCH_PARAMS,
|
|
|
+ _source=False,
|
|
|
+ es_size=10000,
|
|
|
+ sort_by=None,
|
|
|
+ milvus_size=20,
|
|
|
+ limit=10,
|
|
|
):
|
|
|
if filters is None:
|
|
|
filters = {}
|
|
@@ -194,4 +199,4 @@ async def query_search(
|
|
|
"datasetId": content_chunk["dataset_id"],
|
|
|
}
|
|
|
)
|
|
|
- return res[:limit]
|
|
|
+ return res[:limit]
|