Skip to main content
OpenAI logo

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.

Setting up OpenAI

1. Add integration

Select OpenAI from the in-app Integrations page.

2. Configure settings

Fill out the form with the following settings:

SettingRequiredDescription
NameTRUEName that will be displayed to users when selecting this integration in Superblocks
API KeyTRUEAPI key for your OpenAI account
Organization IDFALSESpecify which organization should be used for requests

3. Test and save

Click Test Connection to check that Superblocks can connect to the data source.

info

If using Superblocks Cloud, add these Superblocks IPs to your allowlist (not necessary for On-Premise-Agent).

4. Set profiles

Optionally, configure different profiles for separate development environments.

success

OpenAI connected Now you can use OpenAI 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

Use cases

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?

tip

If you’re trying to simulate ChatGPT like behavior or generate code, you’ll want to use the gpt-3.5-turbo or gpt-4 model.

info

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 language task / completion models.

List of available models per OpenAI Action:

Generate Code

  • gpt-3.5-turbo (default): Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with the latest OpenAI model iteration.
  • gpt-4: OpenAI's most advanced model. ChatGPT+ membership or GPT-4 beta enrollment is required for access

Generate ChatGPT Response

  • gpt-3.5-turbo (default): Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with our latest model iteration.
  • gpt-4: OpenAI's most advanced model. ChatGPT+ membership or GPT-4 beta enrollment is required for access

Generate Text

  • text-davinci-003 (default): Can do any language task with better quality, longer output, and consistent instruction-following than the curie, babbage, or ada models. Also supports inserting completions within text.
  • text-curie-001: Very capable, faster and lower cost than Davinci.
  • text-babbage-001: Capable of straightforward tasks, very fast, and lower cost.
  • text-ada-001: Capable of very simple tasks, usually the fastest model in the GPT-3 series, and lowest cost.

Check Moderation

  • text-moderation-latest (default): Most capable moderation model. Accuracy will be slightly higher than the stable model.
  • text-moderation-stable: Almost as capable as the latest model, but slightly older.

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.