Rename "ConfigKeys" enum to "GitAIConfigKey"

This commit is contained in:
Caleb Owens 2024-03-18 00:19:36 +00:00 committed by Mattias Granlund
parent 9c3093a918
commit bdb596005d
3 changed files with 34 additions and 34 deletions

View File

@ -4,7 +4,7 @@ import { OpenAIClient } from '$lib/backend/aiClients/openAI';
import { import {
AIService, AIService,
AnthropicModelName, AnthropicModelName,
ConfigKeys, GitAIConfigKey,
KeyOption, KeyOption,
ModelKind, ModelKind,
OpenAIModelName OpenAIModelName
@ -16,13 +16,13 @@ import type { AIClient } from '$lib/backend/aiClient';
import type { GitConfigService } from '$lib/backend/gitConfigService'; import type { GitConfigService } from '$lib/backend/gitConfigService';
const defaultGitConfig = Object.freeze({ const defaultGitConfig = Object.freeze({
[ConfigKeys.ModelProvider]: ModelKind.OpenAI, [GitAIConfigKey.ModelProvider]: ModelKind.OpenAI,
[ConfigKeys.OpenAIKeyOption]: KeyOption.ButlerAPI, [GitAIConfigKey.OpenAIKeyOption]: KeyOption.ButlerAPI,
[ConfigKeys.OpenAIKey]: undefined, [GitAIConfigKey.OpenAIKey]: undefined,
[ConfigKeys.OpenAIModelName]: OpenAIModelName.GPT35Turbo, [GitAIConfigKey.OpenAIModelName]: OpenAIModelName.GPT35Turbo,
[ConfigKeys.AnthropicKeyOption]: KeyOption.ButlerAPI, [GitAIConfigKey.AnthropicKeyOption]: KeyOption.ButlerAPI,
[ConfigKeys.AnthropicKey]: undefined, [GitAIConfigKey.AnthropicKey]: undefined,
[ConfigKeys.AnthropicModelName]: AnthropicModelName.Haiku [GitAIConfigKey.AnthropicModelName]: AnthropicModelName.Haiku
}); });
class DummyGitConfigService implements GitConfigService { class DummyGitConfigService implements GitConfigService {
@ -91,8 +91,8 @@ describe.concurrent('AIService', () => {
test('When token is bring your own, When a openAI token is present. It returns OpenAIClient', async () => { test('When token is bring your own, When a openAI token is present. It returns OpenAIClient', async () => {
const gitConfig = new DummyGitConfigService({ const gitConfig = new DummyGitConfigService({
...defaultGitConfig, ...defaultGitConfig,
[ConfigKeys.OpenAIKeyOption]: KeyOption.BringYourOwn, [GitAIConfigKey.OpenAIKeyOption]: KeyOption.BringYourOwn,
[ConfigKeys.OpenAIKey]: 'sk-asdfasdf' [GitAIConfigKey.OpenAIKey]: 'sk-asdfasdf'
}); });
const aiService = new AIService(gitConfig, cloud); const aiService = new AIService(gitConfig, cloud);
@ -103,8 +103,8 @@ describe.concurrent('AIService', () => {
const toastErrorSpy = vi.spyOn(toasts, 'error'); const toastErrorSpy = vi.spyOn(toasts, 'error');
const gitConfig = new DummyGitConfigService({ const gitConfig = new DummyGitConfigService({
...defaultGitConfig, ...defaultGitConfig,
[ConfigKeys.OpenAIKeyOption]: KeyOption.BringYourOwn, [GitAIConfigKey.OpenAIKeyOption]: KeyOption.BringYourOwn,
[ConfigKeys.OpenAIKey]: undefined [GitAIConfigKey.OpenAIKey]: undefined
}); });
const aiService = new AIService(gitConfig, cloud); const aiService = new AIService(gitConfig, cloud);
@ -117,9 +117,9 @@ describe.concurrent('AIService', () => {
test('When ai provider is Anthropic, When token is bring your own, When an anthropic token is present. It returns AnthropicAIClient', async () => { test('When ai provider is Anthropic, When token is bring your own, When an anthropic token is present. It returns AnthropicAIClient', async () => {
const gitConfig = new DummyGitConfigService({ const gitConfig = new DummyGitConfigService({
...defaultGitConfig, ...defaultGitConfig,
[ConfigKeys.ModelProvider]: ModelKind.Anthropic, [GitAIConfigKey.ModelProvider]: ModelKind.Anthropic,
[ConfigKeys.AnthropicKeyOption]: KeyOption.BringYourOwn, [GitAIConfigKey.AnthropicKeyOption]: KeyOption.BringYourOwn,
[ConfigKeys.AnthropicKey]: 'sk-ant-api03-asdfasdf' [GitAIConfigKey.AnthropicKey]: 'sk-ant-api03-asdfasdf'
}); });
const aiService = new AIService(gitConfig, cloud); const aiService = new AIService(gitConfig, cloud);
@ -130,9 +130,9 @@ describe.concurrent('AIService', () => {
const toastErrorSpy = vi.spyOn(toasts, 'error'); const toastErrorSpy = vi.spyOn(toasts, 'error');
const gitConfig = new DummyGitConfigService({ const gitConfig = new DummyGitConfigService({
...defaultGitConfig, ...defaultGitConfig,
[ConfigKeys.ModelProvider]: ModelKind.Anthropic, [GitAIConfigKey.ModelProvider]: ModelKind.Anthropic,
[ConfigKeys.AnthropicKeyOption]: KeyOption.BringYourOwn, [GitAIConfigKey.AnthropicKeyOption]: KeyOption.BringYourOwn,
[ConfigKeys.AnthropicKey]: undefined [GitAIConfigKey.AnthropicKey]: undefined
}); });
const aiService = new AIService(gitConfig, cloud); const aiService = new AIService(gitConfig, cloud);

View File

@ -59,7 +59,7 @@ export enum AnthropicModelName {
Haiku = 'claude-3-haiku-20240307' Haiku = 'claude-3-haiku-20240307'
} }
export enum ConfigKeys { export enum GitAIConfigKey {
ModelProvider = 'gitbutler.aiModelProvider', ModelProvider = 'gitbutler.aiModelProvider',
OpenAIKeyOption = 'gitbutler.aiOpenAIKeyOption', OpenAIKeyOption = 'gitbutler.aiOpenAIKeyOption',
OpenAIModelName = 'gitbutler.aiOpenAIModelName', OpenAIModelName = 'gitbutler.aiOpenAIModelName',
@ -94,15 +94,15 @@ export class AIService {
// Secondly, if the user has opted to bring their own key but hasn't provided one, it will return undefined // Secondly, if the user has opted to bring their own key but hasn't provided one, it will return undefined
async buildClient(userToken?: string): Promise<undefined | AIClient> { async buildClient(userToken?: string): Promise<undefined | AIClient> {
const modelKind = await this.gitConfig.getWithDefault<ModelKind>( const modelKind = await this.gitConfig.getWithDefault<ModelKind>(
ConfigKeys.ModelProvider, GitAIConfigKey.ModelProvider,
ModelKind.OpenAI ModelKind.OpenAI
); );
const openAIKeyOption = await this.gitConfig.getWithDefault<KeyOption>( const openAIKeyOption = await this.gitConfig.getWithDefault<KeyOption>(
ConfigKeys.OpenAIKeyOption, GitAIConfigKey.OpenAIKeyOption,
KeyOption.ButlerAPI KeyOption.ButlerAPI
); );
const anthropicKeyOption = await this.gitConfig.getWithDefault<KeyOption>( const anthropicKeyOption = await this.gitConfig.getWithDefault<KeyOption>(
ConfigKeys.AnthropicKeyOption, GitAIConfigKey.AnthropicKeyOption,
KeyOption.ButlerAPI KeyOption.ButlerAPI
); );
@ -119,10 +119,10 @@ export class AIService {
if (modelKind == ModelKind.OpenAI) { if (modelKind == ModelKind.OpenAI) {
const openAIModelName = await this.gitConfig.getWithDefault<OpenAIModelName>( const openAIModelName = await this.gitConfig.getWithDefault<OpenAIModelName>(
ConfigKeys.OpenAIModelName, GitAIConfigKey.OpenAIModelName,
OpenAIModelName.GPT35Turbo OpenAIModelName.GPT35Turbo
); );
const openAIKey = await this.gitConfig.get(ConfigKeys.OpenAIKey); const openAIKey = await this.gitConfig.get(GitAIConfigKey.OpenAIKey);
if (!openAIKey) { if (!openAIKey) {
toasts.error( toasts.error(
@ -136,10 +136,10 @@ export class AIService {
} }
if (modelKind == ModelKind.Anthropic) { if (modelKind == ModelKind.Anthropic) {
const anthropicModelName = await this.gitConfig.getWithDefault<AnthropicModelName>( const anthropicModelName = await this.gitConfig.getWithDefault<AnthropicModelName>(
ConfigKeys.AnthropicModelName, GitAIConfigKey.AnthropicModelName,
AnthropicModelName.Haiku AnthropicModelName.Haiku
); );
const anthropicKey = await this.gitConfig.get(ConfigKeys.AnthropicKey); const anthropicKey = await this.gitConfig.get(GitAIConfigKey.AnthropicKey);
if (!anthropicKey) { if (!anthropicKey) {
toasts.error( toasts.error(

View File

@ -4,7 +4,7 @@
import TextBox from './TextBox.svelte'; import TextBox from './TextBox.svelte';
import { import {
AnthropicModelName, AnthropicModelName,
ConfigKeys, GitAIConfigKey,
KeyOption, KeyOption,
ModelKind, ModelKind,
OpenAIModelName OpenAIModelName
@ -37,29 +37,29 @@
onMount(async () => { onMount(async () => {
modelKind = await gitConfigService.getWithDefault<ModelKind>( modelKind = await gitConfigService.getWithDefault<ModelKind>(
ConfigKeys.ModelProvider, GitAIConfigKey.ModelProvider,
ModelKind.OpenAI ModelKind.OpenAI
); );
openAIKeyOption = await gitConfigService.getWithDefault<KeyOption>( openAIKeyOption = await gitConfigService.getWithDefault<KeyOption>(
ConfigKeys.OpenAIKeyOption, GitAIConfigKey.OpenAIKeyOption,
KeyOption.ButlerAPI KeyOption.ButlerAPI
); );
openAIModelName = await gitConfigService.getWithDefault<OpenAIModelName>( openAIModelName = await gitConfigService.getWithDefault<OpenAIModelName>(
ConfigKeys.OpenAIModelName, GitAIConfigKey.OpenAIModelName,
OpenAIModelName.GPT35Turbo OpenAIModelName.GPT35Turbo
); );
openAIKey = await gitConfigService.get(ConfigKeys.OpenAIKey); openAIKey = await gitConfigService.get(GitAIConfigKey.OpenAIKey);
anthropicKeyOption = await gitConfigService.getWithDefault<KeyOption>( anthropicKeyOption = await gitConfigService.getWithDefault<KeyOption>(
ConfigKeys.AnthropicKeyOption, GitAIConfigKey.AnthropicKeyOption,
KeyOption.ButlerAPI KeyOption.ButlerAPI
); );
anthropicModelName = await gitConfigService.getWithDefault<AnthropicModelName>( anthropicModelName = await gitConfigService.getWithDefault<AnthropicModelName>(
ConfigKeys.AnthropicModelName, GitAIConfigKey.AnthropicModelName,
AnthropicModelName.Haiku AnthropicModelName.Haiku
); );
anthropicKey = await gitConfigService.get(ConfigKeys.AnthropicKey); anthropicKey = await gitConfigService.get(GitAIConfigKey.AnthropicKey);
}); });
$: if (form) form.modelKind.value = modelKind; $: if (form) form.modelKind.value = modelKind;