Skip to content

Commit 7eada8b

Browse files
authored
Merge pull request RooCodeInc#999 from d-oit/mistral
Mistral
2 parents 6c371e1 + 0573643 commit 7eada8b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/api/providers/mistral.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class MistralHandler implements ApiHandler {
3535
}
3636

3737
private getBaseUrl(): string {
38-
const modelId = this.options.apiModelId
38+
const modelId = this.options.apiModelId ?? mistralDefaultModelId
3939
if (modelId?.startsWith("codestral-")) {
4040
return this.options.mistralCodestralUrl || "https://codestral.mistral.ai"
4141
}
@@ -86,4 +86,25 @@ export class MistralHandler implements ApiHandler {
8686
info: mistralModels[mistralDefaultModelId],
8787
}
8888
}
89+
90+
async completePrompt(prompt: string): Promise<string> {
91+
try {
92+
const response = await this.client.chat.complete({
93+
model: this.options.apiModelId || mistralDefaultModelId,
94+
messages: [{ role: "user", content: prompt }],
95+
temperature: this.options.modelTemperature ?? MISTRAL_DEFAULT_TEMPERATURE,
96+
})
97+
98+
const content = response.choices?.[0]?.message.content
99+
if (Array.isArray(content)) {
100+
return content.map((c) => (c.type === "text" ? c.text : "")).join("")
101+
}
102+
return content || ""
103+
} catch (error) {
104+
if (error instanceof Error) {
105+
throw new Error(`Mistral completion error: ${error.message}`)
106+
}
107+
throw error
108+
}
109+
}
89110
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage, fromWelcomeView }: A
314314
placeholder="Enter API Key...">
315315
<span style={{ fontWeight: 500 }}>Mistral API Key</span>
316316
</VSCodeTextField>
317-
318317
<p
319318
style={{
320319
fontSize: "12px",
@@ -335,7 +334,8 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage, fromWelcomeView }: A
335334
)}
336335
</p>
337336

338-
{apiConfiguration?.apiModelId?.startsWith("codestral-") && (
337+
{(apiConfiguration?.apiModelId?.startsWith("codestral-") ||
338+
(!apiConfiguration?.apiModelId && mistralDefaultModelId.startsWith("codestral-"))) && (
339339
<div>
340340
<VSCodeTextField
341341
value={apiConfiguration?.mistralCodestralUrl || ""}

0 commit comments

Comments
 (0)