Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save transmissions11/87ab124ebd85823b1565c4110836c7f3 to your computer and use it in GitHub Desktop.
Save transmissions11/87ab124ebd85823b1565c4110836c7f3 to your computer and use it in GitHub Desktop.
import { OpenAI } from "openai-streams";
import { yieldStream } from "yield-stream";
const stream = await OpenAI(
"chat",
{
model: "gpt-3.5-turbo",
n: 2,
temperature: 1,
messages: [{ role: "user", content: "hi" }],
},
{ apiKey: API_KEY, mode: "raw" }
);
const DECODER = new TextDecoder();
for await (const chunk of yieldStream(stream)) {
const decoded = JSON.parse(DECODER.decode(chunk));
console.log(decoded);
}
@transmissions11
Copy link
Author

output ends with this weird error object

Screenshot 2023-03-16 at 7 49 00 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment