Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Mar 8, 2023
1 parent 3eadc65 commit 9df914f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 21 deletions.
95 changes: 75 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,90 @@
# node-openai

Yet another Node.js wrapper for OpenAI's API.
An elegant Node.js library written in TypeScript for the OpenAI API.

## Installation

```bash
npm install node-openai
```

## Usage
## Example

```js
const OpenAI = require('node-openai');
For Node.js (CommonJS):

```javascript
const { OpenAI } = require('node-openai');
```

For ES Modules:

```javascript
import { OpenAI } from 'node-openai';
```

For TypeScript:

```typescript
import { OpenAI } from 'node-openai';
```

Create an instance of the OpenAI class:

```javascript
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
// organization: 'YOUR_ORGANIZATION_ID',
// options: { /* Axios Request Options */ },
});
```

## V1 API

To use the OpenAI V1 API, you must call the `v1()` method on the client instance:

```javascript
const v1 = client.v1();
```

### Models

List all available models:

```javascript
const models = await v1.models.list();
```

Retrieve a model:

```javascript
const model = await v1.models.retrieve('davinci');
```

### Completions

Create a completion:

```javascript
const completion = await v1.completions.create({
model: 'davinci',
prompt: 'This is a test',
max_tokens: 5,
temperature: 0.9
});
```

### Chat

(async () => {
const response = await client.v1().completions.create({
engine: 'davinci',
prompt: 'This is a test',
maxTokens: 5,
temperature: 0.9,
topP: 1,
presencePenalty: 0,
frequencyPenalty: 0,
bestOf: 1,
n: 1,
stream: false,
stop: ['\n', ' '],
});
})();
```
Create a chat:

```javascript
const chat = await v1.chat.create({
model: 'gpt-3.5-turbo',
messages: [
{
role: 'user',
content: 'Hello, how are you?'
}
]
});
```
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import axios, { AxiosRequestConfig } from "axios";
import * as v1 from "./v1";

// ApiConfig defines the configuration options for the OpenAI API
Expand Down

0 comments on commit 9df914f

Please sign in to comment.