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

Vercel AI SDK Streaming Response Stuck in Loop #4141

Open
troycampano opened this issue Dec 18, 2024 · 0 comments
Open

Vercel AI SDK Streaming Response Stuck in Loop #4141

troycampano opened this issue Dec 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@troycampano
Copy link

troycampano commented Dec 18, 2024

Description

When attempting to use the Vercel AI SDK for the first time, with a very specific prompt, the response seems to get stuck in a loop. When using the normal REST blocking response, the program runs and never finishes. When using the streamed response, you can see it appears to be stuck in a loop on this particular person, Kurt.

I've included videos of this running from the command line as well a React app using an express backend (easier to visual the response that is coming back from the stream). If I change the system prompt, I get a different answer and don't run into this issue. The issue appears to be specific to this name.

You can see the details in the code, but this is using the gpt-4o-mini model from Azure OpenAI.

Screen.Recording.2024-12-18.at.10.36.45.AM.mov
Screen.Recording.2024-12-18.at.10.31.59.AM.mov

The code below can be used to reproduce the issue, assuming you have access to the same Azure OpenAI model:

Code example

import { createAzure } from '@ai-sdk/azure';
import { generateText,streamText } from 'ai'

let apiKey = process.env.OPENAI_API_KEY ? process.env.OPENAI_API_KEY : ''

const azure = createAzure({
    resourceName: 'openai-sandbox', // Azure resource name
    apiKey: apiKey,
    apiVersion: '2024-08-01-preview',

});

async function runProgramStream() {
     
    const { textStream } = streamText({
        model: azure('gpt-4o-mini'),
        //system: 'You are a helpful AI assistant.',
        prompt: 'Who is the founder of Intranet Software Unlimited whose first name started with "Kurt"?',
      });

      console.log(textStream)
      
      for await (const textPart of textStream) {
        console.log(textPart);
      } 
 }

runProgramStream()

AI provider

Azure OpenAI

Additional context

No response

@troycampano troycampano added the bug Something isn't working label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant