Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sadasant committed Apr 15, 2023
1 parent 640d3f6 commit 5b66a96
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 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 — closes [#]() thanks to [PR #]() by sadasant ([@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
4 changes: 3 additions & 1 deletion src/ai/aiProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { uncommittedStaged } from '../git/models/constants';
import type { GitRevisionReference } from '../git/models/reference';
import type { Repository } from '../git/models/repository';
import { isRepository } from '../git/models/repository';
import { configuration } from '../system/configuration';
import type { Storage } from '../system/storage';
import { OpenAIProvider } from './openaiProvider';

Expand All @@ -23,7 +24,8 @@ export class AIProviderService implements Disposable {
private _provider: AIProvider;

constructor(private readonly container: Container) {
this._provider = new OpenAIProvider(container);
const model = configuration.get('experimental.OpenAIModel');
this._provider = new OpenAIProvider(container, model);
}

dispose() {
Expand Down
14 changes: 10 additions & 4 deletions src/ai/openaiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ export class OpenAIProvider implements AIProvider {
readonly id = 'openai';
readonly name = 'OpenAI';

constructor(private readonly container: Container) {}
constructor(private readonly container: Container, private model: OpenAIChatCompletionModels = 'gpt-3.5-turbo') {}

dispose() {}

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

async generateCommitMessage(diff: string, options?: { context?: string }): Promise<string | undefined> {
const openaiApiKey = await getApiKey(this.container.storage);
if (openaiApiKey == null) return undefined;
Expand All @@ -34,7 +38,7 @@ export class OpenAIProvider implements AIProvider {
}

const data: OpenAIChatCompletionRequest = {
model: 'gpt-3.5-turbo',
model: this.model,
messages: [
{
role: 'system',
Expand Down Expand Up @@ -90,7 +94,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 +199,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 5b66a96

Please sign in to comment.