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

TypeError [ERR_INVALID_STATE]: Invalid state: The ReadableStream is locked #1493

Closed
97revenge opened this issue May 4, 2024 · 1 comment · Fixed by #1510
Closed

TypeError [ERR_INVALID_STATE]: Invalid state: The ReadableStream is locked #1493

97revenge opened this issue May 4, 2024 · 1 comment · Fixed by #1510
Assignees

Comments

@97revenge
Copy link

Description

All the code is based on the Vercel IA SDK documentation, I'm using the createGoogleGenerativeAI provider instance with my API key and everything is fine, but whenever I need a return on the client side with new StreamingTextResponse(result.toAIStream( )) return this error:
image
my AI response is not compromised but the available stream is locked...

Code example

import { StreamingTextResponse, streamText, StreamData } from "ai";

import { NextRequest } from "next/server";

import { createGoogleGenerativeAI } from "@ai-sdk/google";

export const dynamic = "force-dynamic";

export const POST = async (req: NextRequest) => {
  const data = await req.json();
 

  const google = createGoogleGenerativeAI({
    apiKey: process.env.GOOGLE_API_KEY!,
    // custom settings
  });

  const model = google("models/gemini-1.5-pro-latest");

  const result = await streamText({
    model,
    prompt: "Hello , you you doing? "
    seed: 5,
  });

  let message = "";

  for await (const item of result.textStream) {
    console.log(item);
    message = item;
  }

  if (!result) {
    console.log("error !!! ");
  }

  return new StreamingTextResponse(result.toAIStream());
};

Additional context

image

@lgrammel
Copy link
Collaborator

lgrammel commented May 8, 2024

Fixed in 3.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants