zbparse/flask_app/main/商务标技术标整合.py
2024-10-10 11:52:37 +08:00

143 lines
7.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- encoding:utf-8 -*-
import json
from flask_app.main.json_utils import clean_json_string
from flask_app.main.通义千问long import upload_file, qianwen_long
# def combine_technical_and_business(data, target_values1, target_values2):
# extracted_data = {} # 根级别存储所有数据
# technical_found = False
# business_found = False
#
# def extract_nested(data, parent_key='', is_technical=False, is_business=False):
# nonlocal technical_found, business_found
# if isinstance(data, dict):
# for key, value in data.items():
# current_key = f"{parent_key}.{key}" if parent_key else key
#
# # 检查是否为技术标的内容
# if any(target in key for target in target_values1):
# if not is_technical:
# # 直接存储在根级别
# extracted_data[key] = value
# technical_found = True
# # 标记为技术标内容并停止进一步处理这个分支
# continue
#
# # 检查是否为商务标的内容
# elif any(target in key for target in target_values2):
# if not is_business:
# # 存储在'商务标'分类下
# if '商务标' not in extracted_data:
# extracted_data['商务标'] = {}
# extracted_data['商务标'][key] = value
# business_found = True
# # 标记为商务标内容并停止进一步处理这个分支
# continue
#
# # 如果当前值是字典或列表,且不在技术或商务分类下,继续递归搜索
# if isinstance(value, dict) or isinstance(value, list):
# extract_nested(value, current_key, is_technical, is_business)
#
# elif isinstance(data, list):
# for index, item in enumerate(data):
# extract_nested(item, f"{parent_key}[{index}]", is_technical, is_business)
#
# # 开始从顶级递归搜索
# extract_nested(data)
#
# # 处理未找到匹配的情况
# if not technical_found:
# extracted_data['技术标'] = ''
# if not business_found:
# extracted_data['商务标'] = ''
#
# return extracted_data
def remove_unknown_scores(data):
if isinstance(data, dict):
return {
k: remove_unknown_scores(v)
for k, v in data.items()
if not (k == "评分" and v in ["未知", "/", ""])
}
elif isinstance(data, list):
return [remove_unknown_scores(item) for item in data]
else:
return data
def combine_technical_and_business(data, target_values):
data=remove_unknown_scores(data)
extracted_data = {} # 根级别存储所有数据
technical_found = False
business_found = False
def extract_nested(data, parent_key='', is_technical=False, is_business=False):
nonlocal technical_found, business_found
if isinstance(data, dict):
for key, value in data.items():
current_key = f"{parent_key}.{key}" if parent_key else key
# 检查是否为技术标的内容
if any(target in key for target in target_values):
if not is_technical:
extracted_data[key] = value
technical_found = True
continue
# 默认其他所有内容都归为商务标
else:
if not is_business:
if '商务评分' not in extracted_data:
extracted_data['商务评分'] = {}
extracted_data['商务评分'][key] = value
business_found = True
continue
if isinstance(value, dict) or isinstance(value, list):
extract_nested(value, current_key, is_technical, is_business)
elif isinstance(data, list):
for index, item in enumerate(data):
extract_nested(item, f"{parent_key}[{index}]", is_technical, is_business)
extract_nested(data)
if not technical_found:
extracted_data['技术评分'] = ''
if not business_found:
extracted_data['商务评分'] = ''
return extracted_data
def combine_evaluation_standards(truncate2):
# 商务标、技术标评分项:千问
file_id = upload_file(truncate2)
# user_query_2 = (
# "根据该文档中的评标办法前附表,请你列出该文件的技术评分,商务评分,投标报价评审标准以及它们对应的具体评分要求,若对应内容中存在其他信息,在键名如'技术评分'中新增子键名'备注'存放该信息。如果评分内容因素不是这3个则返回文档中给定的评分内容因素以及它的评分要求。请以json格式返回结果不要回答有关形式、资格、响应性评审标准的内容")
user_query_2 = (
"""
根据该文档中的评标办法前附表请你列出该文件的技术评分商务评分投标报价评审标准以及它们对应的具体评分要求请以json格式返回结果请在这三大块评分中分别用若干键值对表示具体要求其内层的键名为'评分''要求',若这三大块评分中存在其他信息,则在相应评分大块中新增键名'备注'存放该信息键值为具体的要求否则不需要。如果评分内容因素不是这3个则返回文档中给定的评分内容因素以及它们的具体评分要求。不要回答有关形式、资格、响应性评审标准的内容若存在未知信息填充'未知'。以下为示例输出:
"技术评分": {
"主要监理岗位的职责": {
"评分": "4分",
"要求": "1、总监理工程师的职责全面、清晰、合理得 1.2-2分一般的1.2分。2、其他主要监理人员及岗位的职责全面、清晰、合理得 1.2-2分一般的 1.2分。"
}
}
"""
)
evaluation_res = qianwen_long(file_id, user_query_2)
target_values1 = ['技术标','技术部分','设计', '实施',"技术评分"]
# target_values2=['投标报价','商务标','商务部分','报价部分','业绩','信誉','分值','计算公式','信用','人员','资格','奖项','认证','荣誉']
# update_json=combine_technical_and_business(clean_json_string(evaluation_res),target_values1,target_values2)
update_json = combine_technical_and_business(clean_json_string(evaluation_res), target_values1)
# evaluation_combined_res = json.dumps(update_json,ensure_ascii=False,indent=4)
# return evaluation_combined_res
return update_json #商务标技术标整合
if __name__ == "__main__":
truncate2="C:\\Users\\Administrator\\Desktop\\招标文件\\招标test文件夹\\zbtest1_evaluation_method.pdf"
evaluation_standards_res=combine_evaluation_standards(truncate2)
# 从结果中提取"商务标"和"技术标"
technical_standards = {"技术评分": evaluation_standards_res.get("技术评分", {})}
commercial_standards = {"商务评分": evaluation_standards_res.get("商务评分", {})}
# 返回技术标和商务标
print(json.dumps(technical_standards,ensure_ascii=False,indent=4))
print(json.dumps(commercial_standards, ensure_ascii=False, indent=4))