2024-08-29 16:37:09 +08:00
|
|
|
|
# -*- encoding:utf-8 -*-
|
|
|
|
|
import json
|
|
|
|
|
import os.path
|
|
|
|
|
import re
|
2024-08-30 10:34:23 +08:00
|
|
|
|
from flask_app.main.json_utils import extract_content_from_json # 可以选择性地导入特定的函数
|
2024-08-29 17:30:49 +08:00
|
|
|
|
from flask_app.main.提取打勾符号 import read_pdf_and_judge_main
|
2024-10-18 13:37:54 +08:00
|
|
|
|
from flask_app.main.多线程提问 import multi_threading
|
2024-08-29 17:30:49 +08:00
|
|
|
|
from flask_app.main.通义千问long import qianwen_long,upload_file
|
2024-08-29 16:37:09 +08:00
|
|
|
|
#调用qianwen-ask之后,组织提示词问百炼。
|
|
|
|
|
|
|
|
|
|
def construct_judge_questions(json_data):
|
2024-10-18 13:37:54 +08:00
|
|
|
|
"""
|
|
|
|
|
根据提供的 JSON 数据,生成一个问题列表。每个问题针对一个值为 '未知' 的键,
|
|
|
|
|
要求以 JSON 格式提供该键的值,仅限于 '是', '否', '未知'。
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
json_data (str or dict): 输入的 JSON 数据,可以是 JSON 字符串或字典。
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
list: 包含生成的问题的列表。如果没有符合条件的键,则返回空列表。
|
|
|
|
|
"""
|
|
|
|
|
# 如果 json_data 是字符串,尝试将其解析为字典
|
|
|
|
|
if isinstance(json_data, str):
|
|
|
|
|
try:
|
|
|
|
|
parsed_data = json.loads(json_data)
|
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
|
print("输入的 json_data 不是有效的 JSON 字符串。")
|
|
|
|
|
return []
|
|
|
|
|
elif isinstance(json_data, dict):
|
|
|
|
|
parsed_data = json_data
|
|
|
|
|
else:
|
|
|
|
|
print("输入的 json_data 必须是 JSON 字符串或字典。")
|
|
|
|
|
return []
|
|
|
|
|
# 提取值为 '未知' 的键
|
|
|
|
|
question_keys = [key for key, value in parsed_data.items() if value == '未知']
|
|
|
|
|
# 如果没有符合条件的键,返回空列表
|
2024-08-29 16:37:09 +08:00
|
|
|
|
if not question_keys:
|
2024-10-18 13:37:54 +08:00
|
|
|
|
return []
|
|
|
|
|
# 生成问题列表
|
|
|
|
|
questions = []
|
|
|
|
|
for key in question_keys:
|
|
|
|
|
question = (
|
|
|
|
|
f"请你根据投标人须知前附表中的信息回答,本项目{key},"
|
|
|
|
|
f"请按json格式给我提供信息,键名为'{key}',键值仅限于'是','否','未知',如果原文中对应内容处为'/'或者'\',键值填'否'。"
|
|
|
|
|
)
|
|
|
|
|
questions.append(question)
|
|
|
|
|
return questions
|
2024-08-29 16:37:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def merge_json_to_list(merged):
|
|
|
|
|
"""Merge updates into the original data by modifying specific keys based on their value ('是' or '否'), and create a list based on these values."""
|
|
|
|
|
chosen_numbers = []
|
|
|
|
|
|
|
|
|
|
# 处理是否允许分包 保持'是否允许分包'键名主要是由于存在'未知'的情况。
|
|
|
|
|
if merged.get('是否允许分包') == '是':
|
|
|
|
|
chosen_numbers.append(1)
|
|
|
|
|
merged.pop('是否允许分包', None)
|
|
|
|
|
elif merged.get('是否允许分包') == '否':
|
|
|
|
|
merged['分包'] = '不允许'
|
|
|
|
|
merged.pop('是否允许分包', None)
|
|
|
|
|
|
2024-10-15 20:57:58 +08:00
|
|
|
|
guarantee_key = '是否递交投标保证金' if '是否递交投标保证金' in merged else '是否递交磋商保证金'
|
|
|
|
|
if merged.get(guarantee_key) == '是':
|
2024-08-29 16:37:09 +08:00
|
|
|
|
chosen_numbers.extend([2, 3])
|
2024-10-16 20:18:55 +08:00
|
|
|
|
merged.pop(guarantee_key, None)
|
|
|
|
|
elif merged.get(guarantee_key) == '否':
|
2024-10-15 20:57:58 +08:00
|
|
|
|
guarantee_type = '投标' if '投标' in guarantee_key else '磋商'
|
|
|
|
|
merged[f'{guarantee_type}保证金'] = '不提交'
|
|
|
|
|
merged[f'退还{guarantee_type}保证金'] = '/'
|
2024-10-16 20:18:55 +08:00
|
|
|
|
merged.pop(guarantee_key, None)
|
2024-08-29 16:37:09 +08:00
|
|
|
|
|
|
|
|
|
# 处理是否有履约保证金
|
2024-10-15 20:57:58 +08:00
|
|
|
|
if merged.get('是否提交履约保证金') == '是':
|
2024-08-29 16:37:09 +08:00
|
|
|
|
chosen_numbers.append(4)
|
2024-10-15 20:57:58 +08:00
|
|
|
|
merged.pop('是否提交履约保证金', None)
|
|
|
|
|
elif merged.get('是否提交履约保证金') == '否':
|
2024-08-29 16:37:09 +08:00
|
|
|
|
merged['履约保证金'] = '不提交'
|
2024-10-15 20:57:58 +08:00
|
|
|
|
merged.pop('是否提交履约保证金', None)
|
2024-08-29 16:37:09 +08:00
|
|
|
|
|
|
|
|
|
# 处理是否有招标代理服务费
|
|
|
|
|
if merged.get('是否有招标代理服务费') == '是':
|
|
|
|
|
chosen_numbers.append(5)
|
|
|
|
|
merged.pop('是否有招标代理服务费', None)
|
|
|
|
|
elif merged.get('是否有招标代理服务费') == '否':
|
|
|
|
|
merged['招标代理服务费'] = '无'
|
|
|
|
|
merged.pop('是否有招标代理服务费', None)
|
|
|
|
|
|
|
|
|
|
if merged.get('是否组织踏勘现场') == '是':
|
|
|
|
|
chosen_numbers.append(6)
|
|
|
|
|
merged.pop('是否组织踏勘现场',None)
|
|
|
|
|
elif merged.get('是否组织踏勘现场') == '否':
|
|
|
|
|
merged['踏勘现场']='不组织'
|
|
|
|
|
merged.pop('是否组织踏勘现场', None)
|
|
|
|
|
|
2024-10-15 20:57:58 +08:00
|
|
|
|
preparation_key = '是否召开投标预备会' if '是否召开投标预备会' in merged else '是否召开投标答疑会'
|
|
|
|
|
if merged.get(preparation_key) == '是':
|
2024-08-29 16:37:09 +08:00
|
|
|
|
chosen_numbers.append(7)
|
2024-10-16 20:18:55 +08:00
|
|
|
|
merged.pop(preparation_key, None)
|
|
|
|
|
elif merged.get(preparation_key) == '否':
|
2024-10-15 20:57:58 +08:00
|
|
|
|
meeting_type = '预备会' if '预备会' in preparation_key else '答疑会'
|
2024-10-16 20:18:55 +08:00
|
|
|
|
merged[f'投标{meeting_type}']='不召开'
|
|
|
|
|
merged.pop(preparation_key,None)
|
2024-08-29 16:37:09 +08:00
|
|
|
|
|
|
|
|
|
if merged.get('是否允许偏离') == '是':
|
|
|
|
|
chosen_numbers.append(8)
|
|
|
|
|
merged.pop('是否允许偏离',None)
|
|
|
|
|
elif merged.get('是否允许偏离') == '否':
|
|
|
|
|
merged['偏离']='不允许'
|
|
|
|
|
merged.pop('是否允许偏离', None)
|
|
|
|
|
|
2024-10-17 15:33:58 +08:00
|
|
|
|
return chosen_numbers, merged
|
2024-08-29 16:37:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_questions_from_judge(file_path, indices):
|
|
|
|
|
questions = []
|
|
|
|
|
|
|
|
|
|
# 读取文件内容
|
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
|
|
|
content = file.read()
|
|
|
|
|
|
|
|
|
|
# 正则表达式提取问题
|
|
|
|
|
pattern = r'(\d+)\.(.*?)#pdf提取之后的提示词|(\d+)\.(.*?)(?=\d+\.|$)'
|
|
|
|
|
matches = re.findall(pattern, content, re.DOTALL)
|
|
|
|
|
|
|
|
|
|
# 解析匹配到的内容并提取对应序号的问题
|
|
|
|
|
for match in matches:
|
|
|
|
|
num = match[0] or match[2]
|
|
|
|
|
question = match[1].strip() or match[3].strip()
|
|
|
|
|
if int(num) in indices:
|
|
|
|
|
questions.append(question)
|
|
|
|
|
|
|
|
|
|
return questions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def judge_whether_main(file_path,output_folder): #传入招标文件中‘投标人须知前附表’
|
2024-09-03 11:42:43 +08:00
|
|
|
|
user_query1 = "请你依据以上信息,回答以下问题:是否组织踏勘现场?是否召开投标预备会?是否允许偏离?是否退还投标文件?是否允许分包? 是否需要递交投标保证金?是否需要提交履约保证金(履约担保)?是否有招标代理服务费?请按json格式给我提供信息,键名分别为'是否组织踏勘现场','是否召开投标预备会','是否允许偏离','是否退还投标文件',是否允许分包','是否递交投标保证金','是否提交履约保证金','是否有招标代理服务费',键值仅限于'是','否','未知',若存在矛盾信息,请回答'未知'。"
|
2024-10-18 13:37:54 +08:00
|
|
|
|
output_txt_path = os.path.join(output_folder,'judge_exist.txt')
|
|
|
|
|
read_pdf_and_judge_main(file_path, output_txt_path) #提取打勾符号
|
|
|
|
|
file_id=upload_file(output_txt_path)
|
|
|
|
|
qianwen_answer=qianwen_long(file_id,user_query1)
|
|
|
|
|
user_querys = construct_judge_questions(extract_content_from_json(qianwen_answer)) # 提取回答为”未知“的键
|
2024-10-15 20:57:58 +08:00
|
|
|
|
# 判断user_query2是否为空
|
2024-10-18 13:37:54 +08:00
|
|
|
|
if user_querys:
|
2024-08-29 16:37:09 +08:00
|
|
|
|
file_id = upload_file(file_path)
|
2024-10-18 13:37:54 +08:00
|
|
|
|
qianwen_results = multi_threading(user_querys, "", file_id, 2) # 1代表使用百炼rag 2代表使用qianwen-long
|
|
|
|
|
qianwen_list = [extract_content_from_json(res) for _, res in qianwen_results] if qianwen_results else [] #整个前附表一起传问千问long
|
|
|
|
|
return process_judge_content(qianwen_answer, qianwen_list)
|
2024-08-29 16:37:09 +08:00
|
|
|
|
|
|
|
|
|
else:
|
2024-09-03 11:42:43 +08:00
|
|
|
|
print("正常现象,没有'未知',无需调用qianwen-long")
|
2024-08-29 16:37:09 +08:00
|
|
|
|
original = extract_content_from_json(qianwen_answer)
|
|
|
|
|
return merge_json_to_list(original)
|
|
|
|
|
|
2024-10-18 13:37:54 +08:00
|
|
|
|
def process_judge_content(original_json, qianwen_list): #用新的数据合并旧数据
|
2024-08-29 16:37:09 +08:00
|
|
|
|
"""Process judging content by merging updates into the original JSON data."""
|
|
|
|
|
original = extract_content_from_json(original_json)
|
2024-10-18 13:37:54 +08:00
|
|
|
|
for i in qianwen_list:
|
|
|
|
|
original.update(i)
|
2024-08-29 16:37:09 +08:00
|
|
|
|
return merge_json_to_list(original)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-10-18 13:37:54 +08:00
|
|
|
|
file_path="C:\\Users\Administrator\\Desktop\\fsdownload\\ee2d8828-bae0-465a-9171-7b2dd7453251\\ztbfile_tobidders_notice_table.pdf"
|
|
|
|
|
output_dir='C:\\Users\Administrator\\Desktop\\fsdownload\\ee2d8828-bae0-465a-9171-7b2dd7453251\\tmp'
|
2024-08-29 16:37:09 +08:00
|
|
|
|
chosen_numbers, merged=judge_whether_main(file_path,output_dir)
|
|
|
|
|
print(chosen_numbers)
|
|
|
|
|
print(merged)
|
|
|
|
|
|