Skip to content

Instantly share code, notes, and snippets.

@greenido
Created March 20, 2023 18:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
An openai API example of using the DaVinci engine for language translation
const axios = require('axios');
const API_KEY = 'your_api_key_here';
const API_URL = 'https://api.openai.com/v1/';
async function translateText(text, targetLanguage) {
const response = await axios.post(`${API_URL}engines/davinci/translate`, {
text,
target_language: targetLanguage,
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
});
const translatedText = response.data.translations[0].text;
console.log(translatedText);
}
translateText('All the world is crazy', 'es');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment