0.2.2 • Published 5 months ago

@gensx/openai v0.2.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

@gensx/openai

A pre-wrapped version of the OpenAI SDK for GenSX. This package provides a simple way to use OpenAI's API with GenSX components.

Installation

npm install @gensx/openai openai

Usage

You can use this package in two ways:

1. Drop-in Replacement (Recommended)

Simply replace your OpenAI import with the GenSX version:

// Instead of:
// import { OpenAI } from 'openai';

// Use:
import { OpenAI } from "@gensx/openai";

// Create a client as usual
const client = new OpenAI({
  apiKey: "your-api-key",
});

// All methods are automatically wrapped with GenSX functionality
const completion = await client.chat.completions.create({
  model: "gpt-4",
  messages: [{ role: "user", content: "Hello!" }],
});

// Use embeddings
const embedding = await client.embeddings.create({
  model: "text-embedding-ada-002",
  input: "Hello world!",
});

// Use responses
const response = await client.responses.create({
  model: "gpt-4",
  messages: [{ role: "user", content: "Hello!" }],
});

2. Wrap an Existing Instance

If you already have an OpenAI instance, you can wrap it with GenSX functionality:

import { OpenAI } from "openai";
import { wrapOpenAI } from "@gensx/openai";

// Create your OpenAI instance as usual
const client = wrapOpenAI(
  new OpenAI({
    apiKey: "your-api-key",
  }),
);

// Now all methods are wrapped with GenSX functionality
const completion = await client.chat.completions.create({
  model: "gpt-4",
  messages: [{ role: "user", content: "Hello!" }],
});

API

The package exports:

  1. OpenAI - A drop-in replacement for the OpenAI client that automatically wraps all methods with GenSX functionality
  2. wrapOpenAI - A function to manually wrap an OpenAI instance with GenSX functionality

License

Apache-2.0

0.2.2

5 months ago

0.2.1

5 months ago

0.2.0

5 months ago

0.2.0-alpha.3

5 months ago

0.2.0-alpha.2

5 months ago

0.2.0-alpha.1

5 months ago

0.1.28

5 months ago

0.1.27

6 months ago

0.1.26

6 months ago

0.1.25

6 months ago

0.1.24

6 months ago

0.1.23

6 months ago

0.1.22

6 months ago

0.1.21

6 months ago

0.1.20

7 months ago

0.1.19

7 months ago

0.1.18

7 months ago

0.1.17

7 months ago

0.1.16

7 months ago

0.1.15

7 months ago

0.1.14

7 months ago

0.1.13

7 months ago

0.1.12

8 months ago

0.1.11

8 months ago

0.1.10

8 months ago

0.1.9

8 months ago

0.1.8

8 months ago

0.1.7

8 months ago

0.1.6

8 months ago

0.1.5

9 months ago

0.1.4

9 months ago

0.1.3

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

10 months ago