Skip to content

OpenAI Streaming Example

This example shows how to integrate oRPC with the OpenAI Streaming API to build a chatbot.

Basic Example

ts
import  from 'openai'

const  = new ()

const  = 
  .(.({ : .() }))
  .(async function* ({  }) {
    const  = await ...({
      : 'gpt-4o',
      : [{ : 'user', : . }],
      : true,
    })

    yield* 
  })

const  = {  }

// --------------- CLIENT ---------------

const  = new ({
  : 'https://example.com/rpc',
})

const : <typeof > = ()

const  = await .({ : 'Hello, world!' })

for await (const  of ) {
  .(.[0]?.?. || '')
}

INFO

Learn more about RPCLink and Event Iterator.

Released under the MIT License.