Skip to content

Generate text with tool call result #1655

Closed Answered by Frollamma
Frollamma asked this question in Help
Discussion options

You must be logged in to vote

I was able to solve this using a streamUI inside a streamUI and updating the AI state (hopefully) in the right way. This is the relevant code:

async function submitUserMessage(text: string, images: ImageFile[] = [], files: File[] = []) {
  'use server'

  const session = await auth()

  // IMPR: you should check plans
  if (!session?.user?.id && (images.length > 0 || files.length > 0)) {
    throw new Error('You need to be authenticated to upload files')
  }

  const content = await parseContent(text, images, files)

  const aiState = getMutableAIState<typeof AI>()

  aiState.update({
    ...aiState.get(),
    messages: [
      ...aiState.get().messages,
      {
        id: nanoid(),

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@Frollamma
Comment options

@sagar803
Comment options

Answer selected by Frollamma
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants