-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Revert PR #7188 - Restore temperature parameter to fix TabbyApi/ExLlamaV2 crashes #7594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5dfb30a
a521eaf
7e6c8eb
cb25121
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentional that the temperature here is 0 instead of a default like 0.5 or 0.7? Just want to confirm this aligns with the expected default behavior for OpenAI providers when temperature isn't explicitly set. |
||
| }, | ||
| { path: "/models/chat/completions" }, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,19 +74,17 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string> | |
| info: { maxTokens: max_tokens }, | ||
| } = this.getModel() | ||
|
|
||
| const temperature = this.options.modelTemperature ?? this.defaultTemperature | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good restoration of the temperature parameter. This ensures it's always included with a fallback to the default temperature (0) when not explicitly set, preventing the TypeError in TabbyApi/ExLlamaV2. Consider adding a comment here explaining why temperature must always be included to prevent future developers from attempting similar optimizations: |
||
|
|
||
| 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) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The restoration here correctly handles the special case for DeepSeek Reasoner models while ensuring temperature is always included. This maintains compatibility with all OpenAI-compatible endpoints. |
||
| 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) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good cleanup - removing the tests that validated omitting temperature. The remaining test correctly expects temperature to always be present.