You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// https://github.com/dexaai/openai-fetchimport{OpenAIClient,typeChatParams}from'openai-fetch';constclient=newOpenAIClient({apiKey: 'YOUR_KEY'});letpartialResponseText=''asyncfunctionreadStreamChunks(stream: ReadableStream,cb: Function){constreader=stream.getReader();// A function to handle reading each chunkasyncfunctionread(){const{ done, value }=awaitreader.read();if(done){cb();return;}console.log('delta chunk response',value.choices[0].delta.content)partialResponseText+=value.choices[0].delta.contentconsole.log('concat partial response',partialResponseText)// Recursively read the next chunkread();}// Start readingread();}constreadableStream: ChatStreamResponse=awaitclient.streamChatCompletion({model: "gpt-4-turbo-preview",// make sure on platform.openai.com that you have access to that model or choose anothermessages: [{role: "system",content: "Tell me a story about openai-fetch, a library that can stream OpenAI responses."},],temperature: 0.7,n: 1,}asChatParams);// start reading the streamreadStreamChunks(readableStream,()=>{console.log('full response ready',partialResponseText)})
Is this function already implemented?
The text was updated successfully, but these errors were encountered: