Skip to content

Commit bd0e1f3

Browse files
sadasanteamodio
authored andcommitted
Closes #2636 - Adds experimental.OpenAIModel
1 parent 0fa0355 commit bd0e1f3

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Adds a `gitlens.experimental.openAIModel` setting to specify the OpenAI model to use to generate commit messages when using the `GitLens: Generate Commit Message` command (defaults to `gpt-3.5-turbo`) — closes [#2636](https://github.com/gitkraken/vscode-gitlens/issues/2636) thanks to [PR #2637](https://github.com/gitkraken/vscode-gitlens/pull/2637) by Daniel Rodríguez ([@sadasant](https://github.com/sadasant))
12+
913
## [13.6.0] - 2023-05-11
1014

1115
### Added

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,13 @@
36673667
"scope": "window",
36683668
"order": 55
36693669
},
3670+
"gitlens.experimental.openAIModel": {
3671+
"type": "string",
3672+
"default": "gpt-3.5-turbo",
3673+
"markdownDescription": "Specifies the OpenAI model to use to generate commit messages when using the `GitLens: Generate Commit Message` command",
3674+
"scope": "window",
3675+
"order": 56
3676+
},
36703677
"gitlens.advanced.externalDiffTool": {
36713678
"type": [
36723679
"string",

src/ai/openaiProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ const maxCodeCharacters = 12000;
1212
export class OpenAIProvider implements AIProvider {
1313
readonly id = 'openai';
1414
readonly name = 'OpenAI';
15+
private model: OpenAIChatCompletionModels = 'gpt-3.5-turbo';
1516

1617
constructor(private readonly container: Container) {}
1718

1819
dispose() {}
1920

2021
async generateCommitMessage(diff: string, options?: { context?: string }): Promise<string | undefined> {
22+
this.model = configuration.get('experimental.openAIModel') || 'gpt-3.5-turbo';
23+
2124
const openaiApiKey = await getApiKey(this.container.storage);
2225
if (openaiApiKey == null) return undefined;
2326

@@ -34,7 +37,7 @@ export class OpenAIProvider implements AIProvider {
3437
}
3538

3639
const data: OpenAIChatCompletionRequest = {
37-
model: 'gpt-3.5-turbo',
40+
model: this.model,
3841
messages: [
3942
{
4043
role: 'system',
@@ -79,6 +82,8 @@ export class OpenAIProvider implements AIProvider {
7982
}
8083

8184
async explainChanges(message: string, diff: string): Promise<string | undefined> {
85+
this.model = configuration.get('experimental.openAIModel') || 'gpt-3.5-turbo';
86+
8287
const openaiApiKey = await getApiKey(this.container.storage);
8388
if (openaiApiKey == null) return undefined;
8489

@@ -90,7 +95,7 @@ export class OpenAIProvider implements AIProvider {
9095
}
9196

9297
const data: OpenAIChatCompletionRequest = {
93-
model: 'gpt-3.5-turbo',
98+
model: this.model,
9499
messages: [
95100
{
96101
role: 'system',
@@ -195,8 +200,10 @@ async function getApiKey(storage: Storage): Promise<string | undefined> {
195200
return openaiApiKey;
196201
}
197202

203+
export type OpenAIChatCompletionModels = 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-32k' | 'gpt-4-32k-0314';
204+
198205
interface OpenAIChatCompletionRequest {
199-
model: 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301';
206+
model: OpenAIChatCompletionModels;
200207
messages: { role: 'system' | 'user' | 'assistant'; content: string }[];
201208
temperature?: number;
202209
top_p?: number;

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface Config {
4949
detectNestedRepositories: boolean;
5050
experimental: {
5151
generateCommitMessagePrompt: string;
52+
openAIModel?: 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-32k' | 'gpt-4-32k-0314';
5253
};
5354
fileAnnotations: {
5455
command: string | null;

0 commit comments

Comments
 (0)