mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-22 00:51:38 +03:00
Rename "ConfigKeys" enum to "GitAIConfigKey"
This commit is contained in:
parent
9c3093a918
commit
bdb596005d
@ -4,7 +4,7 @@ import { OpenAIClient } from '$lib/backend/aiClients/openAI';
|
||||
import {
|
||||
AIService,
|
||||
AnthropicModelName,
|
||||
ConfigKeys,
|
||||
GitAIConfigKey,
|
||||
KeyOption,
|
||||
ModelKind,
|
||||
OpenAIModelName
|
||||
@ -16,13 +16,13 @@ import type { AIClient } from '$lib/backend/aiClient';
|
||||
import type { GitConfigService } from '$lib/backend/gitConfigService';
|
||||
|
||||
const defaultGitConfig = Object.freeze({
|
||||
[ConfigKeys.ModelProvider]: ModelKind.OpenAI,
|
||||
[ConfigKeys.OpenAIKeyOption]: KeyOption.ButlerAPI,
|
||||
[ConfigKeys.OpenAIKey]: undefined,
|
||||
[ConfigKeys.OpenAIModelName]: OpenAIModelName.GPT35Turbo,
|
||||
[ConfigKeys.AnthropicKeyOption]: KeyOption.ButlerAPI,
|
||||
[ConfigKeys.AnthropicKey]: undefined,
|
||||
[ConfigKeys.AnthropicModelName]: AnthropicModelName.Haiku
|
||||
[GitAIConfigKey.ModelProvider]: ModelKind.OpenAI,
|
||||
[GitAIConfigKey.OpenAIKeyOption]: KeyOption.ButlerAPI,
|
||||
[GitAIConfigKey.OpenAIKey]: undefined,
|
||||
[GitAIConfigKey.OpenAIModelName]: OpenAIModelName.GPT35Turbo,
|
||||
[GitAIConfigKey.AnthropicKeyOption]: KeyOption.ButlerAPI,
|
||||
[GitAIConfigKey.AnthropicKey]: undefined,
|
||||
[GitAIConfigKey.AnthropicModelName]: AnthropicModelName.Haiku
|
||||
});
|
||||
|
||||
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 () => {
|
||||
const gitConfig = new DummyGitConfigService({
|
||||
...defaultGitConfig,
|
||||
[ConfigKeys.OpenAIKeyOption]: KeyOption.BringYourOwn,
|
||||
[ConfigKeys.OpenAIKey]: 'sk-asdfasdf'
|
||||
[GitAIConfigKey.OpenAIKeyOption]: KeyOption.BringYourOwn,
|
||||
[GitAIConfigKey.OpenAIKey]: 'sk-asdfasdf'
|
||||
});
|
||||
const aiService = new AIService(gitConfig, cloud);
|
||||
|
||||
@ -103,8 +103,8 @@ describe.concurrent('AIService', () => {
|
||||
const toastErrorSpy = vi.spyOn(toasts, 'error');
|
||||
const gitConfig = new DummyGitConfigService({
|
||||
...defaultGitConfig,
|
||||
[ConfigKeys.OpenAIKeyOption]: KeyOption.BringYourOwn,
|
||||
[ConfigKeys.OpenAIKey]: undefined
|
||||
[GitAIConfigKey.OpenAIKeyOption]: KeyOption.BringYourOwn,
|
||||
[GitAIConfigKey.OpenAIKey]: undefined
|
||||
});
|
||||
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 () => {
|
||||
const gitConfig = new DummyGitConfigService({
|
||||
...defaultGitConfig,
|
||||
[ConfigKeys.ModelProvider]: ModelKind.Anthropic,
|
||||
[ConfigKeys.AnthropicKeyOption]: KeyOption.BringYourOwn,
|
||||
[ConfigKeys.AnthropicKey]: 'sk-ant-api03-asdfasdf'
|
||||
[GitAIConfigKey.ModelProvider]: ModelKind.Anthropic,
|
||||
[GitAIConfigKey.AnthropicKeyOption]: KeyOption.BringYourOwn,
|
||||
[GitAIConfigKey.AnthropicKey]: 'sk-ant-api03-asdfasdf'
|
||||
});
|
||||
const aiService = new AIService(gitConfig, cloud);
|
||||
|
||||
@ -130,9 +130,9 @@ describe.concurrent('AIService', () => {
|
||||
const toastErrorSpy = vi.spyOn(toasts, 'error');
|
||||
const gitConfig = new DummyGitConfigService({
|
||||
...defaultGitConfig,
|
||||
[ConfigKeys.ModelProvider]: ModelKind.Anthropic,
|
||||
[ConfigKeys.AnthropicKeyOption]: KeyOption.BringYourOwn,
|
||||
[ConfigKeys.AnthropicKey]: undefined
|
||||
[GitAIConfigKey.ModelProvider]: ModelKind.Anthropic,
|
||||
[GitAIConfigKey.AnthropicKeyOption]: KeyOption.BringYourOwn,
|
||||
[GitAIConfigKey.AnthropicKey]: undefined
|
||||
});
|
||||
const aiService = new AIService(gitConfig, cloud);
|
||||
|
||||
|
@ -59,7 +59,7 @@ export enum AnthropicModelName {
|
||||
Haiku = 'claude-3-haiku-20240307'
|
||||
}
|
||||
|
||||
export enum ConfigKeys {
|
||||
export enum GitAIConfigKey {
|
||||
ModelProvider = 'gitbutler.aiModelProvider',
|
||||
OpenAIKeyOption = 'gitbutler.aiOpenAIKeyOption',
|
||||
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
|
||||
async buildClient(userToken?: string): Promise<undefined | AIClient> {
|
||||
const modelKind = await this.gitConfig.getWithDefault<ModelKind>(
|
||||
ConfigKeys.ModelProvider,
|
||||
GitAIConfigKey.ModelProvider,
|
||||
ModelKind.OpenAI
|
||||
);
|
||||
const openAIKeyOption = await this.gitConfig.getWithDefault<KeyOption>(
|
||||
ConfigKeys.OpenAIKeyOption,
|
||||
GitAIConfigKey.OpenAIKeyOption,
|
||||
KeyOption.ButlerAPI
|
||||
);
|
||||
const anthropicKeyOption = await this.gitConfig.getWithDefault<KeyOption>(
|
||||
ConfigKeys.AnthropicKeyOption,
|
||||
GitAIConfigKey.AnthropicKeyOption,
|
||||
KeyOption.ButlerAPI
|
||||
);
|
||||
|
||||
@ -119,10 +119,10 @@ export class AIService {
|
||||
|
||||
if (modelKind == ModelKind.OpenAI) {
|
||||
const openAIModelName = await this.gitConfig.getWithDefault<OpenAIModelName>(
|
||||
ConfigKeys.OpenAIModelName,
|
||||
GitAIConfigKey.OpenAIModelName,
|
||||
OpenAIModelName.GPT35Turbo
|
||||
);
|
||||
const openAIKey = await this.gitConfig.get(ConfigKeys.OpenAIKey);
|
||||
const openAIKey = await this.gitConfig.get(GitAIConfigKey.OpenAIKey);
|
||||
|
||||
if (!openAIKey) {
|
||||
toasts.error(
|
||||
@ -136,10 +136,10 @@ export class AIService {
|
||||
}
|
||||
if (modelKind == ModelKind.Anthropic) {
|
||||
const anthropicModelName = await this.gitConfig.getWithDefault<AnthropicModelName>(
|
||||
ConfigKeys.AnthropicModelName,
|
||||
GitAIConfigKey.AnthropicModelName,
|
||||
AnthropicModelName.Haiku
|
||||
);
|
||||
const anthropicKey = await this.gitConfig.get(ConfigKeys.AnthropicKey);
|
||||
const anthropicKey = await this.gitConfig.get(GitAIConfigKey.AnthropicKey);
|
||||
|
||||
if (!anthropicKey) {
|
||||
toasts.error(
|
||||
|
@ -4,7 +4,7 @@
|
||||
import TextBox from './TextBox.svelte';
|
||||
import {
|
||||
AnthropicModelName,
|
||||
ConfigKeys,
|
||||
GitAIConfigKey,
|
||||
KeyOption,
|
||||
ModelKind,
|
||||
OpenAIModelName
|
||||
@ -37,29 +37,29 @@
|
||||
|
||||
onMount(async () => {
|
||||
modelKind = await gitConfigService.getWithDefault<ModelKind>(
|
||||
ConfigKeys.ModelProvider,
|
||||
GitAIConfigKey.ModelProvider,
|
||||
ModelKind.OpenAI
|
||||
);
|
||||
|
||||
openAIKeyOption = await gitConfigService.getWithDefault<KeyOption>(
|
||||
ConfigKeys.OpenAIKeyOption,
|
||||
GitAIConfigKey.OpenAIKeyOption,
|
||||
KeyOption.ButlerAPI
|
||||
);
|
||||
openAIModelName = await gitConfigService.getWithDefault<OpenAIModelName>(
|
||||
ConfigKeys.OpenAIModelName,
|
||||
GitAIConfigKey.OpenAIModelName,
|
||||
OpenAIModelName.GPT35Turbo
|
||||
);
|
||||
openAIKey = await gitConfigService.get(ConfigKeys.OpenAIKey);
|
||||
openAIKey = await gitConfigService.get(GitAIConfigKey.OpenAIKey);
|
||||
|
||||
anthropicKeyOption = await gitConfigService.getWithDefault<KeyOption>(
|
||||
ConfigKeys.AnthropicKeyOption,
|
||||
GitAIConfigKey.AnthropicKeyOption,
|
||||
KeyOption.ButlerAPI
|
||||
);
|
||||
anthropicModelName = await gitConfigService.getWithDefault<AnthropicModelName>(
|
||||
ConfigKeys.AnthropicModelName,
|
||||
GitAIConfigKey.AnthropicModelName,
|
||||
AnthropicModelName.Haiku
|
||||
);
|
||||
anthropicKey = await gitConfigService.get(ConfigKeys.AnthropicKey);
|
||||
anthropicKey = await gitConfigService.get(GitAIConfigKey.AnthropicKey);
|
||||
});
|
||||
|
||||
$: if (form) form.modelKind.value = modelKind;
|
||||
|
Loading…
Reference in New Issue
Block a user