zbparse/flask_app/general/判断截取位置.py

77 lines
3.9 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('../testdir/test.json', 'r', encoding='utf-8') as f:
data_dict = json.load(f)
# 定义目标名称列表
target_names = [
"营业执照",
# "开户信息",
"法定代表人身份证",
# "法定代表人授权人身份证",
"人员证书",
"人员社保资料",
# "劳动合同",
"企业证书",
"企业业绩",
"财务审计报告",
"缴纳税收证明",
"公司缴纳社保证明"
]
# 定义user_query模板
def generate_user_query(target, chapters, keywords):
#章节名格式通常是如'三、联合体协议书'这样的序号+标题。现在我需要将{target}贴在该章节的最后面,但是在下一章之前,目前我需要定位到插入的位置,
template = f"""这是投标文件模板,作为投标人,我需要把不同的投标材料填充到对应位置,请你根据该文件回答:{target}应该插入在该文件哪块地方?你可能需要查找以下关键词出现的地方:{', '.join([f"'{chapter}'" for chapter in chapters])},并确认插入的小节,然后在该小节的末尾内容之后插入{target}请你返回给我插入位置的上下文内容上文为该小节的末尾内容下文为下一小节的开头内容上下文字数请限制在20字以内即你只需返回最末尾的内容以及最开头的内容不需考虑语义。你的回答以json格式返回外层键名为'{target}',嵌套键名分别是'上文','下文',上下文内容应完全与原文保持一致,不得擅自删减总结,若插入位置不明确,那么嵌套键名'上文''下文'的键值为'未知',输出格式示例如下:
{{
{target}:{{
"上文":"上文测试投标人: (盖单位章)
年 月 日",
"下文":"下文测试章节名
(招标人名称):测试"
}}
}}
"""
template2=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}'未在数据字典中找到相关信息。")
#TODO:先对文件打标记,
# 将生成的查询添加到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))