Skip to content

Instantly share code, notes, and snippets.

@roh26it
Created November 21, 2023 07:59
Show Gist options
  • Save roh26it/16633ca9726a39f6d9befee66943b3ee to your computer and use it in GitHub Desktop.
Save roh26it/16633ca9726a39f6d9befee66943b3ee to your computer and use it in GitHub Desktop.
OpenAI v4 with Portkey AI (For SiteGPT) - Node
import OpenAI from 'openai'; // We're using the v4 SDK
const openai = new OpenAI({
apiKey: 'OPENAI_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
baseURL: "https://api.portkey.ai",
defaultHeaders: {
"x-portkey-mode": "proxy openai",
"x-portkey-api-key": "PORTKEY_API_KEY",
"x-portkey-config": "CONFIG SLUG" // Optional to implement fallbacks, etc through a simple UI
}
});
async function main() {
const chatCompletion = await openai.chat.completions.create({
messages: [{ role: 'user', content: 'Say this is a test' }],
model: 'gpt-3.5-turbo',
});
console.log(chatCompletion.choices);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment