vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
9.37k stars 1.37k forks source link

Using a schema with useChat #2771

Open janwirth opened 3 weeks ago

janwirth commented 3 weeks ago

Feature Description

Adding a schema option to useChat should allow me to render chat messages other than string.

Use Case

I would like to enrich our chat interface with custom UI like chatbot buttons.

Additional context

No response

mishushakov commented 3 weeks ago

I agree, want a mix between chat response and structured

janwirth commented 3 weeks ago

I found a solution, happy to share when it's tested. my discord is jannibeu

mishushakov commented 3 weeks ago

My current workaround is adding a "commentary" field for outputting LLM thought process.

janwirth commented 3 weeks ago

I'm injecting a zod schema and a prompt to communicate in JSON, then I put the current streamed result through jsonrepair, then zod.

lgrammel commented 3 weeks ago

Would tools work for you?

janwirth commented 3 weeks ago

I tried to get tools to work but really couldn't.

I think I see now how they could be used but yeah I wasn't smart enough. We have something we like now.

janwirth commented 3 weeks ago

For me, it was too difficult to control when a tool would be called