Skip to content

Commit af25adb

Browse files
committed
feat: Add reasoning_effort parameter support
Add reasoning_effort parameter to the completion function and LLMClient, supporting configuration of reasoning intensity via environment variables.
1 parent 1f6915f commit af25adb

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
OPENAI_API_KEY="sk-xxxxxx"
22
OPENAI_API_BASE="https://api.openai.com/v1/"
33
OPENAI_DEFAULT_MODEL="gpt-4o"
4+
OPENAI_REASONING_EFFORT="" # 'high' | 'medium' | 'low' | 'minimal'

core/LLMClient.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def completion(
3030
image_paths: Optional[list[str]] = None,
3131
temperature: float = 0.7,
3232
max_tokens: int = 8192,
33+
reasoning_effort: Optional[str] = None,
3334
) -> str:
3435
"""
3536
Create chat dialogue (supports multimodal)
@@ -71,11 +72,14 @@ def completion(
7172
messages=messages,
7273
temperature=temperature,
7374
max_tokens=max_tokens,
75+
reasoning_effort=reasoning_effort,
7476
extra_headers={
7577
"X-Title": "MarkPDFdown",
7678
"HTTP-Referer": "https://github.com/MarkPDFdown/markpdfdown.git",
7779
},
7880
)
81+
if not response.choices:
82+
raise Exception("No response from API")
7983
return response.choices[0].message.content
8084

8185
except Exception as e:

main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def completion(
2828
temperature=0.5,
2929
max_tokens=8192,
3030
retry_times=3,
31+
reasoning_effort=None,
3132
):
3233
"""
3334
Call OpenAI's completion interface for text generation
@@ -39,6 +40,8 @@ def completion(
3940
image_paths (List[str], optional): List of image paths, defaults to None
4041
temperature (float, optional): Temperature for text generation, defaults to 0.5
4142
max_tokens (int, optional): Maximum number of tokens for generated text, defaults to 8192
43+
retry_times (int, optional): Number of retries, defaults to 3
44+
reasoning_effort (str, optional): Reasoning effort, defaults to None
4245
Returns:
4346
str: Generated text content
4447
"""
@@ -57,6 +60,11 @@ def completion(
5760
model = os.getenv("OPENAI_DEFAULT_MODEL")
5861
if not model:
5962
model = "gpt-4o"
63+
64+
if not reasoning_effort:
65+
reasoning_effort = os.getenv("OPENAI_REASONING_EFFORT")
66+
if not reasoning_effort:
67+
reasoning_effort = None
6068

6169
# Initialize LLMClient
6270
client = LLMClient.LLMClient(base_url=base_url, api_key=api_key, model=model)
@@ -69,6 +77,7 @@ def completion(
6977
image_paths=image_paths,
7078
temperature=temperature,
7179
max_tokens=max_tokens,
80+
reasoning_effort=reasoning_effort,
7281
)
7382
return response
7483
except Exception as e:

0 commit comments

Comments
 (0)