Skip to content

Commit 3d87abf

Browse files
daewoongohdw
authored andcommitted
fix(litellm): extend reasoning_effort typecast options and add tests
- Add none, minimal, xhigh, max options to reasoning_effort parameter typecast - Add test coverage for preserveReasoning and reasoningEffort in fetcher and handler Signed-off-by: daewoongoh <dw.oh@samsung.com>
1 parent b27beed commit 3d87abf

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/api/providers/__tests__/lite-llm.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ describe("LiteLLMHandler", () => {
848848
expect(reasoningChunks).toHaveLength(0)
849849
})
850850

851-
it("should use convertToR1Format and preserve reasoning when preserveReasoning is true", async () => {
851+
it("should use convertToR1Format, preserve reasoning, and pass reasoning_effort when preserveReasoning is true", async () => {
852852
const optionsWithReasoning: ApiHandlerOptions = {
853853
...mockOptions,
854854
litellmModelId: "deepseek-reasoner",
@@ -857,7 +857,7 @@ describe("LiteLLMHandler", () => {
857857

858858
vi.spyOn(handler as any, "fetchModel").mockResolvedValue({
859859
id: "deepseek-reasoner",
860-
info: { ...litellmDefaultModelInfo, preserveReasoning: true },
860+
info: { ...litellmDefaultModelInfo, preserveReasoning: true, reasoningEffort: "high" },
861861
})
862862

863863
const systemPrompt = "You are a helpful assistant"
@@ -899,6 +899,9 @@ describe("LiteLLMHandler", () => {
899899

900900
const createCall = mockCreate.mock.calls[0][0]
901901

902+
// Verify reasoning_effort is passed
903+
expect(createCall.reasoning_effort).toBe("high")
904+
902905
// Verify reasoning_content is preserved
903906
const assistantMessage = createCall.messages.find((m: any) => m.role === "assistant")
904907
expect(assistantMessage).toBeDefined()

src/api/providers/fetchers/__tests__/litellm.spec.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe("getLiteLLMModels", () => {
165165
})
166166
})
167167

168-
it("successfully fetches and formats LiteLLM models", async () => {
168+
it("successfully fetches and formats LiteLLM models with reasoning properties", async () => {
169169
const mockResponse = {
170170
data: {
171171
data: [
@@ -179,6 +179,8 @@ describe("getLiteLLMModels", () => {
179179
input_cost_per_token: 0.000003,
180180
output_cost_per_token: 0.000015,
181181
supports_computer_use: true,
182+
preserveReasoning: true,
183+
reasoningEffort: "high",
182184
},
183185
litellm_params: {
184186
model: "anthropic/claude-3.5-sonnet",
@@ -207,15 +209,6 @@ describe("getLiteLLMModels", () => {
207209

208210
const result = await getLiteLLMModels("test-api-key", "http://localhost:4000")
209211

210-
expect(mockedAxios.get).toHaveBeenCalledWith("http://localhost:4000/v1/model/info", {
211-
headers: {
212-
Authorization: "Bearer test-api-key",
213-
"Content-Type": "application/json",
214-
...DEFAULT_HEADERS,
215-
},
216-
timeout: 5000,
217-
})
218-
219212
expect(result).toEqual({
220213
"claude-3-5-sonnet": {
221214
maxTokens: 4096,
@@ -227,6 +220,8 @@ describe("getLiteLLMModels", () => {
227220
cacheWritesPrice: undefined,
228221
cacheReadsPrice: undefined,
229222
description: "claude-3-5-sonnet via LiteLLM proxy",
223+
preserveReasoning: true,
224+
reasoningEffort: "high",
230225
},
231226
"gpt-4-turbo": {
232227
maxTokens: 8192,

src/api/providers/lite-llm.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,17 @@ export class LiteLLMHandler extends RouterProvider implements SingleCompletionHa
216216
},
217217
tools: this.convertToolsForOpenAI(metadata?.tools),
218218
tool_choice: metadata?.tool_choice,
219-
...(info.reasoningEffort && { reasoning_effort: info.reasoningEffort as "low" | "medium" | "high" }),
219+
...(info.reasoningEffort && {
220+
reasoning_effort: info.reasoningEffort as
221+
| "none"
222+
| "minimal"
223+
| "low"
224+
| "medium"
225+
| "high"
226+
| "xhigh"
227+
| "max"
228+
| any,
229+
}),
220230
}
221231

222232
// GPT-5 models require max_completion_tokens instead of the deprecated max_tokens parameter

0 commit comments

Comments
 (0)