Browse Source

feat: enhance API call parameters with conditional extra_body for thinking mode

myhloli 2 weeks ago
parent
commit
11a1f04b0f
2 changed files with 14 additions and 8 deletions
  1. 1 0
      mineru.template.json
  2. 13 8
      mineru/utils/llm_aided.py

+ 1 - 0
mineru.template.json

@@ -18,6 +18,7 @@
             "api_key": "your_api_key",
             "api_key": "your_api_key",
             "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
             "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
             "model": "qwen3-next-80b-a3b-instruct",
             "model": "qwen3-next-80b-a3b-instruct",
+            "enable_thinking": false,
             "enable": false
             "enable": false
         }
         }
     },
     },

+ 13 - 8
mineru/utils/llm_aided.py

@@ -84,16 +84,21 @@ Corrected title list:
     max_retries = 3
     max_retries = 3
     dict_completion = None
     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:
     while retry_count < max_retries:
         try:
         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 = []
             content_pieces = []
             for chunk in completion:
             for chunk in completion:
                 if chunk.choices and chunk.choices[0].delta.content is not None:
                 if chunk.choices and chunk.choices[0].delta.content is not None: