diff --git a/flask_app/general/llm/多线程提问.py b/flask_app/general/llm/多线程提问.py index 71c7509..8d5b50e 100644 --- a/flask_app/general/llm/多线程提问.py +++ b/flask_app/general/llm/多线程提问.py @@ -5,7 +5,7 @@ import time from dashscope import Assistants, Messages, Runs, Threads from llama_index.indices.managed.dashscope import DashScopeCloudRetriever from flask_app.general.llm.大模型通用函数 import read_txt_to_string -from flask_app.general.llm.通义千问long import qianwen_long, upload_file +from flask_app.general.llm.通义千问long import qianwen_long, upload_file, qianwen_long_stream from flask_app.general.llm.qianwen_plus import qianwen_plus def read_questions_from_file(file_path): @@ -126,8 +126,8 @@ def llm_call(question, knowledge_name,file_id, result_queue, ans_index, llm_type result_queue.put((ans_index, (question, ans))) # 在队列中添加索引 (question, ans) elif llm_type==2: # print(f"qianwen_long! question:{question}") - # qianwen_res,usage = qianwen_long(file_id,question) #有bug - qianwen_res = qianwen_long(file_id, question,2,1,need_extra) + qianwen_res = qianwen_long_stream(file_id, question,2,1,need_extra) #流式返回 + # qianwen_res = qianwen_long(file_id, question,2,1,need_extra) #非流式 if not qianwen_res: result_queue.put((ans_index, None)) # 如果为空字符串,直接返回 None else: diff --git a/flask_app/general/llm/通义千问long.py b/flask_app/general/llm/通义千问long.py index cf81acb..a59d745 100644 --- a/flask_app/general/llm/通义千问long.py +++ b/flask_app/general/llm/通义千问long.py @@ -74,7 +74,7 @@ def qianwen_long(file_id, user_query, max_retries=2, backoff_factor=1.0, need_ex ], stream=False ) - token_usage = completion.usage.completion_tokens + token_usage = completion.usage.completion_tokens #生成的tokens,不算输入的 # 如果调用成功,返回响应内容 if need_extra: return completion.choices[0].message.content, token_usage @@ -142,7 +142,6 @@ def qianwen_long_stream(file_id, user_query, max_retries=2, backoff_factor=1.0, - 当 need_extra=False 时: 返回响应内容 (str) - 当 need_extra=True 时: 返回 (响应内容, token_usage) """ - print("调用 qianwen-long stream...") client = OpenAI( api_key=os.getenv("DASHSCOPE_API_KEY"), @@ -181,7 +180,7 @@ def qianwen_long_stream(file_id, user_query, max_retries=2, backoff_factor=1.0, # 处理 usage 信息 usage = chunk_data.get('usage') if usage is not None: - completion_tokens = usage.get('completion_tokens', 0) + completion_tokens = usage.get('completion_tokens', 0) #生成的tokens,不算输入的 # 处理 choices 信息 choices = chunk_data.get('choices', []) diff --git a/flask_app/货物标/提取采购需求main.py b/flask_app/货物标/提取采购需求main.py index b6d8ef9..dac1927 100644 --- a/flask_app/货物标/提取采购需求main.py +++ b/flask_app/货物标/提取采购需求main.py @@ -29,7 +29,7 @@ def fetch_procurement_reqs(procurement_path, invalid_path): page_count = get_pdf_page_count(procurement_path) if page_count > 60: #转换过多,消耗的tokens 以及 文档转换的费用过高!退而求其次用qianwen-long - tech_model_type = 2 # long + tech_model_type = 2 # long-stream busi_model_type = 3 # long-stream processed_filepath = "" # 如果procurement_path截取成功,则更新invalid_path