上传文件至 kg_lab_6.13
6.13lab 更新main:更新为循环对话
This commit is contained in:
+43
-21
@@ -1,8 +1,50 @@
|
||||
from chains_lab import Problem_rewrite
|
||||
from vector_lab import intersection_of_three_lists
|
||||
from utils import find_target_item, find_target_items, pre_mapping, pre_mapping2
|
||||
import json
|
||||
|
||||
# 初始化
|
||||
problem_rewrite = Problem_rewrite()
|
||||
|
||||
from vector_lab import intersection_of_three_lists
|
||||
# 加载数据
|
||||
with open('./data/data.json', 'r', encoding='utf-8') as file:
|
||||
data = json.load(file)
|
||||
|
||||
print("📥 请输入查询内容,输入 'exit' 可退出程序。\n")
|
||||
|
||||
while True:
|
||||
input_str = input("🔍 输入问题:")
|
||||
|
||||
if input_str.lower() == 'exit':
|
||||
print("👋 已退出。")
|
||||
break
|
||||
|
||||
try:
|
||||
results = intersection_of_three_lists(input_str)
|
||||
if not results:
|
||||
print("⚠️ 无法从向量中获取候选项。")
|
||||
continue
|
||||
|
||||
retriever = results[0]
|
||||
|
||||
print(f"➡️ 匹配向量检索结果:{retriever}")
|
||||
|
||||
# 重写问题,提取关键词
|
||||
keywords = problem_rewrite.invoke({
|
||||
"query": input_str,
|
||||
"retriever": retriever
|
||||
})
|
||||
|
||||
print(f"🧠 提取关键词:{keywords}")
|
||||
|
||||
# 预映射为图数据库结构
|
||||
input_neo4j = pre_mapping2(keywords, data)
|
||||
|
||||
print(f"📊 图谱相关知识输出:\n{input_neo4j}\n")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 发生错误:{e}")
|
||||
|
||||
|
||||
# input_str1 = "杆塔总基数是多少?"
|
||||
# input_str2 = "单回路长度是多少?"
|
||||
@@ -13,25 +55,5 @@ from vector_lab import intersection_of_three_lists
|
||||
# input_str7 = "计算一下本体工程机械费"
|
||||
# ipout_str8 = "项目建设技术服务费合计"
|
||||
|
||||
input_str = "项目建设技术服务费合计是多少?"
|
||||
results = intersection_of_three_lists(input_str)
|
||||
|
||||
retriever = intersection_of_three_lists(input_str)[0]
|
||||
|
||||
print(f"输入:{input_str}")
|
||||
|
||||
keywords = problem_rewrite.invoke({"query":input_str, "retriever":retriever})
|
||||
|
||||
print(f"输出:{keywords}")
|
||||
|
||||
|
||||
import json
|
||||
|
||||
with open('./data/data.json', 'r', encoding='utf-8') as file:
|
||||
data = json.load(file)
|
||||
|
||||
from utils import find_target_item, find_target_items, pre_mapping, pre_mapping2
|
||||
|
||||
input_neo4j = pre_mapping2(keywords, data)
|
||||
|
||||
print(f"检索目标:{input_neo4j}")
|
||||
Reference in New Issue
Block a user