llm-translate
v1.0.9
Published
Translate text using LLM APIs.
Downloads
35
Maintainers
Readme
LLM Translate
Translate text using an LLM API.
Supported LLM APIs
Installation
npm install llm-translate
# or
yarn add llm-translate
Usage
import { OpenAITranslator } from 'llm-translate';
const translator = new OpenAITranslator({
apiKey: '',
})
const text = 'Send';
const sourceLanguage = 'en';
const targetLanguage = 'es';
const options = {
context: 'This is a button in a user interface.',
}
const openaiOptions = {
model: 'gpt-4',
temperature: 0.3,
}
translator.translate(text, sourceLanguage, targetLanguage, options, openaiOptions)
.then((translation) => {
console.log(translation);
})
.catch((error) => {
console.error(error);
});
Supported Languages
All ISO 639-1 language codes can be passed into the LLM. The quality of translations will be lower for languages that are less common on the internet.
LLM Performance
The GPT-4 MMLU case study from OpenAI is a good example of relative performance you might expect. The image below shows the performance on a complex test, the MMLU. As you can see, less common languages will have lower performance than more common languages.
(This is not an image of translation performance. The translation performance will be higher than this.)