Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/add-mistral-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"lingo.dev": minor
"@lingo.dev/_compiler": minor
"@lingo.dev/_spec": minor
---

feat: add Mistral AI as a supported LLM provider

- Added Mistral AI provider support across the entire lingo.dev ecosystem
- Users can now use Mistral models for localization by setting MISTRAL_API_KEY
- Supports all Mistral models available through the @ai-sdk/mistral package
- Configuration via environment variable or user-wide config: `npx lingo.dev@latest config set llm.mistralApiKey <key>`
23 changes: 19 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ Here's how to get the project running locally:
- **Node.js**: Make sure you have Node.js version 18 or higher installed.
- **pnpm**: You can install using this command `npm install -g pnpm` or by following [this guide](https://pnpm.io/installation)
- **AI API Key**:
Currently, Groq and Google are supported.
Currently, Groq, Google, and Mistral are supported.
- **GROQ API Key**: You can get one by signing up at [Groq](https://console.groq.com/)
- **GOOGLE API Key**: You can get one in the [Google AI Studio](https://aistudio.google.com/apikey)
- **MISTRAL API Key**: You can get one by signing up at [Mistral AI](https://console.mistral.ai)

### Setup

Expand All @@ -36,7 +37,7 @@ Next, configure an AI API key. You can configure a key in two different ways:

**Option A: User-wide (Recommended for development):**

Run one of the following commands that corresponds with the AI provider you want to use in a terminal window. Replace `<your-api-key>` with your actual API key. You can configure Groq or Google.
Run one of the following commands that corresponds with the AI provider you want to use in a terminal window. Replace `<your-api-key>` with your actual API key. You can configure Groq, Google, or Mistral.

Groq:

Expand All @@ -50,6 +51,12 @@ Google:
npx lingo.dev@latest config set llm.googleApiKey <your-api-key>
```

Mistral:

```bash
npx lingo.dev@latest config set llm.mistralApiKey <your-api-key>
```

This will store the key in your system's user configuration, allowing you to build the project without needing to set it up in each demo directory.

**Option B: Project-wide (Alternative):**
Expand All @@ -73,9 +80,17 @@ echo "GOOGLE_API_KEY=<your-api-key>" > demo/next-app/.env
echo "GOOGLE_API_KEY=<your-api-key>" > demo/vite-project/.env
```

Mistral:

```bash
echo "MISTRAL_API_KEY=<your-api-key>" > demo/react-router-app/.env
echo "MISTRAL_API_KEY=<your-api-key>" > demo/next-app/.env
echo "MISTRAL_API_KEY=<your-api-key>" > demo/vite-project/.env
```

This will create `.env` files in each demo directory with your AI API key set as an environment variable.

_Note:_ When loading LLM API keys (including Groq and Google), the Lingo.dev Compiler checks the following sources in order of priority:
_Note:_ When loading LLM API keys (including Groq, Google, and Mistral), the Lingo.dev Compiler checks the following sources in order of priority:

1. Environment variables (via `process.env`)
2. Environment files (`.env`, `.env.local`, `.env.development`)
Expand Down Expand Up @@ -132,7 +147,7 @@ Want to add support for a new LLM provider to Lingo.dev? Here's a checklist to h
- Update documentation and this contributing guide as needed.

**Tip:**
Look at how existing providers like "groq" and "google" are implemented for reference. Consistency helps us maintain quality and predictability!
Look at how existing providers like "groq", "google", and "mistral" are implemented for reference. Consistency helps us maintain quality and predictability!

## Issues

Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"dependencies": {
"@ai-sdk/anthropic": "^1.2.11",
"@ai-sdk/google": "^1.2.19",
"@ai-sdk/mistral": "^1.2.8",
"@ai-sdk/openai": "^1.3.22",
"@babel/generator": "^7.27.1",
"@babel/parser": "^7.27.1",
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/cli/localizer/explicit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createAnthropic } from "@ai-sdk/anthropic";
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { createOpenAI } from "@ai-sdk/openai";
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { createMistral } from "@ai-sdk/mistral";
import { I18nConfig } from "@lingo.dev/_spec";
import chalk from "chalk";
import dedent from "dedent";
Expand Down Expand Up @@ -73,6 +74,15 @@ export default function createExplicitLocalizer(
prompt: provider.prompt,
skipAuth: true,
});
case "mistral":
return createAiSdkLocalizer({
factory: (params) =>
createMistral(params).languageModel(provider.model),
id: provider.id,
prompt: provider.prompt,
apiKeyName: "MISTRAL_API_KEY",
baseUrl: provider.baseUrl,
});
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/cli/processor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { colors } from "../constants";
import { createAnthropic } from "@ai-sdk/anthropic";
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { createMistral } from "@ai-sdk/mistral";
import { createOllama } from "ollama-ai-provider";

export default function createProcessor(
Expand Down Expand Up @@ -113,6 +114,17 @@ function getPureModelProvider(provider: I18nConfig["provider"]) {
// No API key check needed for Ollama
return createOllama()(provider.model);
}
case "mistral": {
if (!process.env.MISTRAL_API_KEY) {
throw new Error(
createMissingKeyErrorMessage("Mistral", "MISTRAL_API_KEY"),
);
}
return createMistral({
apiKey: process.env.MISTRAL_API_KEY,
baseURL: provider.baseUrl,
})(provider.model);
}
default: {
throw new Error(createUnsupportedProviderErrorMessage(provider?.id));
}
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/cli/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function getSettings(explicitApiKey: string | undefined): CliSettings {
googleApiKey: env.GOOGLE_API_KEY || systemFile.llm?.googleApiKey,
openrouterApiKey:
env.OPENROUTER_API_KEY || systemFile.llm?.openrouterApiKey,
mistralApiKey: env.MISTRAL_API_KEY || systemFile.llm?.mistralApiKey,
},
};
}
Expand Down Expand Up @@ -73,6 +74,7 @@ const SettingsSchema = Z.object({
groqApiKey: Z.string().optional(),
googleApiKey: Z.string().optional(),
openrouterApiKey: Z.string().optional(),
mistralApiKey: Z.string().optional(),
}),
});

Expand Down Expand Up @@ -103,6 +105,7 @@ function _loadEnv() {
GROQ_API_KEY: Z.string().optional(),
GOOGLE_API_KEY: Z.string().optional(),
OPENROUTER_API_KEY: Z.string().optional(),
MISTRAL_API_KEY: Z.string().optional(),
})
.passthrough()
.parse(process.env);
Expand All @@ -127,6 +130,7 @@ function _loadSystemFile() {
groqApiKey: Z.string().optional(),
googleApiKey: Z.string().optional(),
openrouterApiKey: Z.string().optional(),
mistralApiKey: Z.string().optional(),
}).optional(),
})
.passthrough()
Expand Down Expand Up @@ -203,6 +207,12 @@ function _envVarsInfo() {
`ℹ️ Using OPENROUTER_API_KEY env var instead of key from user config`,
);
}
if (env.MISTRAL_API_KEY && systemFile.llm?.mistralApiKey) {
console.info(
"\x1b[36m%s\x1b[0m",
`ℹ️ Using MISTRAL_API_KEY env var instead of key from user config`,
);
}
if (env.LINGODOTDEV_API_URL) {
console.info(
"\x1b[36m%s\x1b[0m",
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"dependencies": {
"@ai-sdk/google": "^1.2.19",
"@ai-sdk/groq": "^1.2.3",
"@ai-sdk/mistral": "^1.2.8",
"@babel/generator": "^7.26.5",
"@babel/parser": "^7.26.7",
"@babel/traverse": "^7.27.4",
Expand Down
6 changes: 6 additions & 0 deletions packages/compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
getGroqKeyFromRc,
getGoogleKeyFromEnv,
getGoogleKeyFromRc,
getMistralKeyFromEnv,
getMistralKeyFromRc,
getLingoDotDevKeyFromEnv,
getLingoDotDevKeyFromRc,
} from "./utils/llm-api-key";
Expand All @@ -34,6 +36,10 @@ const keyCheckers: Record<
checkEnv: getGoogleKeyFromEnv,
checkRc: getGoogleKeyFromRc,
},
mistral: {
checkEnv: getMistralKeyFromEnv,
checkRc: getMistralKeyFromRc,
},
"lingo.dev": {
checkEnv: getLingoDotDevKeyFromEnv,
checkRc: getLingoDotDevKeyFromRc,
Expand Down
25 changes: 24 additions & 1 deletion packages/compiler/src/lib/lcp/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createGroq } from "@ai-sdk/groq";
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { createOllama } from "ollama-ai-provider";
import { createMistral } from "@ai-sdk/mistral";
import { generateText } from "ai";
import { LingoDotDevEngine } from "@lingo.dev/_sdk";
import { DictionarySchema } from "../schema";
Expand All @@ -17,6 +18,8 @@ import {
getGoogleKeyFromEnv,
getOpenRouterKey,
getOpenRouterKeyFromEnv,
getMistralKey,
getMistralKeyFromEnv,
getLingoDotDevKeyFromEnv,
getLingoDotDevKey,
} from "../../../utils/llm-api-key";
Expand Down Expand Up @@ -353,9 +356,29 @@ export class LCPAPI {
return createOllama()(modelId);
}

case "mistral": {
// Specific check for CI/CD or Docker missing Mistral key
if (isRunningInCIOrDocker()) {
const mistralFromEnv = getMistralKeyFromEnv();
if (!mistralFromEnv) {
this._failMissingLLMKeyCi(providerId);
}
}
const mistralKey = getMistralKey();
if (!mistralKey) {
throw new Error(
"⚠️ Mistral API key not found. Please set MISTRAL_API_KEY environment variable or configure it user-wide.",
);
}
console.log(
`Creating Mistral client for ${targetLocale} using model ${modelId}`,
);
return createMistral({ apiKey: mistralKey })(modelId);
}

default: {
throw new Error(
`⚠️ Provider "${providerId}" for locale "${targetLocale}" is not supported. Only "groq" and "google" providers are supported at the moment.`,
`⚠️ Provider "${providerId}" for locale "${targetLocale}" is not supported. Only "groq", "google", "openrouter", "ollama", and "mistral" providers are supported at the moment.`,
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/compiler/src/lib/lcp/api/provider-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ export const providerDetails: Record<
getKeyLink: "https://ollama.com/download",
docsLink: "https://github.com/ollama/ollama/tree/main/docs",
},
mistral: {
name: "Mistral",
apiKeyEnvVar: "MISTRAL_API_KEY",
apiKeyConfigKey: "llm.mistralApiKey",
getKeyLink: "https://console.mistral.ai",
docsLink: "https://docs.mistral.ai",
},
};
12 changes: 12 additions & 0 deletions packages/compiler/src/utils/llm-api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ export function getOpenRouterKeyFromRc() {
export function getOpenRouterKeyFromEnv() {
return getKeyFromEnv("OPENROUTER_API_KEY");
}

export function getMistralKey() {
return getMistralKeyFromEnv() || getMistralKeyFromRc();
}

export function getMistralKeyFromRc() {
return getKeyFromRc("llm.mistralApiKey");
}

export function getMistralKeyFromEnv() {
return getKeyFromEnv("MISTRAL_API_KEY");
}
9 changes: 8 additions & 1 deletion packages/spec/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,14 @@ export const configV1_4Definition = extendConfigDefinition(
// v1.4 -> v1.5
// Changes: add "provider" field to the config
const providerSchema = Z.object({
id: Z.enum(["openai", "anthropic", "google", "ollama", "openrouter"]),
id: Z.enum([
"openai",
"anthropic",
"google",
"ollama",
"openrouter",
"mistral",
]),
model: Z.string(),
prompt: Z.string(),
baseUrl: Z.string().optional(),
Expand Down
22 changes: 20 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.