|
|
@@ -315,6 +315,71 @@ 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", () => {
|
|
|
@@ -450,7 +515,7 @@ describe("OpenAiHandler", () => {
|
|
|
],
|
|
|
stream: true,
|
|
|
stream_options: { include_usage: true },
|
|
|
- temperature: 0,
|
|
|
+ // temperature should be omitted when not set
|
|
|
},
|
|
|
{ path: "/models/chat/completions" },
|
|
|
)
|