I'm trying to update this repo
https://github.com/vercel/ai-chatbot
hosted at
https://home-liart-chi.vercel.app/
to assistants model
https://platform.openai.com/docs/assistants/overview
using
https://github.com/vercel/ai-chatbot
but I'm unfamiliar with SDKS, in general.
Right now the A.I is called in actions.tsx as shown below; we want to change it to the new asistants beta v2 without messing with the ui, which is good as is.
import 'server-only'
import {
createAI,
getMutableAIState,
getAIState,
streamUI,
createStreamableValue
} from 'ai/rsc'
import { openai } from '@ai-sdk/openai'
import {BotCard, BotMessage,} from '@/components/stocks'
import { Events } from '@/components/stocks/events'
import {nanoid} from '@/lib/utils'
import { saveChat } from '@/app/actions'
import { SpinnerMessage, UserMessage } from '@/components/stocks/message'
import { Chat, Message } from '@/lib/types'
import { auth } from '@/auth'
//...
let textStream: undefined | ReturnType<typeof createStreamableValue<string>>
let textNode: undefined | React.ReactNode
const thread = await streamUI({
model: openai('gpt-4-turbo'),
initial: <SpinnerMessage />,
messages: [
...aiState.get().messages.map((message: any) => ({
role: message.role,
content: message.content,
name: message.name
}))
],
text: ({ content, done, delta }) => {
if (!textStream) {
textStream = createStreamableValue('')
textNode = <BotMessage content={textStream.value} />
}
if (done) {
textStream.done()
aiState.done({
...aiState.get(),
messages: [
...aiState.get().messages,
{
id: nanoid(),
role: 'assistant',
content
}
]
})
} else {
textStream.update(delta)
}
return textNode
},
})