Skip to content

Commit 79778f7

Browse files
committed
feat: more examples
1 parent 939a073 commit 79778f7

4 files changed

Lines changed: 128 additions & 4 deletions

File tree

README.md

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# unofficial Deno wrapper for the Open Ai api
1+
# Deno wrapper for the Open Ai API
22

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

8-
### Usage
8+
## Usage
9+
10+
### Completion
911

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

23-
### Maintainers
25+
### Chat Completion
26+
27+
```ts
28+
import { OpenAI } from "https://deno.land/x/openai/mod.ts";
29+
30+
const openAI = new OpenAI("YOUR_API_KEY");
31+
32+
const chatCompletion = await openAI.createChatCompletion({
33+
model: "gpt-3.5-turbo",
34+
messages: [
35+
{ "role": "system", "content": "You are a helpful assistant." },
36+
{ "role": "user", "content": "Who won the world series in 2020?" },
37+
{
38+
"role": "assistant",
39+
"content": "The Los Angeles Dodgers won the World Series in 2020.",
40+
},
41+
{ "role": "user", "content": "Where was it played?" },
42+
],
43+
});
44+
45+
console.log(chatCompletion);
46+
```
47+
48+
### Image
49+
50+
```ts
51+
import { OpenAI } from "https://deno.land/x/openai/mod.ts";
52+
53+
const openAI = new OpenAI("YOUR_API_KEY");
54+
55+
const image = await openAI.createImage({
56+
prompt: "A unicorn in space",
57+
});
58+
59+
console.log(image);
60+
```
61+
62+
### Edit
63+
64+
```ts
65+
import { OpenAI } from "https://deno.land/x/openai/mod.ts";
66+
67+
const openAI = new OpenAI("YOUR_API_KEY");
68+
69+
const edit = await openAI.createEdit({
70+
model: "text-davinci-edit-001",
71+
input: "What day of the wek is it?",
72+
instruction: "Fix the spelling mistakes",
73+
});
74+
75+
console.log(edit);
76+
```
77+
78+
### Image Edit
79+
80+
```ts
81+
import { OpenAI } from "https://deno.land/x/openai/mod.ts";
82+
83+
const openAI = new OpenAI("YOUR_API_KEY");
84+
85+
const imageEdit = await openAI.createImageEdit({
86+
image: "@otter.png",
87+
mask: "@mask.png",
88+
prompt: "A cute baby sea otter wearing a beret",
89+
n: 2,
90+
size: "1024x1024",
91+
});
92+
93+
console.log(imageEdit);
94+
```
95+
96+
### Image Variation
97+
98+
```ts
99+
import { OpenAI } from "https://deno.land/x/openai/mod.ts";
100+
101+
const openAI = new OpenAI("YOUR_API_KEY");
102+
103+
const imageVariation = await openAI.createImageVariation({
104+
image: "@otter.png",
105+
n: 2,
106+
size: "1024x1024",
107+
});
108+
109+
console.log(imageVariation);
110+
```
111+
112+
## Maintainers
24113

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

28-
### License
117+
## License
29118

30119
MIT

examples/edit.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { OpenAI } from "../mod.ts";
2+
3+
const openAI = new OpenAI("YOUR_API_KEY");
4+
5+
const edit = await openAI.createEdit({
6+
model: "text-davinci-edit-001",
7+
input: "What day of the wek is it?",
8+
instruction: "Fix the spelling mistakes",
9+
});
10+
11+
console.log(edit);

examples/imageEdit.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { OpenAI } from "../mod.ts";
2+
3+
const openAI = new OpenAI("YOUR_API_KEY");
4+
5+
const imageEdit = await openAI.createImageEdit({
6+
image: "@otter.png",
7+
mask: "@mask.png",
8+
prompt: "A cute baby sea otter wearing a beret",
9+
n: 2,
10+
size: "1024x1024",
11+
});
12+
13+
console.log(imageEdit);

examples/imageVariation.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { OpenAI } from "../mod.ts";
2+
3+
const openAI = new OpenAI("YOUR_API_KEY");
4+
5+
const imageVariation = await openAI.createImageVariation({
6+
image: "@otter.png",
7+
n: 2,
8+
size: "1024x1024",
9+
});
10+
11+
console.log(imageVariation);

0 commit comments

Comments
 (0)