zbparse/flask_app/main/基础信息整合.py

136 lines
6.7 KiB
Python
Raw Normal View History

2024-08-29 16:37:09 +08:00
from json_utils import clean_json_string, nest_json_under_key,rename_outer_key, combine_json_results
2024-08-29 17:30:49 +08:00
from flask_app.main.投标人须知正文提取指定内容 import extract_from_notice
from flask_app.main.判断是否分包等 import judge_whether_main, read_questions_from_judge
from flask_app.main.多线程提问 import read_questions_from_file, multi_threading
from flask_app.main.通义千问long import upload_file
2024-08-29 16:37:09 +08:00
def combine_basic_info(baseinfo_list):
combined_baseinfo_list = []
key_groups = {
"招标人/代理信息": ["招标人","招标人联系方式", "招标代理机构","招标代理机构联系方式"],
"项目信息": ["工程名称", "招标编号","工程概况","招标范围","招标控制价","投标竞争下浮率","是否接受联合体投标"],
"关键时间/内容":["投标文件递交截止日期","递交方式","投标人要求澄清招标文件的截止时间","投标有效期","评标结果公示媒介"],
"保证金相关":['质量保证金','退还投标保证金'],
"其他信息":["重新招标、不再招标和终止招标","是否退还投标文件","费用承担"]
}
# 将所有基础信息合并到一个字典中
combined_data = {}
relevant_keys_detected = set()
# 预处理以决定哪些键名将被使用
for baseinfo in baseinfo_list:
json_data = clean_json_string(baseinfo)
combined_data.update(json_data)
relevant_keys_detected.update(json_data.keys())
# for key in relevant_keys.keys():
# if key in json_data:
# relevant_keys[key] = True
# 根据检测到的键动态调整 key_groups
dynamic_key_handling(key_groups, relevant_keys_detected)
# 打印 key_groups 的内容检查它们是否被正确更新
print("Updated key_groups after dynamic handling:")
print(key_groups)
# 使用合并后的字典创建最终输出
for group_name, keys in key_groups.items():
group_data = {key: combined_data.get(key, "未提供") for key in keys}
combined_json = nest_json_under_key(group_data, group_name)
combined_baseinfo_list.append(combined_json)
return combined_baseinfo_list
def dynamic_key_handling(key_groups, detected_keys):
# 检查和调整键组配置
for key in detected_keys:
if "投标保证金" in key or "履约保证金" in key:
key_groups["保证金相关"].append(key)
elif "联合体投标要求" in key:
key_groups["项目信息"].append(key)
elif "分包" in key:
key_groups["项目信息"].append(key)
elif "踏勘现场" in key:
key_groups["其他信息"].append(key)
elif "投标预备会" in key:
key_groups["其他信息"].append(key)
elif "偏离" in key:
key_groups["其他信息"].append(key)
def judge_consortium_bidding(baseinfo_list):
for baseinfo in baseinfo_list:
json_data = clean_json_string(baseinfo)
# 检查 "是否接受联合体投标" 键是否存在且其值为 "是"
if json_data.get("是否接受联合体投标") == "":
return True
return False
def project_basic_info(knowledge_name,truncate0,output_folder,clause_path): #投标人须知前附表
# 调用大模型回答项目基础信息
print("starting基础信息...")
baseinfo_list = []
# baseinfo_file_path='../static/提示词/前两章提问总结.txt'
2024-08-29 17:30:49 +08:00
baseinfo_file_path = 'flask_app/static/提示词/前两章提问总结.txt' # 替换为你的txt文件路径
2024-08-29 16:37:09 +08:00
questions = read_questions_from_file(baseinfo_file_path)
res1 = multi_threading(questions, knowledge_name)
for _, response in res1: # _占位代表ques;response[0]也是ques;response[1]是ans
try:
if response and len(response) > 1: # 检查response存在且有至少两个元素
baseinfo_list.append(response[1])
else:
print(f"Warning: Missing or incomplete response data for query index {_}.")
except Exception as e:
print(f"Error processing response for query index {_}: {e}")
print("basic信息done...")
# 判断是否分包、是否需要递交投标保证金等
chosen_numbers, merged = judge_whether_main(truncate0,output_folder)
baseinfo_list.append(merged)
# judge_file_path = '../static/提示词/是否相关问题.txt'
2024-08-29 17:30:49 +08:00
judge_file_path ='flask_app/static/提示词/是否相关问题.txt'
2024-08-29 16:37:09 +08:00
judge_questions = read_questions_from_judge(judge_file_path, chosen_numbers)
judge_consortium = judge_consortium_bidding(baseinfo_list) #通过招标公告判断是否接受联合体投标
if judge_consortium:
judge_consortium_question = "该招标文件对于联合体投标的要求是怎样的请按json格式给我提供信息外层键名为'联合体投标要求'"
judge_questions.append(judge_consortium_question)
file_id=upload_file(truncate0)
res2 = multi_threading(judge_questions, "",file_id,2) #调用千问-long
if not res2:
print("errror!")
else:
# 打印结果
for question, response in res2:
baseinfo_list.append(response)
# for _, response in res2: # _占位代表ques;response[0]也是ques;response[1]是ans #调用百炼rag
# try:
# if response and len(response) > 1: # 检查response存在且有至少两个元素
# baseinfo_list.append(response[1])
# else:
# print(f"Warning: Missing or incomplete response data for query index {_}.")
# except Exception as e:
# print(f"Error processing response for query index {_}: {e}")
rebidding_situation = extract_from_notice(clause_path, 3) #"重新招标, 不再招标和终止招标"需从投标人须知正文提取
update_json=rename_outer_key(rebidding_situation,"重新招标、不再招标和终止招标")
baseinfo_list.append(update_json)
update_baseinfo_list=combine_basic_info(baseinfo_list) #整合基础信息核心代码
baseinfo_combined_res = combine_json_results(update_baseinfo_list) # 返回值是字典
print("基础信息done")
return nest_json_under_key(baseinfo_combined_res, "基础信息") #返回值是json字符串
if __name__ == "__main__":
knowledge_name = "ztb"
output_folder="C:\\Users\\Administrator\\Desktop\\招标文件\\test2"
truncate0="C:\\Users\\Administrator\\Desktop\\招标文件\\test2\\zbtest10_tobidders_notice_table.pdf"
clause_path="C:\\Users\\Administrator\\Desktop\\招标文件\\output1\\clause1.json"
res=project_basic_info(knowledge_name,truncate0,output_folder,clause_path)
print(res)