65 lines
2.8 KiB
Python
65 lines
2.8 KiB
Python
import json
|
||
from flask_app.general.json_utils import clean_json_string
|
||
from flask_app.general.多线程提问 import multi_threading,read_questions_from_file
|
||
from flask_app.general.通义千问long import upload_file,qianwen_long
|
||
|
||
# 从json文件中读取数据
|
||
with open('test.json', 'r', encoding='utf-8') as f:
|
||
data_dict = json.load(f)
|
||
|
||
# 定义目标名称列表
|
||
target_names = [
|
||
"营业执照",
|
||
"开户信息",
|
||
"法定代表人身份证",
|
||
"法定代表人授权人身份证",
|
||
# "人员证书",
|
||
# "人员社保资料",
|
||
# "劳动合同",
|
||
# "企业证书",
|
||
# "企业业绩",
|
||
# "财务信息(财务审计报告)",
|
||
# "财务信息(缴纳税收证明)",
|
||
# "财务信息(缴纳社保证明)"
|
||
]
|
||
|
||
# 定义user_query模板
|
||
def generate_user_query(target, chapters, keywords):
|
||
template = f"""该文件为投标文件格式要求的部分,请你根据该招标文件回答:{target}应该附在该文件哪个地方?你可能需要查找以下章节(若有):{', '.join([f"'{chapter}'" for chapter in chapters])};或者查找以下关键字出现的地方:{', '.join([f"'{kw}'" for kw in keywords])},你需要确定相关信息所在章节。
|
||
我需要将{target}贴在该章节的最后面,但是在下一章(别的内容)之前,目前我需要定位到插入的位置,请你返回给我插入位置的上下文,其中下文应该是下一章的章节名或开头内容,字数限制在30字以内,以json格式返回,键名分别是'上文','下文',上下文格式内容应完全与原文保持一致,不得擅自删减总结,示例输出如下:
|
||
{{
|
||
"上文":"投标人: (盖单位章)
|
||
年 月 日",
|
||
"下文":"四、投标保证金
|
||
(招标人名称):"
|
||
}}
|
||
"""
|
||
return template
|
||
|
||
# 生成user_query_list
|
||
user_query_list = []
|
||
|
||
for target in target_names:
|
||
if target in data_dict:
|
||
chapters = data_dict[target]["章节"]
|
||
keywords = data_dict[target]["关键字"]
|
||
user_query = generate_user_query(target, chapters, keywords)
|
||
user_query_list.append({
|
||
"target": target,
|
||
"query": user_query
|
||
})
|
||
else:
|
||
print(f"警告:'{target}'未在数据字典中找到相关信息。")
|
||
|
||
# 将生成的查询添加到queries列表
|
||
queries = [item['query'] for item in user_query_list]
|
||
truncate_file="C:\\Users\\Administrator\\Desktop\\招标文件\\招标test文件夹\\zbtest19\\zbtest19_214-320.pdf"
|
||
# 上传文件并获取file_id
|
||
file_id = upload_file(truncate_file)
|
||
# 使用multi_threading并行处理查询
|
||
results = multi_threading(queries, "", file_id, 2)
|
||
# 清理返回结果并输出
|
||
baseinfo_list = [clean_json_string(res) for _, res in results] if results else []
|
||
for i in baseinfo_list:
|
||
print(json.dumps(i, ensure_ascii=False, indent=4))
|