AiBrow
  • Welcome
  • AiBrow web API
    • Getting started
    • Feature comparison
  • AiBrow Extension
    • Getting started
    • Web polyfill
    • Helping users install the AiBrow extension
    • Remove the on-device helper or models
  • Examples
    • Embedding API
    • LanguageDetector API
    • LanguageModel API
    • Rewriter API
    • Summarizer API
    • Translator API
    • Writer API
    • Using different models
    • Model download feedback
    • Getting JSON output
  • API Reference
    • AI
      • AIBrow
      • BrowserAI
      • AIBrowWeb
    • AiBrow
      • Embedding
      • LanguageDetector
      • LanguageModel
      • Rewriter
      • Summarizer
      • Translator
      • Writer
    • Types
      • AIModelAvailability
      • AIModelCoreCompatibility
      • AIModelDtype
      • AIModelGpuEngine
      • AICreateMonitor
      • EmbeddingCreateOptions
      • LanguageDetectorCreateOptions
      • LanguageDetectorDetectResult
      • LanguageModelCreateOptions
      • RewriterCreateOptions
      • RewriterFormat
      • RewriterLength
      • RewriterTone
      • SummarizerCreateOptions
      • SummarizerFormat
      • SummarizerLength
      • SummarizerType
      • TranslatorCreateOptions
      • WriterCreateOptions
      • WriterFormat
      • WriterLength
      • WriterTone
    • Models
Powered by GitBook
On this page
  1. Examples

Translator API

PreviousSummarizer APINextWriter API

Last updated 12 days ago

The translation API allows you to rewrite some text in a different language

This API is compatible with the shipping with Google Chrome

Use the translation API to translate a block of text

import AI from '@aibrow/web'

const translator = await AI.AIBrow.Translator.create({
  sourceLanguage: 'en',
  targetLanguage: 'es'
});

// Prompt the model and wait for the whole result to come back.
const result = await translator.translate("If you don't build your dream, someone else will hire you to help them build theirs.");
console.log(result);

// Prompt the model and stream the result:
const stream = await translator.translateStreaming("If you don't build your dream, someone else will hire you to help them build theirs.");
for await (const chunk of stream) {
  console.log(chunk);
}
Translation API proposal