How to Generate AI Text in Gravity Forms with GC OpenAI

From dynamic replies to auto-written social posts, see how you can summon AI-generated text effortlessly, right from Gravity Forms.

  1. Install and Activate GC OpenAI
  2. Generate Text via Feed
    1. Step 1 — Create a GC OpenAI Feed
    2. Step 2 — Set Up Feed Endpoint
    3. Step 3 — Engineer Your Prompt
    4. Step 4 — Finish Feed Setup
  3. Generate Text via Field
    1. Step 1 — Add OpenAI Stream Field
    2. Step 2 — Set Up Field Endpoint
    3. Step 3 — Engineer Your Prompt
    4. Step 4 — Finish Field Setup
  4. Test your prompt

Generating text with OpenAI in Gravity Forms carries its weight in gold—you can build your own AI-powered tools supported by the robust and adaptable structure Gravity Forms provides. With Gravity Connect: OpenAI, you can connect the dots without writing code while still having prompt engineering tools to craft flexible and secure prompts with ease.

If you’re looking for inspiration, here are a few examples of what our customers have been building (and most of these were with the free version — GC OpenAI can do even more!):

Let me show you how to set it up. 🧙‍♂️🤖

Install and Activate GC OpenAI

GC OpenAI is part of Gravity Connect and easy to get started with—just install it through Spellbook and hook it up to your OpenAI API. 🪄

Once you’re done, you can choose to generate text via a feed or a field, or both!

  • Feed: Generates text after submission and outputs it in the entry meta or in a field. It can receive one prompt per feed (but you can have multiple feeds).
  • Field: Generates text in real time in the form. It’s able to generate responses to multiple prompts in a single form session.

Due to the evolving nature of AI, this article will rely on links to the Gravity Connect: OpenAI documentation for explanations like:

  • “What are Assistants?”
  • “Which models can I use?”
  • And other technical explanations.

Both the documentation and this article will be kept up to date with GC OpenAI updates. If you’d like to be notified, subscribe to our enchanting weekly newsletter. And if you have any questions, we’re here to help.

Generate Text via Feed

Step 1 — Create a GC OpenAI Feed

Head to the form you want to use to generate text. In the Settings menu, click on OpenAI to get to the GC OpenAI feeds screen. From there, click on Add.

Step 2 — Set Up Feed Endpoint

You can use either the Chat Completions or Assistants endpoint. In the endpoint settings, choose the model you want for Chat Completions, or select one of your Assistants for the Assistants endpoint.

Showing GC OpenAI feed settings for choosing the Chat Completions endpoint and models.

Step 3 — Engineer Your Prompt

Onto the fun part: use text, images, merge tags, and message roles to engineer your prompt inside of GC OpenAI’s modular Messages setting. You can add, remove, and reorder these messages—magical!

New to prompt engineering? It serves to both tell and show the AI exactly what you’re looking for. Read more on prompt engineering in our docs, where we go more in depth about message roles and what content better fits each role.

Engineering a prompt to be sent to OpenAI through GC OpenAI's feed.

Step 4 — Finish Feed Setup

There are a few optional configurations left. You can:

  • Choose to Map Result to Field, which will attach the generated response to the field of your choosing. 
  • Process the feed asynchronously. Good for quick submissions, not recommended if your other feeds, confirmations, or notifications depend on the OpenAI response. Read more.
  • Use conditional logic to only run a feed when certain criteria are met. This is useful for controlling when a prompt should actually be sent to OpenAI, or for having multiple feeds in the same form that run conditionally.
  • Tweak the advanced settings for more granular control over the OpenAI response and token usage.

Generate Text via Field

Step 1 — Add OpenAI Stream Field

Head to the form you want to use to generate text and add an OpenAI Stream field.

Step 2 — Set Up Field Endpoint

In the field settings, you’ve got two endpoint options for the OpenAI Stream field: Chat Completions or Assistants. You can use the Chat Completions endpoint to select a model directly, or the Assistants endpoint to choose from one of your existing Assistants.

Showing the GC OpenAI field settings for endpoint and model selection.

Step 3 — Engineer Your Prompt

Now for the good stuff: use Messages to engineer your prompt with merge tags and message roles. Add, remove, and reorder messages as needed.

New to prompt engineering? It serves to both tell and show the AI exactly what you’re looking for. Read more on prompt engineering in our docs, where we go more in depth about message roles and what content better fits each role.

Engineering a prompt to be sent to OpenAI through GC OpenAI's stream field settings.

Step 4 — Finish Field Setup

Choose the Trigger Method, aka when the text should be generated.

  • Form Load: Response is generated right as the user opens the form.
  • Button: The field loads with a “Generate” button, and a response is only generated once the user clicks it.
  • Merge Tag Value Change: This option is available if you’re using merge tags in your prompt. A response will be generated every time a merge tag value changes.

Then, you can choose to:

  • Allow regeneration: When enabled, a “Regenerate” button is available under the response to allow the user to generate a new response—be it because they changed one of their field inputs or because they didn’t like the first response they got.
  • Automatically scroll to bottom of output: When enabled, GC OpenAI will take the user to the bottom of the response.

Test your prompt

That’s it for the setup! Time to see it in action:

Showing demos of GC OpenAI's feed outputting after a form is submitted, and of GC OpenAI's stream field generating text in the form itself.

Before letting your new AI creation loose, read our quick documentation section on prompt injection mitigation. It will touch on what prompt injection is and what you can do to protect your forms against users trying to exploit an inherent AI vulnerability.

If you have any questions, let us know in the comments below. We can’t wait to see what you’ll create! 🧙‍♂️

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.


Grab a bundle of free Gravity Forms plugins

Enter your email and receive our most popular free plugins and snippets, plus access to hundreds of others.

This field is for validation purposes and should be left unchanged.