Skip to main content

Retool AI text actions

Learn how to generate and analyze text with Retool AI.

You can use the Retool AI resource to write queries that leverage AI models to generate and analyze text content. You can provide text directly in the query, reference existing data from elsewhere (for example, another query), or use data stored in Retool Vectors.

As with all queries, the response is available at {{ query.data }}. If you reference the query data in a component, such as a Text Area component, Retool streams the response so it appears in real time.

Add an AI Action

To get started with Text actions for apps, add a new AI Action query. For workflows, add a new AI Action block.

  1. Open the Code panel.
  2. Click + to add a new query.
  3. Select AI Action.

The Retool AI text actions are: Generate text, Summarize text, Classify text, and Extract entity from text.

For all text actions, the Fx button next to the Model field allows you to dynamically select different AI models within your apps or workflows. Refer to the Dynamic AI model selection section for more information.

Generate text

Use the Generate text action to generate text content based on the instructions you provide.

  1. Select the Generate text action.
  2. Enter some instructions in the Input field.
  3. Select the AI model to use (for example, GPT-4).
  4. Click Save and then Run to perform the action.

The specified AI model then generates the requested text.

Include context from Retool Vectors

You can include related information from Retool Vectors to provide more context. This allows you to instruct AI models to use your own data when making decisions, such as responding to a customer with context from support articles.

If you don't yet have any vector data, follow the tutorial to get started.

To include context from a specific Vector, check Use Retool Vectors to provide more context to your query. You can then select a vector to reference. When enabled, Retool identifies relevant content and includes it in the request.

Dynamic AI model selection

Combine the Fx button with an Option list in a Select component to change the AI model dynamically.

  1. Create a new Generate text query.
  2. Open the Components panel and drag a Select component onto the canvas.
  3. In the Inspector, select Mapped.
  4. Set the Data source to the query.
  5. Switch the Mode to Manual and click on the Option labels to edit them.
  6. In your query, select the Fx button next to the Model field and copy the model string.
  7. Paste the string into the Value field of the Edit option box.
  8. Add a Label
  9. Repeat Steps 6-8 as needed for additional AI model options.
  10. Change the Model value in your query to {{ select1.value }}
  11. Click Save.
  12. Choose one of the AI model options from the Select component dropdown list.
  13. Run the query.

The model listed in the Output metadata should match the Model selected from the dropdown.

Summarize text

Use the Summarize text action to generate a summary of the provided text.

  1. Select the Summarize text action.
  2. Enter a passage of text in the Input field.
  3. Select the AI model to use (for example, GPT-4).
  4. Click Save and then Run to perform the action.

The specified AI model then generates a summary of the provided text.

Classify text

Use the Classify text action to analyze text and categorize it with one of the specified labels. The AI model determines what each label should be for and decides which label most appropriately reflects the text. This is useful for performing customer support or sentiment analysis.

  1. Select the Classify text action.
  2. Enter a passage of text in the Input field.
  3. Specify the Classification labels to use.
  4. Select the AI model to use (for example, GPT-4).

{{ query.data }} contains a category property with a value that corresponds to the chosen label.

Extract entity from text

The Extract entity from text action analyzes the input text and identifies information based on the specified entities.

  1. Select the Extract entity from text action.
  2. Enter a passage of text in the Input field.
  3. Specify the Entities to extract (for example, product name or address).
  4. Select the AI model to use (for example, GPT-4).

{{ query.data }} contains an array of key-value pairs for each entity the AI model has identified.