I really struggled to use the official SDK to integration the Chat completions endpoint. In particular, I needed to stream the results and needed it to work in browser and Node.js. NPM package “completions” does both, and it is easy to use:
npm install completions
import { createChat } from "completions";
const chat = createChat({
apiKey: process.env.OPENAI_API_KEY,
model: "gpt-3.5-turbo",
// or:
// model: 'gpt-4',
});
await chat.sentMessage("Ping");
Would be nice if this option was mentioned in the documentation.