12.19 修复豆包模型使用的bug

This commit is contained in:
zy123 2024-12-19 14:34:05 +08:00
parent fd45d78c10
commit de8d8c0a2b
2 changed files with 15 additions and 18 deletions

View File

@ -362,27 +362,26 @@ def generate_prompt(judge_res, full_text=None):
base_prompt += "\n注意事项:\n1.严格按照上述要求执行,确保输出准确性和规范性。\n" base_prompt += "\n注意事项:\n1.严格按照上述要求执行,确保输出准确性和规范性。\n"
return base_prompt return base_prompt
def get_technical_requirements(invalid_path,processed_filepath): def get_technical_requirements(invalid_path,processed_filepath,model_type=1):
judge_res = ""
file_id = "" file_id = ""
model_type = 1 # 默认使用豆包 full_text = read_txt_to_string(processed_filepath)
if model_type:
first_query_template = """该文件是否说明了采购需求,即需要采购哪些内容(包括货物、设备、系统、功能模块等)?如果有,请回答'',否则,回答'' first_query_template = """该文件是否说明了采购需求,即需要采购哪些内容(包括货物、设备、系统、功能模块等)?如果有,请回答'',否则,回答''
文件内容 {}
{full_text}
""" """
judge_query = generate_full_user_query(processed_filepath, first_query_template) judge_query = first_query_template.format(f"文件内容:{full_text}")
# print(judge_query)
judge_res = doubao_model(judge_query) judge_res = doubao_model(judge_query)
if '' in judge_res: if '' in judge_res or model_type == 0:
model_type = 0 # 使用qianwen-long+invalid_path model_type = 0 # 使用qianwen-long+invalid_path
print("no!调用invalid_path") print("no!调用invalid_path")
if invalid_path.lower().endswith('.pdf'): #确保上传的是docx if invalid_path.lower().endswith('.pdf'): # 确保上传的是docx upload中一定是docx但是get_deviation中可能上传的是pdf
invalid_path = pdf2docx(invalid_path) invalid_path = pdf2docx(invalid_path)
file_id = upload_file(invalid_path) file_id = upload_file(invalid_path)
user_query = generate_prompt(judge_res) user_query = generate_prompt(judge_res)
model_res = qianwen_long(file_id, user_query) model_res = qianwen_long(file_id, user_query)
print(model_res) print(model_res)
else: else:
full_text = read_txt_to_string(processed_filepath)
user_query = generate_prompt(judge_res, full_text) user_query = generate_prompt(judge_res, full_text)
model_res = doubao_model(user_query) model_res = doubao_model(user_query)
print(model_res) print(model_res)
@ -467,7 +466,6 @@ def get_technical_requirements(invalid_path,processed_filepath):
modified_key = key.replace('.', '下的') modified_key = key.replace('.', '下的')
# 使用修改后的键填充第一个占位符,原始键填充第二个占位符 # 使用修改后的键填充第一个占位符,原始键填充第二个占位符
if model_type: if model_type:
full_text = read_txt_to_string(processed_filepath)
new_query = user_query_template.format(modified_key, key, modified_key,f"文件内容:{full_text}") #转豆包后取消注释 new_query = user_query_template.format(modified_key, key, modified_key,f"文件内容:{full_text}") #转豆包后取消注释
else: else:
new_query = user_query_template.format(modified_key, key, modified_key,"") new_query = user_query_template.format(modified_key, key, modified_key,"")
@ -479,7 +477,6 @@ def get_technical_requirements(invalid_path,processed_filepath):
# 将键中的 '.' 替换为 '下的' # 将键中的 '.' 替换为 '下的'
modified_grouped_key = grouped_key.replace('.', '下的') modified_grouped_key = grouped_key.replace('.', '下的')
if model_type: if model_type:
full_text = read_txt_to_string(processed_filepath)
new_query = user_query_template_two.format(modified_grouped_key, grouped_key_cnt, grouped_key, new_query = user_query_template_two.format(modified_grouped_key, grouped_key_cnt, grouped_key,
modified_grouped_key, f"文件内容:{full_text}") modified_grouped_key, f"文件内容:{full_text}")
else: else:

View File

@ -32,7 +32,7 @@ def fetch_procurement_reqs(procurement_path, invalid_path):
# 读取 PDF 页码数 # 读取 PDF 页码数
page_count = get_pdf_page_count(procurement_path) page_count = get_pdf_page_count(procurement_path)
if page_count > 80: # 如果页码数大于 50 if page_count > 80: # 如果页码数大于 580
model_type = 0 model_type = 0
processed_filepath = "" processed_filepath = ""
else: else: