From 5dfb30a37d2591a9478dfee2fda5368fa8b2ed65 Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Tue, 2 Sep 2025 10:47:15 -0500 Subject: [PATCH 1/4] Revert "fix: omit temperature parameter when not explicitly set for OpenAI Compatible providers (#7188)" This reverts commit 090737c516d7d56ac271ad2718b3158867d68af7. --- src/api/providers/__tests__/chutes.spec.ts | 1 + src/api/providers/__tests__/fireworks.spec.ts | 1 + src/api/providers/__tests__/groq.spec.ts | 79 +------------------ src/api/providers/__tests__/openai.spec.ts | 67 +--------------- src/api/providers/__tests__/roo.spec.ts | 6 +- src/api/providers/__tests__/sambanova.spec.ts | 1 + src/api/providers/__tests__/zai.spec.ts | 1 + .../base-openai-compatible-provider.ts | 8 +- src/api/providers/openai.ts | 9 +-- 9 files changed, 13 insertions(+), 160 deletions(-) diff --git a/src/api/providers/__tests__/chutes.spec.ts b/src/api/providers/__tests__/chutes.spec.ts index f6fd1ef0456..cbb66b60791 100644 --- a/src/api/providers/__tests__/chutes.spec.ts +++ b/src/api/providers/__tests__/chutes.spec.ts @@ -438,6 +438,7 @@ describe("ChutesHandler", () => { expect.objectContaining({ model: modelId, max_tokens: modelInfo.maxTokens, + temperature: 0.5, messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]), stream: true, stream_options: { include_usage: true }, diff --git a/src/api/providers/__tests__/fireworks.spec.ts b/src/api/providers/__tests__/fireworks.spec.ts index ed1e119a99f..f07c1797a05 100644 --- a/src/api/providers/__tests__/fireworks.spec.ts +++ b/src/api/providers/__tests__/fireworks.spec.ts @@ -373,6 +373,7 @@ describe("FireworksHandler", () => { expect.objectContaining({ model: modelId, max_tokens: modelInfo.maxTokens, + temperature: 0.5, messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]), stream: true, stream_options: { include_usage: true }, diff --git a/src/api/providers/__tests__/groq.spec.ts b/src/api/providers/__tests__/groq.spec.ts index 52846617f43..66bf0690a8f 100644 --- a/src/api/providers/__tests__/groq.spec.ts +++ b/src/api/providers/__tests__/groq.spec.ts @@ -160,11 +160,7 @@ describe("GroqHandler", () => { it("createMessage should pass correct parameters to Groq client", async () => { const modelId: GroqModelId = "llama-3.1-8b-instant" const modelInfo = groqModels[modelId] - const handlerWithModel = new GroqHandler({ - apiModelId: modelId, - groqApiKey: "test-groq-api-key", - modelTemperature: 0.5, // Explicitly set temperature for this test - }) + const handlerWithModel = new GroqHandler({ apiModelId: modelId, groqApiKey: "test-groq-api-key" }) mockCreate.mockImplementationOnce(() => { return { @@ -194,77 +190,4 @@ describe("GroqHandler", () => { undefined, ) }) - - it("should omit temperature when modelTemperature is undefined", async () => { - const modelId: GroqModelId = "llama-3.1-8b-instant" - const handlerWithoutTemp = new GroqHandler({ - apiModelId: modelId, - groqApiKey: "test-groq-api-key", - // modelTemperature is not set - }) - - mockCreate.mockImplementationOnce(() => { - return { - [Symbol.asyncIterator]: () => ({ - async next() { - return { done: true } - }, - }), - } - }) - - const systemPrompt = "Test system prompt" - const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Test message" }] - - const messageGenerator = handlerWithoutTemp.createMessage(systemPrompt, messages) - await messageGenerator.next() - - expect(mockCreate).toHaveBeenCalledWith( - expect.objectContaining({ - model: modelId, - messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]), - stream: true, - }), - undefined, - ) - - // Verify temperature is NOT included - const callArgs = mockCreate.mock.calls[0][0] - expect(callArgs).not.toHaveProperty("temperature") - }) - - it("should include temperature when modelTemperature is explicitly set", async () => { - const modelId: GroqModelId = "llama-3.1-8b-instant" - const handlerWithTemp = new GroqHandler({ - apiModelId: modelId, - groqApiKey: "test-groq-api-key", - modelTemperature: 0.7, - }) - - mockCreate.mockImplementationOnce(() => { - return { - [Symbol.asyncIterator]: () => ({ - async next() { - return { done: true } - }, - }), - } - }) - - const systemPrompt = "Test system prompt" - const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Test message" }] - - const messageGenerator = handlerWithTemp.createMessage(systemPrompt, messages) - await messageGenerator.next() - - expect(mockCreate).toHaveBeenCalledWith( - expect.objectContaining({ - model: modelId, - temperature: 0.7, - messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]), - stream: true, - }), - undefined, - ) - }) }) diff --git a/src/api/providers/__tests__/openai.spec.ts b/src/api/providers/__tests__/openai.spec.ts index 14ed35430a5..3e744d6e16e 100644 --- a/src/api/providers/__tests__/openai.spec.ts +++ b/src/api/providers/__tests__/openai.spec.ts @@ -315,71 +315,6 @@ describe("OpenAiHandler", () => { const callArgs = mockCreate.mock.calls[0][0] expect(callArgs.max_completion_tokens).toBe(4096) }) - - it("should omit temperature when modelTemperature is undefined", async () => { - const optionsWithoutTemperature: ApiHandlerOptions = { - ...mockOptions, - // modelTemperature is not set, should not include temperature - } - const handlerWithoutTemperature = new OpenAiHandler(optionsWithoutTemperature) - const stream = handlerWithoutTemperature.createMessage(systemPrompt, messages) - // Consume the stream to trigger the API call - for await (const _chunk of stream) { - } - // Assert the mockCreate was called without temperature - expect(mockCreate).toHaveBeenCalled() - const callArgs = mockCreate.mock.calls[0][0] - expect(callArgs).not.toHaveProperty("temperature") - }) - - it("should include temperature when modelTemperature is explicitly set to 0", async () => { - const optionsWithZeroTemperature: ApiHandlerOptions = { - ...mockOptions, - modelTemperature: 0, - } - const handlerWithZeroTemperature = new OpenAiHandler(optionsWithZeroTemperature) - const stream = handlerWithZeroTemperature.createMessage(systemPrompt, messages) - // Consume the stream to trigger the API call - for await (const _chunk of stream) { - } - // Assert the mockCreate was called with temperature: 0 - expect(mockCreate).toHaveBeenCalled() - const callArgs = mockCreate.mock.calls[0][0] - expect(callArgs.temperature).toBe(0) - }) - - it("should include temperature when modelTemperature is set to a non-zero value", async () => { - const optionsWithCustomTemperature: ApiHandlerOptions = { - ...mockOptions, - modelTemperature: 0.7, - } - const handlerWithCustomTemperature = new OpenAiHandler(optionsWithCustomTemperature) - const stream = handlerWithCustomTemperature.createMessage(systemPrompt, messages) - // Consume the stream to trigger the API call - for await (const _chunk of stream) { - } - // Assert the mockCreate was called with temperature: 0.7 - expect(mockCreate).toHaveBeenCalled() - const callArgs = mockCreate.mock.calls[0][0] - expect(callArgs.temperature).toBe(0.7) - }) - - it("should include DEEP_SEEK_DEFAULT_TEMPERATURE for deepseek-reasoner models when temperature is not set", async () => { - const deepseekOptions: ApiHandlerOptions = { - ...mockOptions, - openAiModelId: "deepseek-reasoner", - // modelTemperature is not set - } - const deepseekHandler = new OpenAiHandler(deepseekOptions) - const stream = deepseekHandler.createMessage(systemPrompt, messages) - // Consume the stream to trigger the API call - for await (const _chunk of stream) { - } - // Assert the mockCreate was called with DEEP_SEEK_DEFAULT_TEMPERATURE (0.6) - expect(mockCreate).toHaveBeenCalled() - const callArgs = mockCreate.mock.calls[0][0] - expect(callArgs.temperature).toBe(0.6) - }) }) describe("error handling", () => { @@ -515,7 +450,7 @@ describe("OpenAiHandler", () => { ], stream: true, stream_options: { include_usage: true }, - // temperature should be omitted when not set + temperature: 0, }, { path: "/models/chat/completions" }, ) diff --git a/src/api/providers/__tests__/roo.spec.ts b/src/api/providers/__tests__/roo.spec.ts index 5509c51e028..5897156b0a0 100644 --- a/src/api/providers/__tests__/roo.spec.ts +++ b/src/api/providers/__tests__/roo.spec.ts @@ -354,7 +354,7 @@ describe("RooHandler", () => { }) describe("temperature and model configuration", () => { - it("should omit temperature when not explicitly set", async () => { + it("should use default temperature of 0.7", async () => { handler = new RooHandler(mockOptions) const stream = handler.createMessage(systemPrompt, messages) for await (const _chunk of stream) { @@ -362,8 +362,8 @@ describe("RooHandler", () => { } expect(mockCreate).toHaveBeenCalledWith( - expect.not.objectContaining({ - temperature: expect.anything(), + expect.objectContaining({ + temperature: 0.7, }), undefined, ) diff --git a/src/api/providers/__tests__/sambanova.spec.ts b/src/api/providers/__tests__/sambanova.spec.ts index 81de3058c89..d8cae8bf806 100644 --- a/src/api/providers/__tests__/sambanova.spec.ts +++ b/src/api/providers/__tests__/sambanova.spec.ts @@ -144,6 +144,7 @@ describe("SambaNovaHandler", () => { expect.objectContaining({ model: modelId, max_tokens: modelInfo.maxTokens, + temperature: 0.7, messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]), stream: true, stream_options: { include_usage: true }, diff --git a/src/api/providers/__tests__/zai.spec.ts b/src/api/providers/__tests__/zai.spec.ts index 6882cfe448b..a16aa9fcdfe 100644 --- a/src/api/providers/__tests__/zai.spec.ts +++ b/src/api/providers/__tests__/zai.spec.ts @@ -220,6 +220,7 @@ describe("ZAiHandler", () => { expect.objectContaining({ model: modelId, max_tokens: modelInfo.maxTokens, + temperature: ZAI_DEFAULT_TEMPERATURE, messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]), stream: true, stream_options: { include_usage: true }, diff --git a/src/api/providers/base-openai-compatible-provider.ts b/src/api/providers/base-openai-compatible-provider.ts index 5d2b9425e7c..fb6c5d03770 100644 --- a/src/api/providers/base-openai-compatible-provider.ts +++ b/src/api/providers/base-openai-compatible-provider.ts @@ -74,19 +74,17 @@ export abstract class BaseOpenAiCompatibleProvider info: { maxTokens: max_tokens }, } = this.getModel() + const temperature = this.options.modelTemperature ?? this.defaultTemperature + const params: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = { model, max_tokens, + temperature, messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)], stream: true, stream_options: { include_usage: true }, } - // Only include temperature if explicitly set - if (this.options.modelTemperature !== undefined) { - params.temperature = this.options.modelTemperature - } - try { return this.client.chat.completions.create(params, requestOptions) } catch (error) { diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index 2a57f251318..aebe671712a 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -159,20 +159,13 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = { model: modelId, + temperature: this.options.modelTemperature ?? (deepseekReasoner ? DEEP_SEEK_DEFAULT_TEMPERATURE : 0), messages: convertedMessages, stream: true as const, ...(isGrokXAI ? {} : { stream_options: { include_usage: true } }), ...(reasoning && reasoning), } - // Only include temperature if explicitly set - if (this.options.modelTemperature !== undefined) { - requestOptions.temperature = this.options.modelTemperature - } else if (deepseekReasoner) { - // DeepSeek Reasoner has a specific default temperature - requestOptions.temperature = DEEP_SEEK_DEFAULT_TEMPERATURE - } - // Add max_tokens if needed this.addMaxTokensIfNeeded(requestOptions, modelInfo) From a521eaf40ee8031f9119562a66adc5c4c00b97a8 Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Tue, 2 Sep 2025 11:03:32 -0500 Subject: [PATCH 2/4] fix: update tests to match reverted code signature The requestOptions parameter was added after PR #7188, so tests need to be updated to not expect it after the revert --- src/api/providers/__tests__/chutes.spec.ts | 1 - src/api/providers/__tests__/fireworks.spec.ts | 1 - src/api/providers/__tests__/groq.spec.ts | 1 - src/api/providers/__tests__/roo.spec.ts | 3 --- src/api/providers/__tests__/sambanova.spec.ts | 1 - src/api/providers/__tests__/zai.spec.ts | 1 - 6 files changed, 8 deletions(-) diff --git a/src/api/providers/__tests__/chutes.spec.ts b/src/api/providers/__tests__/chutes.spec.ts index cbb66b60791..b301cc005ed 100644 --- a/src/api/providers/__tests__/chutes.spec.ts +++ b/src/api/providers/__tests__/chutes.spec.ts @@ -443,7 +443,6 @@ describe("ChutesHandler", () => { stream: true, stream_options: { include_usage: true }, }), - undefined, ) }) diff --git a/src/api/providers/__tests__/fireworks.spec.ts b/src/api/providers/__tests__/fireworks.spec.ts index f07c1797a05..9c102f8c891 100644 --- a/src/api/providers/__tests__/fireworks.spec.ts +++ b/src/api/providers/__tests__/fireworks.spec.ts @@ -378,7 +378,6 @@ describe("FireworksHandler", () => { stream: true, stream_options: { include_usage: true }, }), - undefined, ) }) diff --git a/src/api/providers/__tests__/groq.spec.ts b/src/api/providers/__tests__/groq.spec.ts index 66bf0690a8f..e31e5b991f7 100644 --- a/src/api/providers/__tests__/groq.spec.ts +++ b/src/api/providers/__tests__/groq.spec.ts @@ -187,7 +187,6 @@ describe("GroqHandler", () => { stream: true, stream_options: { include_usage: true }, }), - undefined, ) }) }) diff --git a/src/api/providers/__tests__/roo.spec.ts b/src/api/providers/__tests__/roo.spec.ts index 5897156b0a0..91f8ac2540d 100644 --- a/src/api/providers/__tests__/roo.spec.ts +++ b/src/api/providers/__tests__/roo.spec.ts @@ -260,7 +260,6 @@ describe("RooHandler", () => { expect.objectContaining({ role: "user", content: "Second message" }), ]), }), - undefined, ) }) }) @@ -365,7 +364,6 @@ describe("RooHandler", () => { expect.objectContaining({ temperature: 0.7, }), - undefined, ) }) @@ -383,7 +381,6 @@ describe("RooHandler", () => { expect.objectContaining({ temperature: 0.9, }), - undefined, ) }) diff --git a/src/api/providers/__tests__/sambanova.spec.ts b/src/api/providers/__tests__/sambanova.spec.ts index d8cae8bf806..cd0e4a1989f 100644 --- a/src/api/providers/__tests__/sambanova.spec.ts +++ b/src/api/providers/__tests__/sambanova.spec.ts @@ -149,7 +149,6 @@ describe("SambaNovaHandler", () => { stream: true, stream_options: { include_usage: true }, }), - undefined, ) }) }) diff --git a/src/api/providers/__tests__/zai.spec.ts b/src/api/providers/__tests__/zai.spec.ts index a16aa9fcdfe..6b93aaa43b7 100644 --- a/src/api/providers/__tests__/zai.spec.ts +++ b/src/api/providers/__tests__/zai.spec.ts @@ -225,7 +225,6 @@ describe("ZAiHandler", () => { stream: true, stream_options: { include_usage: true }, }), - undefined, ) }) }) From 7e6c8ebc529baca4e2b1af62cd2cd5b903ef8867 Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Fri, 5 Sep 2025 20:48:57 -0500 Subject: [PATCH 3/4] fix: update provider tests to expect requestOptions parameter after revert After reverting PR #7188, the createStream method in base-openai-compatible-provider.ts calls client.chat.completions.create() with two parameters: params and requestOptions. The tests need to be updated to expect this second parameter (which is often undefined). --- src/api/providers/__tests__/chutes.spec.ts | 2 ++ src/api/providers/__tests__/fireworks.spec.ts | 1 + src/api/providers/__tests__/groq.spec.ts | 1 + src/api/providers/__tests__/roo.spec.ts | 3 +++ src/api/providers/__tests__/sambanova.spec.ts | 1 + src/api/providers/__tests__/zai.spec.ts | 1 + 6 files changed, 9 insertions(+) diff --git a/src/api/providers/__tests__/chutes.spec.ts b/src/api/providers/__tests__/chutes.spec.ts index b301cc005ed..dbbc9b043ab 100644 --- a/src/api/providers/__tests__/chutes.spec.ts +++ b/src/api/providers/__tests__/chutes.spec.ts @@ -410,6 +410,7 @@ describe("ChutesHandler", () => { }, ], }), + undefined, ) }) @@ -443,6 +444,7 @@ describe("ChutesHandler", () => { stream: true, stream_options: { include_usage: true }, }), + undefined, ) }) diff --git a/src/api/providers/__tests__/fireworks.spec.ts b/src/api/providers/__tests__/fireworks.spec.ts index 9c102f8c891..f07c1797a05 100644 --- a/src/api/providers/__tests__/fireworks.spec.ts +++ b/src/api/providers/__tests__/fireworks.spec.ts @@ -378,6 +378,7 @@ describe("FireworksHandler", () => { stream: true, stream_options: { include_usage: true }, }), + undefined, ) }) diff --git a/src/api/providers/__tests__/groq.spec.ts b/src/api/providers/__tests__/groq.spec.ts index e31e5b991f7..66bf0690a8f 100644 --- a/src/api/providers/__tests__/groq.spec.ts +++ b/src/api/providers/__tests__/groq.spec.ts @@ -187,6 +187,7 @@ describe("GroqHandler", () => { stream: true, stream_options: { include_usage: true }, }), + undefined, ) }) }) diff --git a/src/api/providers/__tests__/roo.spec.ts b/src/api/providers/__tests__/roo.spec.ts index 91f8ac2540d..5897156b0a0 100644 --- a/src/api/providers/__tests__/roo.spec.ts +++ b/src/api/providers/__tests__/roo.spec.ts @@ -260,6 +260,7 @@ describe("RooHandler", () => { expect.objectContaining({ role: "user", content: "Second message" }), ]), }), + undefined, ) }) }) @@ -364,6 +365,7 @@ describe("RooHandler", () => { expect.objectContaining({ temperature: 0.7, }), + undefined, ) }) @@ -381,6 +383,7 @@ describe("RooHandler", () => { expect.objectContaining({ temperature: 0.9, }), + undefined, ) }) diff --git a/src/api/providers/__tests__/sambanova.spec.ts b/src/api/providers/__tests__/sambanova.spec.ts index cd0e4a1989f..d8cae8bf806 100644 --- a/src/api/providers/__tests__/sambanova.spec.ts +++ b/src/api/providers/__tests__/sambanova.spec.ts @@ -149,6 +149,7 @@ describe("SambaNovaHandler", () => { stream: true, stream_options: { include_usage: true }, }), + undefined, ) }) }) diff --git a/src/api/providers/__tests__/zai.spec.ts b/src/api/providers/__tests__/zai.spec.ts index 6b93aaa43b7..a16aa9fcdfe 100644 --- a/src/api/providers/__tests__/zai.spec.ts +++ b/src/api/providers/__tests__/zai.spec.ts @@ -225,6 +225,7 @@ describe("ZAiHandler", () => { stream: true, stream_options: { include_usage: true }, }), + undefined, ) }) }) From cb251210341684e7cac017d9aa0c3477f50d9a82 Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Mon, 8 Sep 2025 08:56:42 -0500 Subject: [PATCH 4/4] fix: update Chutes DeepSeek R1 test to match actual implementation --- src/api/providers/__tests__/chutes.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/api/providers/__tests__/chutes.spec.ts b/src/api/providers/__tests__/chutes.spec.ts index dbbc9b043ab..398f86ce608 100644 --- a/src/api/providers/__tests__/chutes.spec.ts +++ b/src/api/providers/__tests__/chutes.spec.ts @@ -409,8 +409,11 @@ describe("ChutesHandler", () => { content: `${systemPrompt}\n${messages[0].content}`, }, ], + max_tokens: 32768, + temperature: 0.6, + stream: true, + stream_options: { include_usage: true }, }), - undefined, ) })