Skip to content

stream-text: incompatible with response_format: { type: 'json' }Β #190

@kingyue737

Description

@kingyue737

The stream-text is not returning content in chunks as expected β€” instead, it returns everything all at once at the end.

No such issue in v0.2.2

Reproduction

import { streamText } from '@xsai/stream-text'
import { env } from 'node:process'

export default defineEventHandler(async (event) => {
  const { content } = await readValidatedBody(
    event,
    z.object({
      content: z.string(),
    }).parse,
  )

  const { textStream } = await streamText({
    apiKey: env.OPENAI_API_KEY!,
    baseURL: env.OPENAI_BASE_URL!,
    messages: [
      { role: 'system', content: AVeryLongContent },
      { role: 'user', content },
    ],
    model: 'deepseek-chat',
    response_format: { type: 'json_object' },
  })

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

  // return textStream
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions