From 11a1f04b0f123c11218e2d6f5d48f886733af852 Mon Sep 17 00:00:00 2001 From: myhloli Date: Tue, 28 Oct 2025 21:31:43 +0800 Subject: [PATCH] feat: enhance API call parameters with conditional extra_body for thinking mode --- mineru.template.json | 1 + mineru/utils/llm_aided.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mineru.template.json b/mineru.template.json index 4cf1c152..09596fde 100644 --- a/mineru.template.json +++ b/mineru.template.json @@ -18,6 +18,7 @@ "api_key": "your_api_key", "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1", "model": "qwen3-next-80b-a3b-instruct", + "enable_thinking": false, "enable": false } }, diff --git a/mineru/utils/llm_aided.py b/mineru/utils/llm_aided.py index 26285db0..bfb53eb4 100644 --- a/mineru/utils/llm_aided.py +++ b/mineru/utils/llm_aided.py @@ -84,16 +84,21 @@ Corrected title list: max_retries = 3 dict_completion = None + # 构建 API 调用参数 + api_params = { + "model": title_aided_config["model"], + "messages": [{'role': 'user', 'content': title_optimize_prompt}], + "temperature": 0.7, + "stream": True, + } + + # 只有配置中明确指定时才添加 extra_body + if "enable_thinking" in title_aided_config: + api_params["extra_body"] = {"enable_thinking": title_aided_config["enable_thinking"]} + while retry_count < max_retries: try: - completion = client.chat.completions.create( - model=title_aided_config["model"], - messages=[ - {'role': 'user', 'content': title_optimize_prompt}], - extra_body={"enable_thinking": False}, - temperature=0.7, - stream=True, - ) + completion = client.chat.completions.create(**api_params) content_pieces = [] for chunk in completion: if chunk.choices and chunk.choices[0].delta.content is not None: