#Attempting to integrate assistants model + file upload into Vercel.

1 messages · Page 1 of 1 (latest)

granite grotto
#

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
    },
  })
GitHub

A full-featured, hackable Next.js AI chatbot built by Vercel - vercel/ai-chatbot

An AI-powered chatbot template built with Next.js and Vercel.

inland flameBOT
#

Hi @granite grotto. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To integrate the new OpenAI Assistants beta v2 into your existing Vercel project, you'll need to modify the API calls in your code to use the new version.

Based on the information provided in the knowledge sources, you can access the beta versions by passing the right API version header in your API requests. For v2, you would use OpenAI-Beta: assistants=v2.

Here's an example of how to make a request to the v2 API using curl:

curl "<https://api.openai.com/v1/assistants"> \
 -H "Content-Type: application/json" \
 -H "Authorization: Bearer $OPENAI_API_KEY" \
 -H "OpenAI-Beta: assistants=v2" \
 -d '{
 "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
 "name": "Math Tutor",
 "tools": [{"type": "code_interpreter"}],
 "model": "gpt-4-turbo"
 }'

In your case, you would need to modify the model: openai('gpt-4-turbo') line in your streamUI function call to use the new API version and pass the appropriate headers.

However, it's important to note that the exact way to do this will depend on the specifics of the openai function and the @ai-sdk/openai library you're using. You might need to update the library to a newer version that supports the v2 API, as mentioned in one of the forum posts in the knowledge sources.

If you're unfamiliar with SDKs in general, you might find it helpful to review the OpenAI SDK documentation (https://github.com/openai/openai-cookbook/blob/main/examples/How_to_use_the_OpenAI_API_with_python.md) or seek help from the OpenAI community or the Vercel support team.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: