DEV Community

Cover image for OpenAI Assistants with Structured Outputs
Joseph Petty for Appsmith

Posted on

1

OpenAI Assistants with Structured Outputs

OpenAI recently added support to their API for structured outputs, which allow you to define the response format using JSON Schema. Prior to this, the JSON response mode was able to reply with JSON, but there was no way to enforce a specific structure, define enum values, and specify required or optional fields. But with Structured Outputs, you can define every detail about the response, to ensure the data is ready to be passed on to your database or workflow.

In this guide, I'll be using OpenAI's Structured Outputs to analyze customer reviews for a hotel chain. The reviews only contain the rating (1-5), and the review text. The Structured Output feature will be used to add new datapoints for sentiment (positive, neutral, negative), offensiveContent (true/false), and tags (cleanliness, service, staff, etc).

This guide will cover:

  • Creating an OpenAI API key and saving it to an Appsmith datasource
  • Using the Chat /completions API
  • Building a UI to select and send reviews to the assistant
  • Defining a JSON Schema for the response

YOUTUBE: OpenAI Assistants with Structured Outputs

Written tutorial

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)