Skip to content

Multiple Openai Accounts

Albarqawi edited this page Aug 30, 2023 · 2 revisions

With IntelliNode, you can create different openai instances with different accounts. For instance, your microservice can have a chatbot connected to the openai platform and another connected to Azure deployment.

Openai platform chatbot

const { Chatbot, ChatGPTInput, SupportedChatModels } = require('intellinode');
const input = new ChatGPTInput(systemMessage, {model: 'gpt-4'});
input.addUserMessage('What is the distance between the Earth and the Moon?');

// ## account1 key ##
const chatbotOpenai1 = new Chatbot(apiKey1, SupportedChatModels.OPENAI);

// call chatbot1
const chatResponses1 = await chatbotOpenai1.chat(input);

// ## account2 key ##
const chatbotOpenai2 = new Chatbot(apiKey2, SupportedChatModels.OPENAI);

// call chatbot2
const chatResponses2 = await chatbotOpenai2.chat(input);

Azure account chatbot

const { ProxyHelper, Chatbot, ChatGPTInput, SupportedChatModels } = require('intellinode');
// ## azure account instance ##

const input = new ChatGPTInput(systemMessage, {model: 'deployed-model-name'});
input.addUserMessage('What is the distance between the Earth and the Moon?');

// initiate azure proxy instance
const proxyHelper = new ProxyHelper();
proxyHelper.setAzureOpenai(resourceName);

// create chatbot with azure proxy
const chatbotAzure = new Chatbot(apiKey, SupportedChatModels.OPENAI, proxyHelper);

// call azure chatbot
const chatResponses = await chatbotAzure.chat(input);

Openai platform embedding

const { RemoteEmbedModel, EmbedInput } = require('intellinode');
const embedInput = new EmbedInput({ texts: [inputString], model: 'text-embedding-ada-002' });

// ## account1 key ##
const embedOpenai1 = new RemoteEmbedModel(apiKey1, 'openai');

// get the embedding vector - account1
const embeddingsResponse1 = await embedOpenai1.getEmbeddings(embedInput);

// ## account2 key ##
const embedOpenai2 = new RemoteEmbedModel(apiKey2, 'openai');

// get the embedding vector - account2
const embeddingsResponse1 = await embedOpenai2.getEmbeddings(embedInput);
Clone this wiki locally