vercel / ai-chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
https://chat.vercel.ai
Other
5.51k stars 1.62k forks source link

How to handle multistep toll call with streamUI? #357

Closed pavlogolovatyy closed 1 week ago

pavlogolovatyy commented 1 month ago

Something like in the docs of AI SDK RSC:

User: What's the status of my wife's upcoming flight? Function: lookupContacts() -> ["John Doe", "Jane Doe"] Function: lookupBooking("Jane Doe") -> "BA123 confirmed" Function: lookupFlight("BA123") -> "Flight BA123 is scheduled to depart on 12th December." Model: Your wife's flight BA123 is confirmed and scheduled to depart on 12th December.

Before refreshing the chat, only the last UI will be visible: lookupFlight.

How to handle all functions return without refreshing the page?

athrael-soju commented 1 month ago

This should be able to do something similar, but maybe outdated: https://github.com/vercel-labs/gemini-chatbot

iosifnicolae2 commented 1 month ago

I'm also interested in a solution to be able to implement chain of thoughts using AI SDK.

pavlogolovatyy commented 1 month ago

It seems like the issue might stem from the following lines of code in prompt-form.tsx:

const [_, setMessages] = useUIState<typeof AI>()

const responseMessage = await submitUserMessage(value)
setMessages(currentMessages => [...currentMessages, responseMessage])

The submitUserMessage function is returning a single message. Additionally, during refresh, the messages are being fetched from AIState.

intoxopox commented 1 month ago

@pavlogolovatyy Curious to see if you found a better way.

athrael-soju commented 1 month ago

The Completions API has a single output. You may want to look into the assistants API

JokeJason commented 1 week ago

AI SDK 3.2 has new feature that maybe helpful