zbparse/flask_app/testdir/判断截取位置.py
2024-10-25 10:18:38 +08:00

73 lines
3.8 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.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格式返回键名分别是'上文','下文',上下文格式内容应完全与原文保持一致,不得擅自删减总结,输出格式示例如下:
{{
"上文":"上文相关内容
测试",
"下文":"四、下文章节名
(招标人名称):测试"
}}
"""
template2=f"""该文件为投标文件格式要求,请你根据该招标文件回答:{target}应该附在哪个地方?你可能需要查找以下章节出现的地方:{', '.join([f"'{chapter}'" for chapter in chapters])};或者可能匹配的关键字:{', '.join([f"'{kw}'" for kw in keywords])},并确定所在章节。我需要将{target}贴在该章节的最后面目前我需要定位到插入的位置请你返回给我插入位置的上下文下文应该是下一章的章节名或开头内容字数限制在30字以内以json格式返回键名分别是'上文','下文',上下文格式内容应完全与原文保持一致,不得擅自删减总结,示例输出如下:
{{
"上文":"上文相关内容
测试",
"下文":"四、下文章节名
(招标人名称):测试"
}}
"""
return template2
# 生成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))