Skip to content

How to access the raw response from a provider in a stream without reconstructing it from a fullStream? #2129

Answered by Und3rf10w
Und3rf10w asked this question in Help
Discussion options

You must be logged in to vote

I ended up doing something like the below. Unfortunately, I couldn't figure out how to use the fetch to actually access the response:

export async function chatCompletionApi(reqData: ChatCompletionRequest): Promise<Response> {
  const openai = await getLanguageModel(reqData.modelName)

  /** <snip.../> */

  if (reqData.stream) {
    const stream = streamText({
      model: openai,
      /** <snip.../> */
    })
    
    const readable = new ReadableStream({
      async start(controller) {
        try {
          for await (const chunk of stream.textStream) {
            controller.enqueue(chunk)
          }
          controller.close()
        } catch (error) {
          controller.error(e…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Und3rf10w
Comment options

Answer selected by Und3rf10w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants