fix support for reasoning effort, and add support for reasoning summary (#2227)

This commit is contained in:
Adrian Lyjak
2025-10-23 16:17:56 -04:00
committed by GitHub
parent ba42e3407c
commit 1028877090
3 changed files with 63 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/openai": patch
---
Fix support for reasoning effort, and add support for reasoning summary
@@ -53,6 +53,7 @@ export class OpenAIResponses extends ToolCallLLM<OpenAIResponsesChatOptions> {
maxOutputTokens?: number | undefined;
additionalChatOptions?: OpenAIResponsesChatOptions | undefined;
reasoningEffort?: "low" | "medium" | "high" | undefined;
reasoningSummary?: "auto" | "concise" | "detailed" | undefined;
apiKey?: string | undefined;
baseURL?: string | undefined;
maxRetries: number;
@@ -86,6 +87,9 @@ export class OpenAIResponses extends ToolCallLLM<OpenAIResponsesChatOptions> {
? init?.reasoningEffort
: undefined;
this.reasoningSummary = isReasoningModel(this.model)
? init?.reasoningSummary
: undefined;
this.topP = init?.topP ?? 1;
this.maxOutputTokens = init?.maxOutputTokens ?? undefined;
this.maxRetries = init?.maxRetries ?? 10;
@@ -515,6 +519,10 @@ export class OpenAIResponses extends ToolCallLLM<OpenAIResponsesChatOptions> {
const baseRequestParams = <OpenAILLM.Responses.ResponseCreateParams>{
model: this.model,
reasoning: {
effort: this.reasoningEffort,
summary: this.reasoningSummary,
},
include: this.include,
input: this.toOpenAIResponseMessages(messages),
tools: processedBuiltInTools,
@@ -1,6 +1,7 @@
import type { BaseTool, ToolCallOptions } from "@llamaindex/core/llms";
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { OpenAIResponses } from "../src/responses";
import { LLMInstance } from "../src/utils";
const API_KEY = process.env.MY_OPENAI_API_KEY;
@@ -94,6 +95,54 @@ describe("OpenAIResponses Integration Tests", () => {
});
describe("OpenAIResponses Unit Tests", () => {
it("passes reasoning_effort to OpenAI SDK when reasoningEffort is set", async () => {
const createSpy = vi.fn().mockResolvedValue({
id: "resp_123",
output: [
{
type: "message",
role: "assistant",
content: [
{
type: "output_text",
text: "ok",
},
],
},
],
});
const mockSession = {
responses: {
create: createSpy,
},
apiKey: undefined,
baseURL: undefined,
chat: {} as unknown,
embeddings: {} as unknown,
} as const;
const llm = new OpenAIResponses({
model: "gpt-5",
reasoningEffort: "high",
reasoningSummary: "auto",
session: mockSession as unknown as LLMInstance,
});
await llm.chat({
messages: [
{
role: "user",
content: "hello",
},
],
});
expect(createSpy).toHaveBeenCalledTimes(1);
const arg = createSpy.mock.calls[0]?.[0] as Record<string, unknown>;
expect(arg["reasoning"]).toHaveProperty("effort", "high");
expect(arg["reasoning"]).toHaveProperty("summary", "auto");
});
// Testing utility functions
describe("processMessageContent", () => {
const llm = new OpenAIResponses({