Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nishtahir/openai-pool


https://github.com/nishtahir/openai-pool

Last synced: 23 days ago
JSON representation

Awesome Lists containing this project

README

        

# openai-pool

A simple round robin pool for OpenAI clients.

## Usage

```js
import { OpenAIPoolBuilder } from "openai-pool";

const clientA = new OpenAI({ apiKey: "your key" });
const clientB = new OpenAI({ apiKey: "your key" });

const pool = new OpenAIPoolBuilder()
.withClient(clientA)
.withClient(clientB)
.create();

// The pool mimics the OpenAI client API
// but invokations are round robin load balanced between client instances

// Uses clientA
pool.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [],
});

// Uses clientB
pool.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [],
});

// Uses clientA
pool.embeddings.create({
model: "text-embedding-ada-002",
input: [],
});
```