Skip to content

Commit b4cf697

Browse files
committed
feat: Add completePrompt method to MistralHandler for chat completions
1 parent 8842497 commit b4cf697

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/api/providers/mistral.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

0 commit comments

Comments
 (0)