Portkey-AI / portkey-node-sdk

Build reliable, secure, and production-ready AI apps easily.

Home Page:https://portkey.ai/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Revamp Node SDK: Wrapper

csgulati09 opened this issue · comments

Building our SDK in a way that it is a wrapper around OpenAI SDK.

Instead of calling our Gateway, making a call to OpenAI SDK with all the needed changes

🤖

Based on your requirements, you'll need to modify the Portkey Node SDK to function as a wrapper around the OpenAI SDK. This involves replacing the calls to the Portkey Gateway with calls to the OpenAI SDK. Here's a general approach you can follow:

  1. Install the OpenAI SDK: You can do this by running the command npm install openai in your terminal.

  2. Modify the Portkey Node SDK: You'll need to replace the calls to the Portkey Gateway with calls to the OpenAI SDK. Here's a simplified example of how you might do this:

import { config } from 'dotenv';
import { OpenAI } from 'openai';

config({ override: true })
const client = new OpenAI(process.env["OPENAI_API_KEY"] ?? "");

describe('Completions APIs', () => {
    test('model: gpt-3.5-turbo-instruct', async () => {
        const completion = await client.createCompletion({ model: 'gpt-3.5-turbo-instruct', prompt: 'This is a test.' });
        expect(completion).toBeDefined();
        expect(completion.choices).toBeDefined();
        expect(completion.choices.length).toBeGreaterThan(0);
    });

    // ... rest of the tests
});

In this example, we're importing the OpenAI SDK and creating a new instance of it using the OpenAI API key. Then, we're using the createCompletion method of the OpenAI SDK to create completions, instead of the completions.create method of the Portkey SDK.

Please note that this is a simplified example and the actual implementation might require additional changes based on the specific requirements of your application. You can refer to the OpenAI SDK documentation for more details on how to use the OpenAI SDK.

Regarding the current structure of the Portkey Node SDK codebase, it's structured around a main class named Portkey which extends from the ApiClient class. This class has several properties and methods corresponding to different APIs. You can refer to the Portkey Node SDK source code for more details.

I hope this helps! If you have any more questions or need further clarification, feel free to ask.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.