Created
November 21, 2023 07:59
-
-
Save roh26it/16633ca9726a39f6d9befee66943b3ee to your computer and use it in GitHub Desktop.
OpenAI v4 with Portkey AI (For SiteGPT) - Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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