mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-20 22:41:23 -04:00
Add reasoning_effort for o1 and o3 (#1628)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@llamaindex/openai": patch
|
||||
---
|
||||
|
||||
Add reasoning_effort for o1 and o3 models
|
||||
@@ -140,6 +140,12 @@ export function isFunctionCallingModel(llm: LLM): llm is OpenAI {
|
||||
return isChatModel && !isOld && !isO1;
|
||||
}
|
||||
|
||||
export function isReasoningModel(model: ChatModel | string): boolean {
|
||||
const isO1 = model.startsWith("o1");
|
||||
const isO3 = model.startsWith("o3");
|
||||
return isO1 || isO3;
|
||||
}
|
||||
|
||||
export function isTemperatureSupported(model: ChatModel | string): boolean {
|
||||
return !model.startsWith("o3");
|
||||
}
|
||||
@@ -152,6 +158,7 @@ export type OpenAIAdditionalChatOptions = Omit<
|
||||
| "messages"
|
||||
| "model"
|
||||
| "temperature"
|
||||
| "reasoning_effort"
|
||||
| "top_p"
|
||||
| "stream"
|
||||
| "tools"
|
||||
@@ -166,6 +173,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;
|
||||
topP: number;
|
||||
maxTokens?: number | undefined;
|
||||
additionalChatOptions?: OpenAIAdditionalChatOptions | undefined;
|
||||
@@ -197,6 +205,9 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
||||
super();
|
||||
this.model = init?.model ?? "gpt-4o";
|
||||
this.temperature = init?.temperature ?? 0.1;
|
||||
this.reasoningEffort = isReasoningModel(this.model)
|
||||
? init?.reasoningEffort
|
||||
: undefined;
|
||||
this.topP = init?.topP ?? 1;
|
||||
this.maxTokens = init?.maxTokens ?? undefined;
|
||||
|
||||
@@ -354,6 +365,7 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
||||
const baseRequestParams = <OpenAILLM.Chat.ChatCompletionCreateParams>{
|
||||
model: this.model,
|
||||
temperature: isTemperatureSupported(this.model) ? this.temperature : null,
|
||||
reasoning_effort: this.reasoningEffort,
|
||||
max_tokens: this.maxTokens,
|
||||
tools: tools?.map(OpenAI.toTool),
|
||||
messages: OpenAI.toOpenAIMessage(messages),
|
||||
|
||||
Reference in New Issue
Block a user