|
@@ -20,14 +20,15 @@ except ImportError:
|
|
|
|
|
|
def _fetch_parsing_data_by_request(request_id: str) -> List[str]:
|
|
|
"""从 knowledge_extraction_content 表中根据 request_id 获取 data 字段"""
|
|
|
- sql = "SELECT data FROM knowledge_extraction_content WHERE request_id = %s"
|
|
|
+ sql = "SELECT data, content_id FROM knowledge_extraction_content WHERE request_id = %s"
|
|
|
rows = MysqlHelper.get_values(sql, (request_id,)) or []
|
|
|
|
|
|
results = []
|
|
|
for row in rows:
|
|
|
data = row[0] # 获取 data 字段
|
|
|
+ content_id = row[1] # 获取 content_id 字段
|
|
|
if data:
|
|
|
- results.append(data)
|
|
|
+ results.append({"data": data, "content_id": content_id})
|
|
|
|
|
|
print(f"Final results: {len(results)} items")
|
|
|
return results
|
|
@@ -152,37 +153,38 @@ def execute_expand_agent_with_api(requestId: str, query: str = "") -> Dict[str,
|
|
|
success = 0
|
|
|
if not data_samples:
|
|
|
# 即使没有数据,也基于 query 生成一次兜底扩展
|
|
|
- prompt = _build_prompt("", query)
|
|
|
- expanded = _run_llm(prompt)
|
|
|
- if not expanded:
|
|
|
- expanded = _heuristic_expand(query)
|
|
|
- expand_querys_json = json.dumps(expanded, ensure_ascii=False)
|
|
|
- insert_sql = """
|
|
|
- INSERT INTO knowledge_expand_content
|
|
|
- (request_id, create_time, expand_querys, query)
|
|
|
- VALUES (%s, NOW(), %s, %s)
|
|
|
- """
|
|
|
- MysqlHelper.insert_and_get_id(insert_sql, (requestId, expand_querys_json, query))
|
|
|
- total = 1
|
|
|
- success = 1 if expanded else 0
|
|
|
+ # prompt = _build_prompt("", query)
|
|
|
+ # expanded = _run_llm(prompt)
|
|
|
+ # if not expanded:
|
|
|
+ # expanded = _heuristic_expand(query)
|
|
|
+ # expand_querys_json = json.dumps(expanded, ensure_ascii=False)
|
|
|
+ # insert_sql = """
|
|
|
+ # INSERT INTO knowledge_expand_content
|
|
|
+ # (request_id, create_time, expand_querys, query)
|
|
|
+ # VALUES (%s, NOW(), %s, %s)
|
|
|
+ # """
|
|
|
+ # MysqlHelper.insert_and_get_id(insert_sql, (requestId, expand_querys_json, query))
|
|
|
+ # total = 1
|
|
|
+ # success = 1 if expanded else 0
|
|
|
+ logger.info(f"没有数据,不进行扩展,直接返回: requestId={requestId}, total={total}, success={success}")
|
|
|
else:
|
|
|
# 针对每条 parsing_data 分别生成与入库
|
|
|
insert_sql = """
|
|
|
INSERT INTO knowledge_expand_content
|
|
|
- (request_id, create_time, expand_querys, query)
|
|
|
- VALUES (%s, NOW(), %s, %s)
|
|
|
+ (request_id, create_time, expand_querys, query, content_id)
|
|
|
+ VALUES (%s, NOW(), %s, %s, %s)
|
|
|
"""
|
|
|
for sample in data_samples:
|
|
|
total += 1
|
|
|
if not sample:
|
|
|
continue
|
|
|
- prompt = _build_prompt(sample, query)
|
|
|
+ prompt = _build_prompt(sample["data"], query)
|
|
|
expanded = _run_llm(prompt)
|
|
|
if not expanded:
|
|
|
expanded = _heuristic_expand(query)
|
|
|
try:
|
|
|
expand_querys_json = json.dumps(expanded, ensure_ascii=False)
|
|
|
- MysqlHelper.insert_and_get_id(insert_sql, (requestId, expand_querys_json, query))
|
|
|
+ MysqlHelper.insert_and_get_id(insert_sql, (requestId, expand_querys_json, query, sample["content_id"]))
|
|
|
success += 1
|
|
|
except Exception as ie:
|
|
|
logger.error(f"单条扩展结果入库失败: requestId={requestId}, error={ie}")
|