Skip to content

Commit d257695

Browse files
add reasoning level for gpt-5 family
1 parent 8cced67 commit d257695

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ const result = await zerox({
9696

9797
### Parameters
9898

99-
```ts
10099
const result = await zerox({
101100
// Required
102101
filePath: "path/to/file",
@@ -132,6 +131,14 @@ const result = await zerox({
132131
});
133132
```
134133
134+
// For GPT-5 models, you can control the reasoning effort:
135+
// Allowed values: "minimal", "low", "medium", "high"
136+
// Example:
137+
// ...
138+
// model: ModelOptions.OPENAI_GPT_5,
139+
// reasoning_effort: "medium",
140+
// ...
141+
135142
The `maintainFormat` option tries to return the markdown in a consistent format by passing the output of a prior page in as additional context for the next page. This requires the requests to run synchronously, so it's a lot slower. But valuable if your documents have a lot of tabular data, or frequently have tables that cross pages.
136143
137144
```
@@ -386,7 +393,6 @@ print(result)
386393

387394
### Parameters
388395

389-
```python
390396
async def zerox(
391397
cleanup: bool = True,
392398
concurrency: int = 10,
@@ -402,6 +408,12 @@ async def zerox(
402408
...
403409
```
404410
411+
# For GPT-5 models, you can control the reasoning effort:
412+
# Allowed values: "minimal", "low", "medium", "high"
413+
# Example:
414+
# result = await zerox(file_path=..., model="gpt-5", reasoning_effort="medium")
415+
416+
405417
Parameters
406418
407419
- **cleanup** (bool, optional):
@@ -423,6 +435,8 @@ Parameters
423435
The system prompt to use for the model, this overrides the default system prompt of Zerox.Generally it is not required unless you want some specific behavior. Defaults to None.
424436
- **select_pages** (Optional[Union[int, Iterable[int]]], optional):
425437
Pages to process, can be a single page number or an iterable of page numbers. Defaults to None
438+
- **reasoning_effort** (str, optional, GPT-5 only):
439+
Controls the reasoning effort for GPT-5 models. Allowed values: "minimal", "low", "medium", "high". Defaults to None.
426440
- **kwargs** (dict, optional):
427441
Additional keyword arguments to pass to the litellm.completion method.
428442
Refer to the LiteLLM Documentation and Completion Input for details.

node-zerox/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const zerox = async ({
6464
imageFormat = "png",
6565
imageHeight,
6666
llmParams = {},
67+
reasoning_effort,
6768
maintainFormat = false,
6869
maxImageSize = 15,
6970
maxRetries = 1,
@@ -79,6 +80,10 @@ export const zerox = async ({
7980
trimEdges = true,
8081
}: ZeroxArgs): Promise<ZeroxOutput> => {
8182
let extracted: Record<string, unknown> | null = null;
83+
// If reasoning is provided, add to llmParams
84+
if (reasoning_effort) {
85+
llmParams = { ...llmParams, reasoning_effort };
86+
}
8287
let extractedLogprobs: LogprobPage[] = [];
8388
let inputTokenCount: number = 0;
8489
let outputTokenCount: number = 0;

node-zerox/src/models/openAI.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default class OpenAIModel implements ModelInterface {
9696
priorPage,
9797
prompt,
9898
}: CompletionArgs): Promise<CompletionResponse> {
99-
const systemPrompt = prompt || SYSTEM_PROMPT_BASE;
99+
const systemPrompt = prompt || SYSTEM_PROMPT_BASE;
100100

101101
// Default system message
102102
const messages: any = [{ role: "system", content: systemPrompt }];
@@ -120,13 +120,18 @@ export default class OpenAIModel implements ModelInterface {
120120
messages.push({ role: "user", content: imageContents });
121121

122122
try {
123+
// If model is GPT-5 and reasoning_effort is provided, add it to payload
124+
let payload: any = {
125+
messages,
126+
model: this.model,
127+
...convertKeysToSnakeCase(this.llmParams ?? null),
128+
};
129+
if (this.model && this.model.startsWith("gpt-5") && this.llmParams?.reasoning_effort) {
130+
payload.reasoning_effort = this.llmParams.reasoning_effort;
131+
}
123132
const response = await axios.post(
124133
"https://api.openai.com/v1/chat/completions",
125-
{
126-
messages,
127-
model: this.model,
128-
...convertKeysToSnakeCase(this.llmParams ?? null),
129-
},
134+
payload,
130135
{
131136
headers: {
132137
Authorization: `Bearer ${this.apiKey}`,

node-zerox/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface ZeroxArgs {
2828
imageHeight?: number;
2929
imageFormat?: "png" | "jpeg";
3030
llmParams?: Partial<LLMParams>;
31+
reasoning_effort?: "minimal" | "low" | "medium" | "high";
3132
maintainFormat?: boolean;
3233
maxImageSize?: number;
3334
maxRetries?: number;
@@ -227,6 +228,7 @@ export interface GoogleLLMParams extends BaseLLMParams {
227228
export interface OpenAILLMParams extends BaseLLMParams {
228229
logprobs: boolean;
229230
maxTokens: number;
231+
reasoning_effort?: "minimal" | "low" | "medium" | "high";
230232
}
231233

232234
// Union type of all provider params

py_zerox/pyzerox/core/zerox.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async def zerox(
3535
temp_dir: Optional[str] = None,
3636
custom_system_prompt: Optional[str] = None,
3737
select_pages: Optional[Union[int, Iterable[int]]] = None,
38+
reasoning_effort: Optional[str] = None,
3839
**kwargs
3940
) -> ZeroxOutput:
4041
"""
@@ -76,6 +77,11 @@ async def zerox(
7677
raise FileUnavailable()
7778

7879
# Create an instance of the litellm model interface
80+
if reasoning_effort is not None:
81+
allowed = {"minimal", "low", "medium", "high"}
82+
if reasoning_effort not in allowed:
83+
raise ValueError(f"reasoning_effort must be one of {allowed}")
84+
kwargs["reasoning_effort"] = reasoning_effort
7985
vision_model = litellmmodel(model=model,**kwargs)
8086

8187
# override the system prompt if a custom prompt is provided

py_zerox/pyzerox/models/modellitellm.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ async def completion(
9292
)
9393

9494
try:
95-
response = await litellm.acompletion(model=self.model, messages=messages, **self.kwargs)
95+
# If model is GPT-5 and reasoning_effort is provided, add it to kwargs
96+
call_kwargs = dict(self.kwargs)
97+
if self.model and self.model.startswith("gpt-5") and "reasoning_effort" in call_kwargs:
98+
allowed = {"minimal", "low", "medium", "high"}
99+
if call_kwargs["reasoning_effort"] not in allowed:
100+
raise ValueError(f"reasoning_effort must be one of {allowed}")
101+
response = await litellm.acompletion(model=self.model, messages=messages, **call_kwargs)
96102

97103
## completion response
98104
response = CompletionResponse(

0 commit comments

Comments
 (0)