From 95078a6bc9e530a367937f3934340ba1a29b928a Mon Sep 17 00:00:00 2001 From: "d.o.it" <6849456+d-oit@users.noreply.github.com> Date: Wed, 12 Feb 2025 15:04:02 +0100 Subject: [PATCH] add mistral latest api models --- src/api/providers/mistral.ts | 23 +++++++++++----- src/shared/api.ts | 1 + .../src/components/settings/ApiOptions.tsx | 27 +++++++++++++++++-- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/api/providers/mistral.ts b/src/api/providers/mistral.ts index 9ce70a297c..a70d21754a 100644 --- a/src/api/providers/mistral.ts +++ b/src/api/providers/mistral.ts @@ -22,22 +22,31 @@ export class MistralHandler implements ApiHandler { constructor(options: ApiHandlerOptions) { this.options = options + const baseUrl = this.getBaseUrl() + console.log("MistralHandler: baseUrl", baseUrl) this.client = new Mistral({ - serverURL: "https://codestral.mistral.ai", + serverURL: baseUrl, apiKey: this.options.mistralApiKey, }) } + private getBaseUrl(): string { + const modelId = this.options.apiModelId + if (modelId?.startsWith("codestral-")) { + return this.options.mistralCodestralUrl || "https://codestral.mistral.ai" + } + return "https://api.mistral.ai" + } + async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream { - const stream = await this.client.chat.stream({ - model: this.getModel().id, - // max_completion_tokens: this.getModel().info.maxTokens, + const response = await this.client.chat.stream({ + model: this.options.apiModelId || mistralDefaultModelId, + messages: convertToMistralMessages(messages), + maxTokens: this.options.includeMaxTokens ? this.getModel().info.maxTokens : undefined, temperature: this.options.modelTemperature ?? MISTRAL_DEFAULT_TEMPERATURE, - messages: [{ role: "system", content: systemPrompt }, ...convertToMistralMessages(messages)], - stream: true, }) - for await (const chunk of stream) { + for await (const chunk of response) { const delta = chunk.data.choices[0]?.delta if (delta?.content) { let content: string = "" diff --git a/src/shared/api.ts b/src/shared/api.ts index 3f1c65b1c2..5ad9df8dfa 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -52,6 +52,7 @@ export interface ApiHandlerOptions { geminiApiKey?: string openAiNativeApiKey?: string mistralApiKey?: string + mistralCodestralUrl?: string // New option for Codestral URL azureApiVersion?: string openRouterUseMiddleOutTransform?: boolean openAiStreamingEnabled?: boolean diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index 0d8bb43bb5..125c3d3785 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -314,6 +314,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage, fromWelcomeView }: A placeholder="Enter API Key..."> Mistral API Key +
- You can get a Mistral API key by signing up here. + You can get a La Plateforme (api.mistral.ai) / Codestral (codestral.mistral.ai) API key + by signing up here. )}
+ + {apiConfiguration?.apiModelId?.startsWith("codestral-") && ( ++ Set alternative URL for Codestral model: https://api.mistral.ai +
+