llm-translate

1.0.8 • Public • Published

LLM Translate

NPM version

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.)

OpenAI Language Performance

Package Sidebar

Install

npm i llm-translate

Weekly Downloads

5

Version

1.0.8

License

MIT

Unpacked Size

201 kB

Total Files

8

Last publish

Collaborators

  • camnapoli