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

Support for the promptFeedback.blockReason in the Gemini streaming output #4236

Open
xukecheng opened this issue Dec 31, 2024 · 0 comments · May be fixed by #4265
Open

Support for the promptFeedback.blockReason in the Gemini streaming output #4236

xukecheng opened this issue Dec 31, 2024 · 0 comments · May be fixed by #4265
Labels
bug Something isn't working

Comments

@xukecheng
Copy link

Description

During the use of Gemini API, it is possible to encounter a return blockReason.

{
  "promptFeedback": {
    "blockReason": "PROHIBITED_CONTENT"
  },
  "usageMetadata": {
    "promptTokenCount": 12559,
    "totalTokenCount": 12559
  },
  "modelVersion": "gemini-1.5-flash-002"
}

However, it currently seems that there is no way to obtain the blockReason in the streaming output.

Code example

  const textStream = await streamText({
    model,
    system,
    prompt,
    maxTokens: 8192,
    onFinish({ usage }) {
      modelUsage = usage;
    },
  });

  for await (const textPart of textStream.textStream) {
    const formattedText = textPart.replace(/\n/g, '\r\n');
    controller.enqueue(encoder.encode(`data: ${formattedText}\n\n`));
  }

AI provider

[email protected] @ai-sdk/[email protected]

Additional context

No response

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

Successfully merging a pull request may close this issue.

1 participant