Skip to content

Commit

Permalink
Closes #2636 - Adds experimental.OpenAIModel
Browse files Browse the repository at this point in the history
  • Loading branch information
sadasant committed Apr 17, 2023
1 parent 640d3f6 commit 683e92c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### Added

- 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))

## [13.5.0] - 2023-04-07

### Added
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3684,6 +3684,13 @@
"scope": "window",
"order": 55
},
"gitlens.experimental.openAIModel": {
"type": "string",
"default": "gpt-3.5-turbo",
"markdownDescription": "Specifies the OpenAI model to use to generate commit messages when using the `GitLens: Generate Commit Message` command",
"scope": "window",
"order": 56
},
"gitlens.advanced.externalDiffTool": {
"type": [
"string",
Expand Down
17 changes: 14 additions & 3 deletions src/ai/openaiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ const maxCodeCharacters = 12000;
export class OpenAIProvider implements AIProvider {
readonly id = 'openai';
readonly name = 'OpenAI';
private model: OpenAIChatCompletionModels = 'gpt-3.5-turbo';

constructor(private readonly container: Container) {}

dispose() {}

public setModel(model: OpenAIChatCompletionModels) {
this.model = model;
}

async generateCommitMessage(diff: string, options?: { context?: string }): Promise<string | undefined> {
this.setModel(configuration.get('experimental.openAIModel') || 'gpt-3.5-turbo');

const openaiApiKey = await getApiKey(this.container.storage);
if (openaiApiKey == null) return undefined;

Expand All @@ -34,7 +41,7 @@ export class OpenAIProvider implements AIProvider {
}

const data: OpenAIChatCompletionRequest = {
model: 'gpt-3.5-turbo',
model: this.model,
messages: [
{
role: 'system',
Expand Down Expand Up @@ -79,6 +86,8 @@ export class OpenAIProvider implements AIProvider {
}

async explainChanges(message: string, diff: string): Promise<string | undefined> {
this.setModel(configuration.get('experimental.openAIModel') || 'gpt-3.5-turbo');

const openaiApiKey = await getApiKey(this.container.storage);
if (openaiApiKey == null) return undefined;

Expand All @@ -90,7 +99,7 @@ export class OpenAIProvider implements AIProvider {
}

const data: OpenAIChatCompletionRequest = {
model: 'gpt-3.5-turbo',
model: this.model,
messages: [
{
role: 'system',
Expand Down Expand Up @@ -195,8 +204,10 @@ async function getApiKey(storage: Storage): Promise<string | undefined> {
return openaiApiKey;
}

export type OpenAIChatCompletionModels = 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-32k' | 'gpt-4-32k-0314';

interface OpenAIChatCompletionRequest {
model: 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301';
model: OpenAIChatCompletionModels;
messages: { role: 'system' | 'user' | 'assistant'; content: string }[];
temperature?: number;
top_p?: number;
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface Config {
detectNestedRepositories: boolean;
experimental: {
generateCommitMessagePrompt: string;
openAIModel?: 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-32k' | 'gpt-4-32k-0314';
};
fileAnnotations: {
command: string | null;
Expand Down

0 comments on commit 683e92c

Please sign in to comment.