vercel / ai

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

Unable to access some of the return values from `streamUI()` #2161

Closed ashersamuel8 closed 2 months ago

ashersamuel8 commented 4 months ago

Description

Unable to access some of the return values from the returned object of streamUI. I am only being able to access rawCall, rawResponse, stream, value, and warnings. I'm unable to access values like textStream, fullStream, usage, etc. I am using google's gemini-flash as the model. This code is in actions.tsx and I am using next@14.2.4 and ai@3.2.16.

Code example

  const result = await streamUI({
    model: google("models/gemini-1.5-flash-latest"),
    messages: [
      ...aiState.get().messages.map((message: any) => ({
        role: message.role,
        content: message.content,
        name: message.name,
      })),
    ],
  })

Additional context

No response

lgrammel commented 4 months ago

@ashersamuel8 with streamUI, you can use parameters to define callbacks, see https://sdk.vercel.ai/docs/ai-sdk-rsc/streaming-react-components#adding-a-tool

Saran33 commented 2 months ago

@lgrammel the docs suggest that these methods are returned in the result, similarly to streamText, but that doesn't appear the case. Looking through the commit history, it doesn't seem to have ever been the case in previous releases either. https://sdk.vercel.ai/docs/reference/ai-sdk-rsc/stream-ui#returns

  const result = await streamUI({
    model: google("models/gemini-1.5-flash-latest"),
    messages: [
      ...aiState.get().messages.map((message: any) => ({
        role: message.role,
        content: message.content,
        name: message.name,
      })),
    ],
  })
  // `fullStream` etc is not returned as the docs suggest
  const { value, fullStream } = result

The result resolves to:

{
    value: ReactNode;
} & {
    stream: ReadableStream<LanguageModelV1StreamPart>;
    rawCall: {
        rawPrompt: unknown;
        rawSettings: Record<string, unknown>;
    };
    rawResponse?: {
        headers?: Record<string, string>;
    };
    warnings?: LanguageModelV1CallWarning[];
}
lgrammel commented 2 months ago

@Saran33 this information is incorrect. I'll update the docs. thank you

lgrammel commented 2 months ago

Docs fix: https://github.com/vercel/ai/pull/2871