OpenAI Node

Installation

npm install martian-node

Usage

Using OpenAI's SDK, the following function

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'My OPENAI Key', // defaults to process.env["OPENAI_API_KEY"]
});

async function main() {
  const chatCompletion = await openai.chat.completions.create({
    messages: [{ role: 'user', content: 'Say this is a test' }],
    model: 'gpt-3.5-turbo',
  });
}

main();

becomes

import OpenAI from 'martian-node';

const openai = new OpenAI({
  apiKey: 'My Martian Key', // defaults to process.env["MARTIAN_API_KEY"]
});

async function main() {
  const chatCompletion = await openai.chat.completions.create({
    messages: [{ role: 'user', content: 'Say this is a test' }],
    model: 'router'
    // model: ['gpt-3.5-turbo', 'claude-v1'], // If more than one is specified, the router chooses the best among them
  });
}

main();

Last updated