Translation & AI Providers
Relevant source files
The following files were used as context for generating this wiki page:
The Translation & AI Provider system is a core component of Read Frog, powering its immersive translation and advanced AI-driven reading analysis features. It provides a flexible and extensible architecture for integrating various third-party services. The system supports a wide range of providers, from simple translation APIs to powerful Large Language Models (LLMs), and allows users to configure and switch between them easily.
This modular design enables users to choose providers based on their needs, such as cost, performance, or privacy. The system distinguishes between services for "translation" and "reading," allowing for separate provider configurations for each function. It also supports custom, OpenAI-compatible providers, offering significant flexibility.
Sources: README.md:52-53, src/locales/en.yml:30-34
Provider Configuration
Provider settings are stored in the main application configuration under the providersConfig key. This is an array of objects, where each object represents a single configured provider.
Sources: src/utils/config/tests/example/v022.ts:10-91
Configuration Schema
The following diagram illustrates the structure of a provider configuration object. Each provider has a unique id, a user-defined name, a provider type identifier, and optional credentials like apiKey and baseURL. LLM-based providers also include a models object to specify which model to use for read and translate tasks.
Provider Object Properties
The table below details the fields for each provider object within the providersConfig array.
| Field | Type | Description |
|---|---|---|
id | string | A unique identifier for the provider instance. |
name | string | A user-friendly name for the provider, displayed in the UI. |
provider | string | The built-in provider type (e.g., openai, google, deepseek). |
enabled | boolean | A flag to enable or disable the provider. |
apiKey | string (optional) | The API key for authentication with the service. |
baseURL | string (optional) | The base URL for the API endpoint. Useful for proxies or self-hosted models. |
models | object (optional) | Configuration for LLM providers, specifying models for read and translate tasks. |
Sources: src/utils/config/tests/example/v022.ts:10-91, src/types/config/provider.ts
An example of a providersConfig array:
"providersConfig": [
{
"name": "Google Translate",
"provider": "google"
},
{
"name": "OpenAI",
"provider": "openai",
"apiKey": "sk-1234567890",
"baseURL": "https://api.openai.com/v1",
"models": {
"read": {
"model": "gpt-4o-mini",
"isCustomModel": true,
"customModel": "gpt-4.1-nano"
},
"translate": {
"model": "gpt-4o-mini",
"isCustomModel": false,
"customModel": ""
}
}
}
]
Sources: src/utils/config/tests/example/v022.ts:10-49
Provider Categories
Providers are organized into three categories in the options UI, reflecting their capabilities and configuration methods.
Sources: src/locales/en.yml:42-50
- Pure Translation Providers: Services focused exclusively on translation, without LLM capabilities for advanced reading analysis.
- Examples: Google Translate, Microsoft Translator, DeepLX.
- Built-in LLM Providers: A curated list of popular LLM providers with pre-configured settings, simplifying setup. Users typically only need to provide an API key.
- Examples: OpenAI, DeepSeek, Gemini, Anthropic.
- OpenAI Compatible Custom Providers: Allows users to configure any provider that adheres to the OpenAI API specification. This requires manually entering the
name,apiKey, andbaseURL.- Example: Zhipu AI.
Sources: src/locales/en.yml:42-50
Built-in Providers
The extension includes support for over 20 built-in providers, each with a brief description in the UI to guide the user's choice.
| Provider | Description |
|---|---|
openai | Provides models like GPT-4o. |
deepseek | Recommended for use in China. |
openrouter | Unified interface for multiple LLM providers with pay-per-use pricing. |
ollama | Run large language models locally on your machine for complete privacy. |
gemini | Google's flagship AI models with advanced reasoning capabilities. |
anthropic | Claude models known for safety and reasoning excellence. |
deeplx | Unofficial DeepL API. |
groq | Specialized hardware for ultra-fast LLM inference speeds. |
mistral | European AI company specializing in efficient multilingual models. |
cohere | Enterprise-focused AI with strong multilingual and RAG capabilities. |
Sources: src/locales/en.yml:68-91
Model Configuration and Selection
For LLM providers, users can select specific models for different tasks. The configuration separates model choice for the "Read" feature and the "Translate" feature.
Sources: src/utils/config/tests/example/v022.ts:27-37
Task-Specific Models
Within a provider's configuration, the models object contains two keys:
read: Defines the model used for advanced functions like article analysis and summarization.translate: Defines the model used for webpage translation.
This allows users to, for example, use a more powerful (and expensive) model for in-depth analysis and a faster, cheaper model for simple translations.
Sources: src/locales/en.yml:60-67, src/utils/config/tests/example/v022.ts:27-37
Custom Models
The system allows the use of models not included in the default dropdown lists.
isCustomModel(boolean): When set totrue, the extension will use the model name specified incustomModel.customModel(string): The name of the custom model to be used.
// Example of using a custom model for the 'read' task
{
// ...
"models": {
"read": {
"model": "gpt-4o-mini", // A fallback or default UI selection
"isCustomModel": true,
"customModel": "gpt-4.1-nano" // The actual model to be used
},
// ...
}
}
Sources: src/utils/config/tests/example/v022.ts:28-32
Provider Usage Flow
The application logic retrieves the appropriate provider and model based on the user's configuration for a given task.
AI Smart Context Example
The "AI Smart Context" feature demonstrates a typical LLM provider workflow. It generates a summary of an article to provide context for subsequent translations, improving their quality.
The following sequence diagram shows the process for generating an article summary.
This diagram shows how generateArticleSummary uses the provided providerConfig to get a model instance and then calls the Vercel AI SDK's generateText function to interact with the external API.
Sources: src/utils/content/summary.ts:1-41, src/utils/providers/model.ts
Provider Management UI
Users manage their providers through the "API Providers" page in the extension's options. This interface allows for adding, configuring, and deleting providers.
The UI is built with React and uses components to handle different aspects of provider management. Key features include:
- Add Provider Dialog: A modal that groups providers into the three categories (Built-in LLM, OpenAI Compatible, Pure Translation).
- Provider Form: A form for editing a provider's
name,apiKey,baseURL, and model selections. - Default Provider Selection: Users can set a provider as the default for "Read" or "Translate" functions.
- Test Connection: A button to validate the
apiKeyandbaseURLfor a given provider. - Deletion with Validation: The system prevents the user from deleting providers if it would leave them without at least one for reading and one for translation.
Sources: src/locales/en.yml:30-94, src/entrypoints/options/pages/api-providers/index.tsx
Conclusion
The Translation & AI Provider system is a cornerstone of Read Frog's functionality, offering a robust and user-configurable way to leverage a vast ecosystem of AI and translation services. Its separation of concerns between "read" and "translate" tasks, support for custom models, and an intuitive management UI make it a powerful tool for language learners. The architecture is designed for easy extension, allowing new providers to be integrated as the AI landscape evolves.