18aa0281bc
6.16 更新 修复None bug
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
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()
|
|
|
|
# 加载数据
|
|
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_mapping(keywords, data)
|
|
|
|
print(f"📊 图谱相关知识输出:\n{input_neo4j}\n")
|
|
|
|
except Exception as e:
|
|
print(f"❌ 发生错误:{e}")
|
|
|
|
|
|
# input_str1 = "杆塔总基数是多少?"
|
|
# input_str2 = "单回路长度是多少?"
|
|
# input_str3 = "计算一下角钢塔的塔材装材费"
|
|
# input_str4 = "计算一下土石方总量"
|
|
# input_str5 = "板式塔基的各类基础数量占总塔基数比例是多少?"
|
|
# input_str6 = "基础混凝土总量是多少"
|
|
# input_str7 = "计算一下本体工程机械费"
|
|
# ipout_str8 = "项目建设技术服务费合计"
|
|
|
|
|
|
|