Skip to main content

OpenAI

Overview

Use the OpenAI integration to generate text or code based on a text prompt you provide it. Provide AI capabilities to end-users or leverage it within APIs to enrich your Superblocks APIs. Some examples include flagging fraudulent activities based on customer transaction history, suggesting potential fixes to customer issue tickets for support reps, or generating product descriptions for e-commerce products based on a text prompt.

Use OpenAI API to generate SQL queries from user input

Setting up OpenAI

1. Select OpenAI from the in-app Integrations page

2. Fill out the form with the following configuration:

  • Name - Name that will be displayed to users when selecting this integration in Superblocks
  • API Key - API key for your OpenAI account
  • Organization ID - Specify which organization should be used for requests

3. Click "Create Integration"

Connect your Superblocks account to the OpenAI API

4. Set environments

After creating the integration, you can optionally set different connection settings for your Production and Staging environments.

success

OpenAI Connected You can now send requests to the OpenAI API to leverage AI in any Application, Workflow, or Scheduled Job.

Creating OpenAI steps

Connect to your OpenAI integration from Superblocks by creating steps in Application APIs, Workflows and Scheduled Jobs. You can configure a Superblocks OpenAI integration to generate code by sending a prompt. In the Advanced Tuning Parameters section, select which AI Model to use when generating the response and the Max Tokens to be returned.

Use OpenAI API to generate python scripts

In the above example, the following prompt produces the Python script below.

Prompt:
Generate a python script that iterates through a list of dictionary and prints each key's value

Python script output:

mylistofdicts = [
{"name": "John", "age": 23},
{"name": "Betty", "age": 27},
{"name": "Casey", "age": 35}
]

for dictionary in mylistofdicts:
for key, value in dictionary.items():
print("{}: {}".format(key, value))

Actions

Generate ChatGPT Response

Given a prompt, the model will return a chat completion response.

FieldDescription
PromptThe user input or question used to prompt the OpenAI API to generate a response
Message HistoryPrevious conversation history between the user and OpenAI. This enables users to reference prior messages in their prompt
Advanced Tuning Parameters:
FieldDescription
AI ModelThe AI Model to use when generating responses
Max Tokens (optional)Maximum number of tokens (words or symbols) the generated response can contain
System Instruction (optional)Specific instruction to set the intended behavior of the AI language model, such as “Be a helpful assistant”, “Speak as F500 CEO”, “Make responses funny”

Generate Text

Given a prompt, the model will return a text completion response.

FieldDescription
TypeNew Text (Given a prompt, the model will return a predicted text completion.) or Edit Text (Given text, the model will edit the text based on the prompt.)
PromptThe text or question describing the text to generate or edit
Text to EditThe original text that requires editing. Used as the basis for generating a revised version of the text
Advanced Tuning Parameters:
FieldDescription
AI ModelThe AI Model to use when generating responses
Max Tokens (optional)Maximum number of tokens (words or symbols) the generated response can contain

Generate Code

Given a prompt or code, the model will return a code completion response.

FieldDescription
TypeNew Code (Given a prompt, the model will return code completion.) or Edit Code (Given a code snippet, the model will edit the code based on the prompt.)
PromptThe text or question describing the code to generate or edit
Code to EditThe original code that requires editing. Used as the basis for generating a revised version of the code
Advanced Tuning Parameters:
FieldDescription
AI ModelThe AI Model to use when generating responses
Max Tokens (optional)Maximum number of tokens (words or symbols) the generated response can contain

Generate Image

Given a prompt or image, the model will return a new image.

Generate from Prompt

Given a prompt, the model will generate a new image.

FieldDescription
PromptA text description of the desired image. The maximum length is 1000 characters
Image SizeThe size of the generated images, options are: 256x256, 512x512, or 1024x1024
Edit Image

Given an original image and a prompt, the model will create an edited or extended image.

FieldDescription
PromptA text description of the desired image. The maximum length is 1000 characters
Image File to EditThe image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask. Image URLs are not supported
Image Mask (optional)An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image
Generated Image SizeThe size of the generated images, options are: 256x256, 512x512, or 1024x1024
Vary Image

Given an original image, the model will create a variation of the image.

FieldDescription
Image FileThe image to use as the basis for the variation. Must be a valid PNG file, less than 4MB, and square. Image URLs are not supported
Image SizeThe size of the generated images, options are: 256x256, 512x512, or 1024x1024

Check Moderation

Given text, the model will check for hate, hate/threatening, self-harm, sexual, sexual/minors, violence, or violence/graphic content.

FieldDescription
TextThe text to run a moderation check on.
Advanced Tuning Parameters:
FieldDescription
AI ModelThe AI Model to use when generating responses

Transcribe Audio to Text

Given an audio file, convert to text.

FieldDescription
Audio FileThe audio file to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm
Translate to EnglishTranslates the input audio to English
Input LanguageThe language the input audio is in
Advanced Tuning Parameters:
FieldDescription
AI ModelThe AI Model to use when generating responses

Generate Text Embedding

Given text, will generate a vector representation of the text that can be consumed by ML models and algorithms.

FieldDescription
InputInput text to get embeddings for. Must not exceed 8,192 tokens
Advanced Tuning Parameters:
FieldDescription
AI ModelThe AI Model to use when generating responses

Troubleshooting

The OpenAI Integration is failing with a 500 response
A 500 response usually indicates that the OpenAI API is down or unreachable. Check OpenAI’s status page to check availability.

The OpenAI Integration is failing with a 429 response
This usually indicates that you’re hitting a quota or rate limit for your API Key. Learn more about OpenAI’s rate limits and quotas and best practices for mitigating errors.

FAQ

I set my Max Tokens to 100. Why didn’t I get 100 words back?
The Max Tokens is based on the number of tokens returned by the model. This is roughly equivalent to words but not one to one.

Which model should I use?
If you’re trying to simulate ChatGPT like behavior, you’ll want to use the text-davinci-003 model (default). For code generation, consider changing to the code-davinci-002 model. Davinci models have been trained on a robust data set up to June 2021. Because these models have been trained on a large corpus, they can sometimes take several seconds to respond. For faster and cheaper models, consider other OpenAI models.

How do I get an API key?
To get an API key to use the OpenAI integration, create an OpenAI account and go to the API Key page to generate a new API key.