Transformation
Learn how to translate and summarize text and convert it to emojis using chat completions and its practical use cases.
We'll cover the following...
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
We input the prompt text and request parameters into the OpenAI API’s model to transform the text.
Press + to interact
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
SECRET_KEY
Not Specified...
// Define endpoint URL hereconst endpointUrl = "https://api.openai.com/v1/chat/completions";// Define Header Parameters hereconst headerParameters = {"Authorization": "Bearer {{SECRET_KEY}}","Content-Type": "application/json"};// Body Parametersconst 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 optionsconst options = {method: "POST",headers: headerParameters,body: bodyParameters};// Function to make API callasync function translate() {try {const response = await fetch(`${endpointUrl}`, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API calltranslate();
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