useAssistant()

Allows you to handle the client state when interacting with an OpenAI compatible assistant API. This hook is useful when you want to integrate assistant capabilities into your application, with the UI updated automatically as the assistant is streaming its execution.

This works in conjunction with AssistantResponse in the backend.

Import

import { useAssistant } from '@ai-sdk/react'

API Signature

Parameters

api:

string

threadId?:

string | undefined

credentials?:

'omit' | 'same-origin' | 'include' = 'same-origin'

headers?:

Record<string, string> | Headers

body?:

any

onError?:

(error: Error) => void

fetch?:

FetchFunction

Returns

messages:

Message[]

setMessages:

React.Dispatch<React.SetStateAction<Message>>

threadId:

string | undefined

setThreadId:

(threadId: string | undefined) => void

input:

string

setInput:

React.Dispatch<React.SetStateAction<string>>

handleInputChange:

(event: any) => void

submitMessage:

(event?: { preventDefault?: () => void }) => void

status:

'awaiting_message' | 'in_progress'

append:

(message: Message | CreateMessage, chatRequestOptions: { options: { headers, body } }) => Promise<string | undefined>

stop:

() => void

error:

undefined | Error