|
|
@@ -35,7 +35,7 @@ export class MistralHandler implements ApiHandler {
|
|
|
}
|
|
|
|
|
|
private getBaseUrl(): string {
|
|
|
- const modelId = this.options.apiModelId
|
|
|
+ const modelId = this.options.apiModelId ?? mistralDefaultModelId
|
|
|
if (modelId?.startsWith("codestral-")) {
|
|
|
return this.options.mistralCodestralUrl || "https://codestral.mistral.ai"
|
|
|
}
|
|
|
@@ -86,4 +86,25 @@ export class MistralHandler implements ApiHandler {
|
|
|
info: mistralModels[mistralDefaultModelId],
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ async completePrompt(prompt: string): Promise<string> {
|
|
|
+ try {
|
|
|
+ const response = await this.client.chat.complete({
|
|
|
+ model: this.options.apiModelId || mistralDefaultModelId,
|
|
|
+ messages: [{ role: "user", content: prompt }],
|
|
|
+ temperature: this.options.modelTemperature ?? MISTRAL_DEFAULT_TEMPERATURE,
|
|
|
+ })
|
|
|
+
|
|
|
+ const content = response.choices?.[0]?.message.content
|
|
|
+ if (Array.isArray(content)) {
|
|
|
+ return content.map((c) => (c.type === "text" ? c.text : "")).join("")
|
|
|
+ }
|
|
|
+ return content || ""
|
|
|
+ } catch (error) {
|
|
|
+ if (error instanceof Error) {
|
|
|
+ throw new Error(`Mistral completion error: ${error.message}`)
|
|
|
+ }
|
|
|
+ throw error
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|