Search⌘ K
AI Features

Transformation

Explore how to leverage OpenAI's completions endpoint to perform text transformations including translating between languages, summarizing lengthy text, and converting text into emojis. Gain practical skills in designing prompts and adjusting parameters to create effective NLP solutions using Python.

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.

Transformation
Transformation

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

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:

Python
#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 ...