Skip to content

Commit 945cc86

Browse files
committed
Fixes models that don't support temperature
1 parent baa6f2f commit 945cc86

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

src/ai/aiProviderService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface AIModel<
4848
readonly default?: boolean;
4949
readonly hidden?: boolean;
5050

51-
readonly temperature?: number;
51+
readonly temperature?: number | null;
5252
}
5353

5454
interface AIProviderConstructor<Provider extends AIProviders = AIProviders> {
@@ -711,6 +711,8 @@ export function showDiffTruncationWarning(maxCodeCharacters: number, model: AIMo
711711
);
712712
}
713713

714-
export function getValidatedTemperature(): number {
714+
export function getValidatedTemperature(modelTemperature?: number | null): number | undefined {
715+
if (modelTemperature === null) return undefined;
716+
if (modelTemperature != null) return modelTemperature;
715717
return Math.max(0, Math.min(configuration.get('ai.modelOptions.temperature'), 2));
716718
}

src/ai/anthropicProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { OpenAICompatibleProvider } from './openAICompatibleProvider';
77
const provider = { id: 'anthropic', name: 'Anthropic' } as const;
88

99
type AnthropicModel = AIModel<typeof provider.id>;
10-
1110
const models: AnthropicModel[] = [
1211
{
1312
id: 'claude-3-5-sonnet-latest',
@@ -119,7 +118,7 @@ export class AnthropicProvider extends OpenAICompatibleProvider<typeof provider.
119118
system: system.content,
120119
stream: false,
121120
max_tokens: Math.min(outputTokens, model.maxTokens.output),
122-
temperature: model.temperature ?? getValidatedTemperature(),
121+
temperature: getValidatedTemperature(model.temperature),
123122
};
124123

125124
const rsp = await this.fetchCore(model, apiKey, request, cancellation);

src/ai/openAICompatibleProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
222222
messages: messages(maxCodeCharacters, retries),
223223
stream: false,
224224
max_completion_tokens: Math.min(outputTokens, model.maxTokens.output),
225-
temperature: model.temperature ?? getValidatedTemperature(),
225+
temperature: getValidatedTemperature(model.temperature),
226226
};
227227

228228
const rsp = await this.fetchCore(model, apiKey, request, cancellation);

src/ai/openaiProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,29 @@ const models: OpenAIModel[] = [
1111
name: 'o1 preview',
1212
maxTokens: { input: 128000, output: 32768 },
1313
provider: provider,
14+
temperature: null,
1415
},
1516
{
1617
id: 'o1-preview-2024-09-12',
1718
name: 'o1 preview',
1819
maxTokens: { input: 128000, output: 32768 },
1920
provider: provider,
21+
temperature: null,
2022
hidden: true,
2123
},
2224
{
2325
id: 'o1-mini',
2426
name: 'o1 mini',
2527
maxTokens: { input: 128000, output: 65536 },
2628
provider: provider,
29+
temperature: null,
2730
},
2831
{
2932
id: 'o1-mini-2024-09-12',
3033
name: 'o1 mini',
3134
maxTokens: { input: 128000, output: 65536 },
3235
provider: provider,
36+
temperature: null,
3337
hidden: true,
3438
},
3539
{

src/ai/vscodeProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class VSCodeAIProvider implements AIProvider<typeof provider.id> {
9292
messages,
9393
{
9494
justification: accessJustification,
95-
modelOptions: { temperature: model.temperature ?? getValidatedTemperature() },
95+
modelOptions: { temperature: getValidatedTemperature(model.temperature) },
9696
},
9797
cancellation,
9898
);

0 commit comments

Comments
 (0)