File tree Expand file tree Collapse file tree 5 files changed +31
-7
lines changed Expand file tree Collapse file tree 5 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ export const zerox = async ({
64
64
imageFormat = "png" ,
65
65
imageHeight,
66
66
llmParams = { } ,
67
+ reasoning_effort,
67
68
maintainFormat = false ,
68
69
maxImageSize = 15 ,
69
70
maxRetries = 1 ,
@@ -79,6 +80,10 @@ export const zerox = async ({
79
80
trimEdges = true ,
80
81
} : ZeroxArgs ) : Promise < ZeroxOutput > => {
81
82
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
+ }
82
87
let extractedLogprobs : LogprobPage [ ] = [ ] ;
83
88
let inputTokenCount : number = 0 ;
84
89
let outputTokenCount : number = 0 ;
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ export default class OpenAIModel implements ModelInterface {
96
96
priorPage,
97
97
prompt,
98
98
} : CompletionArgs ) : Promise < CompletionResponse > {
99
- const systemPrompt = prompt || SYSTEM_PROMPT_BASE ;
99
+ const systemPrompt = prompt || SYSTEM_PROMPT_BASE ;
100
100
101
101
// Default system message
102
102
const messages : any = [ { role : "system" , content : systemPrompt } ] ;
@@ -120,13 +120,18 @@ export default class OpenAIModel implements ModelInterface {
120
120
messages . push ( { role : "user" , content : imageContents } ) ;
121
121
122
122
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
+ }
123
132
const response = await axios . post (
124
133
"https://api.openai.com/v1/chat/completions" ,
125
- {
126
- messages,
127
- model : this . model ,
128
- ...convertKeysToSnakeCase ( this . llmParams ?? null ) ,
129
- } ,
134
+ payload ,
130
135
{
131
136
headers : {
132
137
Authorization : `Bearer ${ this . apiKey } ` ,
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ export interface ZeroxArgs {
28
28
imageHeight ?: number ;
29
29
imageFormat ?: "png" | "jpeg" ;
30
30
llmParams ?: Partial < LLMParams > ;
31
+ reasoning_effort ?: "minimal" | "low" | "medium" | "high" ;
31
32
maintainFormat ?: boolean ;
32
33
maxImageSize ?: number ;
33
34
maxRetries ?: number ;
@@ -227,6 +228,7 @@ export interface GoogleLLMParams extends BaseLLMParams {
227
228
export interface OpenAILLMParams extends BaseLLMParams {
228
229
logprobs : boolean ;
229
230
maxTokens : number ;
231
+ reasoning_effort ?: "minimal" | "low" | "medium" | "high" ;
230
232
}
231
233
232
234
// Union type of all provider params
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ async def zerox(
35
35
temp_dir : Optional [str ] = None ,
36
36
custom_system_prompt : Optional [str ] = None ,
37
37
select_pages : Optional [Union [int , Iterable [int ]]] = None ,
38
+ reasoning_effort : Optional [str ] = None ,
38
39
** kwargs
39
40
) -> ZeroxOutput :
40
41
"""
@@ -76,6 +77,11 @@ async def zerox(
76
77
raise FileUnavailable ()
77
78
78
79
# 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
79
85
vision_model = litellmmodel (model = model ,** kwargs )
80
86
81
87
# override the system prompt if a custom prompt is provided
Original file line number Diff line number Diff line change @@ -92,7 +92,13 @@ async def completion(
92
92
)
93
93
94
94
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 )
96
102
97
103
## completion response
98
104
response = CompletionResponse (
You can’t perform that action at this time.
0 commit comments