I’m building a feature for my app that integrates the OpenAI API, and I’m looking for some advice.
I’ve got two things working separately: one is a chatbot that I can have conversations with (streaming responses), and the other is a structured output feature that generates formatted content I can interact with in the UI (built with Next.js).
What I’m struggling with is how to combine them. The idea is that if the AI needs more info before generating the structured output, it should start a dialogue with the user to ask for those details. Once it has enough, it would generate the output.
Is this where I’d use something like an “assistant” approach, with the structured output being a function that the AI can call once it has what it needs? And is it mostly about designing the right prompts for that back-and-forth interaction?
I know this might be a basic question, but any pointers would be appreciated. Just trying to figure out the best way to approach this.
1 Like
Hi, welcome back.
Yessir, you’ll definitely want to use multiple Assistants for this flow.
What I gather from this is that you’re using the chat completions endpoint for two different conversations?
There’s no way to have them talk to each other. Alternatively, Multiple Assistants can all work on the same Thread. So, I suggest:
- Start by creating multiple Assistants, each trained for your various different tasks.
- Assistant 1 has function calling enabled. Based on the user prompt, this Assistant asks for more details, or can also call other Assistants to go grab data for the user and put it in the thread. This is where you’ll want your correct prompting for the interaction.
- Any number of “middleman” Assistants can be made to go grab the context you want. Assistant 1 calls them via Function Calling triggered by Keywords in the User Prompt.
- Critique Assistant looks over the information to make sure it’s complete, or sends it back through for more.
- Final Assistant simply uses Structured Output and response_format to put the final data in the next.js format you want.
1 Like