Transformation

Learn how to translate and summarize text and convert it to emojis using chat completions and its practical use cases.

Overview

The chat completions endpoint has the ability to translate from one language to another language, summarize the text, and convert the text to emojis or vice versa.

Press + to interact
Transformation
Transformation

We input the prompt text and request parameters into the OpenAI API’s model to transform the text.

Press + to interact
Completions: text transformation
Completions: text transformation

Translation

The OpenAI API can translate from one language to another language.

Let’s see how to provide the prompt to translate from English to other languages.

Translate this into 1. French, 2. Spanish and 3. Japanese.

We provide an online learning platform made by developers, created for developers.

Example

Let’s try the above example in the code widget below:

Press + to interact
Please provide values for the following:
SECRET_KEY
Not Specified...
// Define endpoint URL here
const endpointUrl = "https://api.openai.com/v1/chat/completions";
// Define Header Parameters here
const headerParameters = {
"Authorization": "Bearer {{SECRET_KEY}}",
"Content-Type": "application/json"
};
// Body Parameters
const bodyParameters = JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{role:"system",content:"Translate this into 1. French, 2. Spanish and 3. Japanese."},
{role:"user",content:"We provide an online learning platform made by developers, created for developers."}],
temperature: 0,
max_tokens: 100
});
// Setting API call options
const options = {
method: "POST",
headers: headerParameters,
body: bodyParameters
};
// Function to make API call
async function translate() {
try {
const response = await fetch(`${endpointUrl}`, options);
// Printing response
printResponse(response);
} catch (error) {
// Printing error message
printError(error);
}
}
// Calling function to make API call
translate();

In the code ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy