mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-19 15:41:31 +03:00
Rename model to modelName
This commit is contained in:
parent
52427bbed8
commit
f50dd13844
@ -1,13 +1,13 @@
|
||||
import { type AIClient, type PromptMessage, MessageRole } from '$lib/backend/aiClient';
|
||||
import { fetch, Body } from '@tauri-apps/api/http';
|
||||
import type { AnthropicModel } from '$lib/backend/aiService';
|
||||
import type { AnthropicModelName } from '$lib/backend/aiService';
|
||||
|
||||
type AnthropicAPIResponse = { content: { text: string }[] };
|
||||
|
||||
export class AnthropicAIClient implements AIClient {
|
||||
constructor(
|
||||
private apiKey: string,
|
||||
private model: AnthropicModel
|
||||
private modelName: AnthropicModelName
|
||||
) {}
|
||||
|
||||
async evaluate(prompt: string) {
|
||||
@ -16,7 +16,7 @@ export class AnthropicAIClient implements AIClient {
|
||||
const body = Body.json({
|
||||
messages,
|
||||
max_tokens: 1024,
|
||||
model: this.model
|
||||
model: this.modelName
|
||||
});
|
||||
|
||||
const response = await fetch<AnthropicAPIResponse>('https://api.anthropic.com/v1/messages', {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { type AIClient, type PromptMessage, MessageRole } from '$lib/backend/aiClient';
|
||||
import type { OpenAIModel } from '$lib/backend/aiService';
|
||||
import type { OpenAIModelName } from '$lib/backend/aiService';
|
||||
import type OpenAI from 'openai';
|
||||
|
||||
export class OpenAIClient implements AIClient {
|
||||
constructor(
|
||||
private model: OpenAIModel,
|
||||
private modelName: OpenAIModelName,
|
||||
private openAI: OpenAI
|
||||
) {}
|
||||
|
||||
@ -15,7 +15,7 @@ export class OpenAIClient implements AIClient {
|
||||
// @ts-expect-error There is a type mismatch where it seems to want a "name" paramater
|
||||
// that isn't required https://github.com/openai/openai-openapi/issues/118#issuecomment-1847667988
|
||||
messages,
|
||||
model: this.model,
|
||||
model: this.modelName,
|
||||
max_tokens: 400
|
||||
});
|
||||
|
||||
|
@ -44,13 +44,13 @@ export enum KeyOption {
|
||||
ButlerAPI = 'butlerAPI'
|
||||
}
|
||||
|
||||
export enum OpenAIModel {
|
||||
export enum OpenAIModelName {
|
||||
GPT35Turbo = 'gpt-3.5-turbo',
|
||||
GPT4 = 'gpt-4',
|
||||
GPT4Turbo = 'gpt-4-turbo-preview'
|
||||
}
|
||||
|
||||
export enum AnthropicModel {
|
||||
export enum AnthropicModelName {
|
||||
Opus = 'claude-3-opus-20240229',
|
||||
Sonnet = 'claude-3-sonnet-20240229'
|
||||
}
|
||||
@ -95,8 +95,8 @@ export class AIService {
|
||||
|
||||
if (modelKind == ModelKind.OpenAI) {
|
||||
const openAIModelName =
|
||||
(await this.gitConfig.get<OpenAIModel>('gitbutler.aiOpenAIModelName')) ||
|
||||
OpenAIModel.GPT35Turbo;
|
||||
(await this.gitConfig.get<OpenAIModelName>('gitbutler.aiOpenAIModelName')) ||
|
||||
OpenAIModelName.GPT35Turbo;
|
||||
const openAIKey = await this.gitConfig.get('gitbutler.aiOpenAIKey');
|
||||
|
||||
// TODO: Provide feedback to user
|
||||
@ -107,8 +107,8 @@ export class AIService {
|
||||
}
|
||||
if (modelKind == ModelKind.Anthropic) {
|
||||
const anthropicModelName =
|
||||
(await this.gitConfig.get<AnthropicModel>('gitbutler.aiAnthropicModelName')) ||
|
||||
AnthropicModel.Sonnet;
|
||||
(await this.gitConfig.get<AnthropicModelName>('gitbutler.aiAnthropicModelName')) ||
|
||||
AnthropicModelName.Sonnet;
|
||||
const anthropicKey = await this.gitConfig.get('gitbutler.aiAnthropicKey');
|
||||
|
||||
// TODO: Provide feedback to user
|
||||
|
@ -2,7 +2,12 @@
|
||||
import Select from './Select.svelte';
|
||||
import SelectItem from './SelectItem.svelte';
|
||||
import TextBox from './TextBox.svelte';
|
||||
import { AnthropicModel, KeyOption, ModelKind, OpenAIModel } from '$lib/backend/aiService';
|
||||
import {
|
||||
AnthropicModelName,
|
||||
KeyOption,
|
||||
ModelKind,
|
||||
OpenAIModelName
|
||||
} from '$lib/backend/aiService';
|
||||
import { GIT_CONFING_CONTEXT, GitConfig } from '$lib/backend/gitConfig';
|
||||
import RadioButton from '$lib/components/RadioButton.svelte';
|
||||
import SectionCard from '$lib/components/SectionCard.svelte';
|
||||
@ -18,11 +23,11 @@
|
||||
$: gitConfig.set('gitbutler.aiAnthropicKeyOption', anthropicKeyOption);
|
||||
let openAIKey: string | undefined;
|
||||
$: if (openAIKey) gitConfig.set('gitbutler.aiOpenAIKey', openAIKey);
|
||||
let openAIModelName: OpenAIModel;
|
||||
let openAIModelName: OpenAIModelName;
|
||||
$: gitConfig.set('gitbutler.aiOpenAIModelName', openAIModelName);
|
||||
let anthropicKey: string | undefined;
|
||||
$: if (anthropicKey) gitConfig.set('gitbutler.aiAnthropicKey', anthropicKey);
|
||||
let anthropicModelName: AnthropicModel;
|
||||
let anthropicModelName: AnthropicModelName;
|
||||
$: gitConfig.set('gitbutler.aiAnthropicModelName', anthropicModelName);
|
||||
|
||||
onMount(async () => {
|
||||
@ -32,11 +37,12 @@
|
||||
anthropicKeyOption =
|
||||
(await gitConfig.get<KeyOption>('gitbutler.aiAnthropicKeyOption')) || KeyOption.ButlerAPI;
|
||||
openAIModelName =
|
||||
(await gitConfig.get<OpenAIModel>('gitbutler.aiOpenAIModelName')) || OpenAIModel.GPT35Turbo;
|
||||
(await gitConfig.get<OpenAIModelName>('gitbutler.aiOpenAIModelName')) ||
|
||||
OpenAIModelName.GPT35Turbo;
|
||||
openAIKey = (await gitConfig.get('gitbutler.aiOpenAIKey')) || undefined;
|
||||
anthropicModelName =
|
||||
(await gitConfig.get<AnthropicModel>('gitbutler.aiAnthropicModelName')) ||
|
||||
AnthropicModel.Sonnet;
|
||||
(await gitConfig.get<AnthropicModelName>('gitbutler.aiAnthropicModelName')) ||
|
||||
AnthropicModelName.Sonnet;
|
||||
anthropicKey = (await gitConfig.get('gitbutler.aiAnthropicKey')) || undefined;
|
||||
});
|
||||
|
||||
@ -56,26 +62,26 @@
|
||||
const openAIModelOptions = [
|
||||
{
|
||||
name: 'GPT 3.5 Turbo',
|
||||
value: OpenAIModel.GPT35Turbo
|
||||
value: OpenAIModelName.GPT35Turbo
|
||||
},
|
||||
{
|
||||
name: 'GPT 4',
|
||||
value: OpenAIModel.GPT4
|
||||
value: OpenAIModelName.GPT4
|
||||
},
|
||||
{
|
||||
name: 'GPT 4 Turbo',
|
||||
value: OpenAIModel.GPT4Turbo
|
||||
value: OpenAIModelName.GPT4Turbo
|
||||
}
|
||||
];
|
||||
|
||||
const anthropicModelOptions = [
|
||||
{
|
||||
name: 'Sonnet',
|
||||
value: AnthropicModel.Sonnet
|
||||
value: AnthropicModelName.Sonnet
|
||||
},
|
||||
{
|
||||
name: 'Opus',
|
||||
value: AnthropicModel.Opus
|
||||
value: AnthropicModelName.Opus
|
||||
}
|
||||
];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user