Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail type inference at createStreamableValue #1526

Closed
toy-crane opened this issue May 8, 2024 · 3 comments
Closed

fail type inference at createStreamableValue #1526

toy-crane opened this issue May 8, 2024 · 3 comments
Labels

Comments

@toy-crane
Copy link

toy-crane commented May 8, 2024

Description

follow this example at vercel AI example
https://sdk.vercel.ai/examples/next-app/basics/streaming-object-generation#server
createStreamableValue doesnt inferred although using stream.update(partialObject);

Code example

'use server';

import { streamObject } from 'ai';
import { openai } from '@ai-sdk/openai';
import { createStreamableValue } from 'ai/rsc';
import { z } from 'zod';

export async function generate(input: string) {
  'use server';

  const stream = createStreamableValue();

  (async () => {
    const { partialObjectStream } = await streamObject({
      model: openai('gpt-4-turbo'),
      system: 'You generate three notifications for a messages app.',
      prompt: input,
      schema: z.object({
        notifications: z.array(
          z.object({
            name: z.string().describe('Name of a fictional person.'),
            message: z.string().describe('Do not use emojis or links.'),
            minutesAgo: z.number(),
          }),
        ),
      }),
    });

    for await (const partialObject of partialObjectStream) {
      stream.update(partialObject);
    }

    stream.done();
  })();

  return { object: stream.value };
}

Additional context

how can I fix this problem?
are there anyone have same problem??

@lgrammel
Copy link
Collaborator

lgrammel commented May 8, 2024

Can you provide the full error message?

@toy-crane
Copy link
Author

(property) value: StreamableValue<any, any>
The value of the streamable. This can be returned from a Server Action and received by the client. To read the streamed values, use the readStreamableValue or useStreamableValue APIs.

there are no errors
The value is not just inferred instead of any.

@shuding
Copy link
Member

shuding commented May 14, 2024

Yeah createStreamableValue() can't infer its data type if data is set later with a .update() in a new clousure. I'm not sure if that's possible with TypeScript (example).

Only createStreamableValue<T>() and createStreamableValue(data) have the data type.

Let me know if you have other questions!

@shuding shuding closed this as completed May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants