Skip to content

railsstudent/nodejs-gemini-translation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nodejs-gemini-translation

Use Vertex AI to call Gemini 1.5 Pro latest model to perform translation

Authenticate Google Cloud Credential for local development

gcloud auth application-default login

Create environment file

  • Copy .env.example to .env
  • Update GOOGLE_PROJECT_ID to Google Cloud Project
  • Update GOOGLE_LOCATION to Google Cloud Project
  • Update GOOGLE_MODEL to a model found in Vertex AI Model Garden

Add sample strings to perform translation

Add texts to sample array

const samples = [
    'Good morning',
    'Hello, how are you today?',
    'How much does 3 apples and 4 oranges cost?'
]

and the results are

[
    {
        "en": "Good morning",
        "es": "Buenos Dias"
    },
    {
        "en": "Hello, how are you today?",
        "es": "Hola, ¿cómo estás hoy?"
    },
    {
        "en": "How much does 3 apples and 4 oranges cost?",
        "es": "¿Cuánto cuestan tres manzanas, cinco piñas y cuatro naranjas?"
    }
]

Update target language code

Change the TARGET environment variable in the "start script" of package.json

    "scripts": {
        "start": "TARGET=<target language code> node -r ts-node/register --env-file=.env index.ts"
    }

Run the application

pnpm start

Revoke Authenticate Google Cloud Credential

gcloud auth application-default revoke

Resources

About

Use Vertex AI to call Gemini 1.5 Pro latest model to perform translation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
close