mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-18 16:44:33 -04:00
chore: add minimal reasoning effort for gpt5 (#2177)
Co-authored-by: Raj Shrestha <raj.shrestha@carelon.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@llamaindex/openai": patch
|
||||
---
|
||||
|
||||
chore: add minimal reasoning effort for gpt5
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user