
OpenAI Trigger
Table of Contents
Overview
The OpenAI Trigger (listed under API Triggers in the main menu) can be used to initiate an action based on incoming information from OpenAI. Using this trigger, you can specify what kind of incoming information is to be used as a trigger, such as text-based, image or audio-based, via selection of one of the different Model Types listed.
NOTE: For this option to be available, you have to first list your API Key under in the Settings tab.

Selecting this option will lead to the following parameters being displayed:

Model Types Available
Using the Model Type drop-down, the following options are available:
| Model Type | Description |
|---|---|
ChatGPT | Incoming text-based responses from OpenAI |
Image Generation | Incoming image-based responses |
Generate Audio | Incoming audio-based responses |
ChatGPT Model Type
With ChatGPT selected, the trigger fires each time a text response from OpenAI arrives. Two fields control what happens to that response:
| Option | Description |
|---|---|
Append result to chat history | When checked, the response is added as a new row to the linked data frame, with the role assistant in the first column and the response text in the second. |
Chat History Dataframe | Appears when Append result to chat history is checked. Links the data frame variable that holds the conversation. |
In the example below, the data frame that was assigned is called ‘df’ and the result from the ‘OpenAI Trigger’ will be appended to this data frame. This data frame needs to have two columns. The first column will denote the ‘role’ and the second column the ‘chat message.’ The values from the action will be automatically appended to the data frame that is linked here.

NOTE 1: If you are also using the ‘Send to OpenAI’ action, then you need to utilize the same data frame there as you have indicated here.
NOTE 2: Also refer to this walkthrough where we build a study step-by-step, integrating ChatGPT for a text-to-text-based study with a chat and utilizing these trigger options.
Image Generation - Model Type
With this option, you can indicate a generated image to be saved and also specify in which Variable it should be saved in.
| Option | Description |
|---|---|
Save Generated Image | When checked, the generated image is uploaded and stored in a variable. The image is saved in webp format. |
Image File Variable | Appears when Save Generated Image is checked. Links the variable that stores the image. It must be a File variable with a single (scalar) value. |

NOTE: When assigning and creating the particular variable here, remember to indicate the variable type as File, in order for the image file to be stored in there.

Useful Demo: Check out this demo that makes use of image generation via the OpenAI Trigger and action. The participant is asked to input a prompt and this prompt is then used to generate an image.
Generate Audio - Model Type
With this option, you can indicate a generated audio file to be saved and also specify in which Variable it should be saved in.
| Option | Description |
|---|---|
Save Generated Audio File | When checked, the generated audio is uploaded and stored in a variable. The audio is saved in mp3 format. |
Audio File Variable | Appears when Save Generated Audio File is checked. Links the variable that stores the audio. It must be a File variable with a single (scalar) value. |
Note: A generated file larger than 100 MB is not uploaded.

NOTE: When assigning and creating the particular variable here, remember to choose the variable type as File, in order for the audio file to be stored in there.

Trigger-Specific Values for OpenAI
Once the trigger fires, the following values are available in the Value-Select Menu for use in actions.
| Value | Description |
|---|---|
Chat GPT Answer | The text of the response from ChatGPT. Filled when Model Type is ChatGPT, empty for image and audio responses. |
Generated File | The generated image or audio file. Filled when Model Type is Image Generation or Generate Audio, empty for ChatGPT responses. |
File Prompt | The prompt that was used to generate the file. Filled for image and audio responses, empty for ChatGPT responses. |
Trigger Timestamp (Unixtime) | The timestamp of when the OpenAI trigger occurred, in Unix time with milliseconds. |
Trigger Time (From Frame Onset) | The elapsed time in milliseconds from the frame onset to when the OpenAI trigger occurred. |