Skip to content

Commit

Permalink
feat: more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 committed Mar 14, 2023
1 parent 939a073 commit 79778f7
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 4 deletions.
97 changes: 93 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# unofficial Deno wrapper for the Open Ai api
# Deno wrapper for the Open Ai API

[![Tags](https://img.shields.io/github/release/load1n9/openai)](https://github.com/load1n9/openai/releases)
[![Doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/openai/mod.ts)
[![Checks](https://github.com/load1n9/openai/actions/workflows/ci.yml/badge.svg)](https://github.com/load1n9/openai/actions/workflows/ci.yml)
[![License](https://img.shields.io/github/license/load1n9/openai)](https://github.com/load1n9/openai/blob/master/LICENSE)

### Usage
## Usage

### Completion

```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";
Expand All @@ -20,11 +22,98 @@ const completion = await openAI.createCompletion({
console.log(completion.choices);
```

### Maintainers
### Chat Completion

```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI("YOUR_API_KEY");

const chatCompletion = await openAI.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Who won the world series in 2020?" },
{
"role": "assistant",
"content": "The Los Angeles Dodgers won the World Series in 2020.",
},
{ "role": "user", "content": "Where was it played?" },
],
});

console.log(chatCompletion);
```

### Image

```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI("YOUR_API_KEY");

const image = await openAI.createImage({
prompt: "A unicorn in space",
});

console.log(image);
```

### Edit

```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI("YOUR_API_KEY");

const edit = await openAI.createEdit({
model: "text-davinci-edit-001",
input: "What day of the wek is it?",
instruction: "Fix the spelling mistakes",
});

console.log(edit);
```

### Image Edit

```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI("YOUR_API_KEY");

const imageEdit = await openAI.createImageEdit({
image: "@otter.png",
mask: "@mask.png",
prompt: "A cute baby sea otter wearing a beret",
n: 2,
size: "1024x1024",
});

console.log(imageEdit);
```

### Image Variation

```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";

const openAI = new OpenAI("YOUR_API_KEY");

const imageVariation = await openAI.createImageVariation({
image: "@otter.png",
n: 2,
size: "1024x1024",
});

console.log(imageVariation);
```

## Maintainers

- Dean Srebnik ([@load1n9](https://github.com/load1n9))
- Lino Le Van ([@lino-levan](https://github.com/lino-levan))

### License
## License

MIT
11 changes: 11 additions & 0 deletions examples/edit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { OpenAI } from "../mod.ts";

const openAI = new OpenAI("YOUR_API_KEY");

const edit = await openAI.createEdit({
model: "text-davinci-edit-001",
input: "What day of the wek is it?",
instruction: "Fix the spelling mistakes",
});

console.log(edit);
13 changes: 13 additions & 0 deletions examples/imageEdit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { OpenAI } from "../mod.ts";

const openAI = new OpenAI("YOUR_API_KEY");

const imageEdit = await openAI.createImageEdit({
image: "@otter.png",
mask: "@mask.png",
prompt: "A cute baby sea otter wearing a beret",
n: 2,
size: "1024x1024",
});

console.log(imageEdit);
11 changes: 11 additions & 0 deletions examples/imageVariation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { OpenAI } from "../mod.ts";

const openAI = new OpenAI("YOUR_API_KEY");

const imageVariation = await openAI.createImageVariation({
image: "@otter.png",
n: 2,
size: "1024x1024",
});

console.log(imageVariation);

0 comments on commit 79778f7

Please sign in to comment.