Transformation

Learn how to translate and summarize text, and convert it to emojis using the OpenAI API.

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...
#Translating from english to other languages
from openai import OpenAI
client = OpenAI(api_key="{{SECRET_KEY}}")
response = client.chat.completions.create(
model="gpt-3.5-turbo",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": "Translate this into 1. French, 2. Spanish and 3. Japanese. Provide output in json"},
{"role": "user", "content": "We provide an online learning platform made by developers, created for developers."}
],
temperature=0,
max_tokens=130,
top_p=1.0,
)
print(response.choices[0].message.content)

In the code above, temperature is set to 0 because we don’t need randomness in the ...