chore: add minimal reasoning effort for gpt5 (#2177)

Co-authored-by: Raj Shrestha <raj.shrestha@carelon.com>
This commit is contained in:
Raj Shrestha
2025-08-26 21:52:58 -06:00
committed by GitHub
parent 9d7d2052e7
commit 001a5159cf
3 changed files with 22 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/openai": patch
---
chore: add minimal reasoning effort for gpt5
+7 -4
View File
@@ -40,6 +40,7 @@ import { OpenAILive } from "./live.js";
import {
ALL_AVAILABLE_OPENAI_MODELS,
isFunctionCallingModel,
isReasoningEffortSupported,
isReasoningModel,
isTemperatureSupported,
type LLMInstance,
@@ -54,7 +55,7 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
// string & {} is a hack to allow any string, but still give autocomplete
| (string & {});
temperature: number;
reasoningEffort?: "low" | "medium" | "high" | undefined;
reasoningEffort?: "low" | "medium" | "high" | "minimal" | undefined;
topP: number;
maxTokens?: number | undefined;
additionalChatOptions?: OpenAIAdditionalChatOptions | undefined;
@@ -90,9 +91,11 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
this.model = init?.model ?? "gpt-4o";
this.temperature = init?.temperature ?? 0.1;
this.reasoningEffort = isReasoningModel(this.model)
? init?.reasoningEffort
: undefined;
this.reasoningEffort =
isReasoningModel(this.model) &&
isReasoningEffortSupported(this.model, init?.reasoningEffort)
? init?.reasoningEffort
: undefined;
this.topP = init?.topP ?? 1;
this.maxTokens = init?.maxTokens ?? undefined;
+10
View File
@@ -187,6 +187,16 @@ export function isReasoningModel(model: ChatModel | string): boolean {
return isO1 || isO3 || isO4 || isGPT5;
}
export function isReasoningEffortSupported(
model: ChatModel | string,
effort: string | undefined,
): boolean {
const supportedReasoningEffort = ["low", "medium", "high", undefined];
return model.startsWith("gpt-5")
? [...supportedReasoningEffort, "minimal"].includes(effort)
: supportedReasoningEffort.includes(effort);
}
export function isTemperatureSupported(model: ChatModel | string): boolean {
return !model.startsWith("o3") && !model.startsWith("o4");
}