|
| 1 | +// npx jest src/api/providers/__tests__/openai.test.ts |
| 2 | + |
1 | 3 | import { OpenAiHandler } from "../openai" |
2 | 4 | import { ApiHandlerOptions } from "../../../shared/api" |
3 | 5 | import { Anthropic } from "@anthropic-ai/sdk" |
@@ -155,6 +157,39 @@ describe("OpenAiHandler", () => { |
155 | 157 | expect(textChunks).toHaveLength(1) |
156 | 158 | expect(textChunks[0].text).toBe("Test response") |
157 | 159 | }) |
| 160 | + it("should include reasoning_effort when reasoning effort is enabled", async () => { |
| 161 | + const reasoningOptions: ApiHandlerOptions = { |
| 162 | + ...mockOptions, |
| 163 | + enableReasoningEffort: true, |
| 164 | + openAiCustomModelInfo: { contextWindow: 128_000, supportsPromptCache: false, reasoningEffort: "high" }, |
| 165 | + } |
| 166 | + const reasoningHandler = new OpenAiHandler(reasoningOptions) |
| 167 | + const stream = reasoningHandler.createMessage(systemPrompt, messages) |
| 168 | + // Consume the stream to trigger the API call |
| 169 | + for await (const _chunk of stream) { |
| 170 | + } |
| 171 | + // Assert the mockCreate was called with reasoning_effort |
| 172 | + expect(mockCreate).toHaveBeenCalled() |
| 173 | + const callArgs = mockCreate.mock.calls[0][0] |
| 174 | + expect(callArgs.reasoning_effort).toBe("high") |
| 175 | + }) |
| 176 | + |
| 177 | + it("should not include reasoning_effort when reasoning effort is disabled", async () => { |
| 178 | + const noReasoningOptions: ApiHandlerOptions = { |
| 179 | + ...mockOptions, |
| 180 | + enableReasoningEffort: false, |
| 181 | + openAiCustomModelInfo: { contextWindow: 128_000, supportsPromptCache: false }, |
| 182 | + } |
| 183 | + const noReasoningHandler = new OpenAiHandler(noReasoningOptions) |
| 184 | + const stream = noReasoningHandler.createMessage(systemPrompt, messages) |
| 185 | + // Consume the stream to trigger the API call |
| 186 | + for await (const _chunk of stream) { |
| 187 | + } |
| 188 | + // Assert the mockCreate was called without reasoning_effort |
| 189 | + expect(mockCreate).toHaveBeenCalled() |
| 190 | + const callArgs = mockCreate.mock.calls[0][0] |
| 191 | + expect(callArgs.reasoning_effort).toBeUndefined() |
| 192 | + }) |
158 | 193 | }) |
159 | 194 |
|
160 | 195 | describe("error handling", () => { |
|
0 commit comments