PROJECT IN EARLY DEVELOPMENT
A simple modification in the official OpenAI module that gives the possibility to use plugins that follow the OpenAI standards together with the API.
Important note: this library is meant for server-side usage only, as using it in client-side browser code will expose your secret API key. See here for more details.
npm install openai-plugin
The library needs to be configured with your account's secret key, which is available on the website. We recommend setting as an environment variable.
Create a .env
file in the root of your project and add your secret key:
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx
Here's an example of initializing the library with the API key loaded from an environment variable and creating a completion using a plugin:
import { Configuration, OpenAIPluginApi, Plugins } from "openai-plugin";
import dotenv from "dotenv";
dotenv.config();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIPluginApi(configuration);
(async () => {
var plugins = new Plugins([
{
name: 'Calculator',
manifest: 'https://chat-calculator-plugin.supportmirage.repl.co/.well-known/ai-plugin.json'
}
])
var completion = await openai.createChatCompletionPlugin({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: "How much is 3849 x 8394 ?"}],
plugins
});
console.log(completion.completions.map(completion => completion.message));
})();
Check out the full API documentation for examples of all the available functions.
- support to auth
- support to all openapi versions
- support to predefined variables(like $userId)
- debug mode
- token management
- Fix method in sdk generation
- make tamplates and handles more modular
Thank you to ceifa for creating and maintaining the original unofficial openai
npm package before we released this official library! ceifa's original package has been renamed to gpt-x.