Skip to content

Commit 95078a6

Browse files
committed
add mistral latest api models
1 parent 4497e42 commit 95078a6

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

src/api/providers/mistral.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,31 @@ export class MistralHandler implements ApiHandler {
2222

2323
constructor(options: ApiHandlerOptions) {
2424
this.options = options
25+
const baseUrl = this.getBaseUrl()
26+
console.log("MistralHandler: baseUrl", baseUrl)
2527
this.client = new Mistral({
26-
serverURL: "https://codestral.mistral.ai",
28+
serverURL: baseUrl,
2729
apiKey: this.options.mistralApiKey,
2830
})
2931
}
3032

33+
private getBaseUrl(): string {
34+
const modelId = this.options.apiModelId
35+
if (modelId?.startsWith("codestral-")) {
36+
return this.options.mistralCodestralUrl || "https://codestral.mistral.ai"
37+
}
38+
return "https://api.mistral.ai"
39+
}
40+
3141
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
32-
const stream = await this.client.chat.stream({
33-
model: this.getModel().id,
34-
// max_completion_tokens: this.getModel().info.maxTokens,
42+
const response = await this.client.chat.stream({
43+
model: this.options.apiModelId || mistralDefaultModelId,
44+
messages: convertToMistralMessages(messages),
45+
maxTokens: this.options.includeMaxTokens ? this.getModel().info.maxTokens : undefined,
3546
temperature: this.options.modelTemperature ?? MISTRAL_DEFAULT_TEMPERATURE,
36-
messages: [{ role: "system", content: systemPrompt }, ...convertToMistralMessages(messages)],
37-
stream: true,
3847
})
3948

40-
for await (const chunk of stream) {
49+
for await (const chunk of response) {
4150
const delta = chunk.data.choices[0]?.delta
4251
if (delta?.content) {
4352
let content: string = ""

src/shared/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface ApiHandlerOptions {
5252
geminiApiKey?: string
5353
openAiNativeApiKey?: string
5454
mistralApiKey?: string
55+
mistralCodestralUrl?: string // New option for Codestral URL
5556
azureApiVersion?: string
5657
openRouterUseMiddleOutTransform?: boolean
5758
openAiStreamingEnabled?: boolean

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage, fromWelcomeView }: A
314314
placeholder="Enter API Key...">
315315
<span style={{ fontWeight: 500 }}>Mistral API Key</span>
316316
</VSCodeTextField>
317+
317318
<p
318319
style={{
319320
fontSize: "12px",
@@ -323,15 +324,37 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage, fromWelcomeView }: A
323324
This key is stored locally and only used to make API requests from this extension.
324325
{!apiConfiguration?.mistralApiKey && (
325326
<VSCodeLink
326-
href="https://console.mistral.ai/codestral/"
327+
href="https://console.mistral.ai/"
327328
style={{
328329
display: "inline",
329330
fontSize: "inherit",
330331
}}>
331-
You can get a Mistral API key by signing up here.
332+
You can get a La Plateforme (api.mistral.ai) / Codestral (codestral.mistral.ai) API key
333+
by signing up here.
332334
</VSCodeLink>
333335
)}
334336
</p>
337+
338+
{apiConfiguration?.apiModelId?.startsWith("codestral-") && (
339+
<div>
340+
<VSCodeTextField
341+
value={apiConfiguration?.mistralCodestralUrl || ""}
342+
style={{ width: "100%", marginTop: "10px" }}
343+
type="url"
344+
onBlur={handleInputChange("mistralCodestralUrl")}
345+
placeholder="Default: https://codestral.mistral.ai">
346+
<span style={{ fontWeight: 500 }}>Codestral Base URL (Optional)</span>
347+
</VSCodeTextField>
348+
<p
349+
style={{
350+
fontSize: "12px",
351+
marginTop: 3,
352+
color: "var(--vscode-descriptionForeground)",
353+
}}>
354+
Set alternative URL for Codestral model: https://api.mistral.ai
355+
</p>
356+
</div>
357+
)}
335358
</div>
336359
)}
337360

0 commit comments

Comments
 (0)