Răsfoiți Sursa

Merge pull request #999 from d-oit/mistral

Mistral
Matt Rubens 10 luni în urmă
părinte
comite
7eada8bb6d

+ 22 - 1
src/api/providers/mistral.ts

@@ -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
+		}
+	}
 }

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

@@ -314,7 +314,6 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage, fromWelcomeView }: A
 						placeholder="Enter API Key...">
 						<span style={{ fontWeight: 500 }}>Mistral API Key</span>
 					</VSCodeTextField>
-
 					<p
 						style={{
 							fontSize: "12px",
@@ -335,7 +334,8 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage, fromWelcomeView }: A
 						)}
 					</p>
 
-					{apiConfiguration?.apiModelId?.startsWith("codestral-") && (
+					{(apiConfiguration?.apiModelId?.startsWith("codestral-") ||
+						(!apiConfiguration?.apiModelId && mistralDefaultModelId.startsWith("codestral-"))) && (
 						<div>
 							<VSCodeTextField
 								value={apiConfiguration?.mistralCodestralUrl || ""}