Groq
AI translation with Groq and Lingo.dev Compiler
What is Groq?
Groq is a company that designs high-performance AI hardware and software optimized for ultra-low latency inference. Its solutions aim to accelerate AI workloads in areas like large language models and real-time analytics by leveraging its custom Tensor Streaming Processor architecture.
Setting the API Key
Groq requires an API key to authenticate requests from Lingo.dev Compiler. Choose the setup method that best fits your workflow:
Option 1: Environment Variable (Terminal)
Best for quick experiments and testing without modifying any files.
Set the key directly in your terminal session:
export GROQ_API_KEY="your-api-key-here"
This key will only be available until you close your terminal window.
Option 2: Project Configuration (.env)
Best for project-specific configuration and team environments where each project may use different credentials.
Create a .env
file in your project root:
touch .env
Add the following line to the file:
GROQ_API_KEY="your-api-key-here"
Lingo.dev Compiler checks for environment files in this priority order:
.env.development
(highest priority).env.local
.env
(lowest priority)
Values in higher-priority files override those in lower-priority files.
Option 3: Global Configuration (User Settings)
Best for individual developers who want to use the same API key across all their projects.
Create a configuration file in your home directory:
touch ~/.lingodotdevrc
Add the following content to the file:
[llm]
groqApiKey="your-api-key-here"
This configuration persists across all terminal sessions and projects on your machine.
Configuration Priority
When multiple configuration methods are used, Lingo.dev Compiler checks for API keys in this order:
- Environment variables (highest priority)
- Project .env files (in their own priority order)
- User configuration file
~/.lingodotdevrc
(lowest priority)
The first valid API key that's found is used.
Using Groq
To enable Groq, set the models
property in the compiler options:
import react from "@vitejs/plugin-react";
import lingoCompiler from "lingo.dev/compiler";
import { type UserConfig } from "vite";
// https://vite.dev/config/
const viteConfig: UserConfig = {
plugins: [react()],
};
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja"],
rsc: false,
useDirective: false,
debug: false,
models: {
"*:*": "groq:llama-3.1-8b-instant",
},
});
export default withLingo(viteConfig);
The property accepts an object where:
- the keys are pairs of source and target locales, with
*
representing any locale - the values are model identifiers (e.g.,
groq:llama-3.1-8b-instant
)
You can use Groq to translate:
- between all locales
- from a specific source locale
- to a specific target locale
- between a specific source and target locale
Translating all locales
Use the wildcard pattern *:*
to apply the same Groq model for all translation pairs:
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja", "pt", "zh"],
models: {
// Use Llama 3.1 8B for all translation pairs
"*:*": "groq:llama-3.1-8b-instant",
},
});
Translating from a specific source locale
Use a specific source locale with wildcard target to apply a model for all translations from that source:
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja", "pt", "zh"],
models: {
// Use Llama 3.1 70B for all translations from English
"en:*": "groq:llama-3.1-70b-versatile",
// Use Mixtral for translations from Spanish to any language
"es:*": "groq:mixtral-8x7b-32768",
// Fallback for other source languages
"*:*": "groq:llama-3.1-8b-instant",
},
});
Translating to a specific target locale
Use a wildcard source with specific target locale to apply a model for all translations to that target:
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja", "pt", "zh"],
models: {
// Use specialized model for translations to Japanese
"*:ja": "groq:llama-3.1-70b-versatile",
// Use Mixtral for translations to Chinese
"*:zh": "groq:mixtral-8x7b-32768",
// Use Gemma 2 for translations to German
"*:de": "groq:gemma2-9b-it",
// Default for other target languages
"*:*": "groq:llama-3.1-8b-instant",
},
});
Translating between specific locales
Define exact source-target pairs for fine-grained control over which model handles specific language combinations:
const withLingo = lingoCompiler.vite({
sourceRoot: "src",
lingoDir: "lingo",
sourceLocale: "en",
targetLocales: ["es", "fr", "de", "ja", "pt", "zh"],
models: {
// Specific pairs with optimal models
"en:es": "groq:llama-3.1-70b-versatile", // English to Spanish
"en:ja": "groq:llama-3.1-70b-versatile", // English to Japanese
"en:zh": "groq:mixtral-8x7b-32768", // English to Chinese
"es:en": "groq:llama-3.1-8b-instant", // Spanish to English
"fr:en": "groq:gemma2-9b-it", // French to English
"de:en": "groq:gemma2-9b-it", // German to English
// Fallback for unspecified pairs
"*:*": "groq:llama-3.1-8b-instant",
},
});