Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/load1n9/openai
Unofficial Deno wrapper for the Open Ai api
https://github.com/load1n9/openai
ai chatgpt chatgpt-api collaborate dall-e dalle2 gpt gpt-3 gpt-35-turbo gpt-4 gpt4 gptchat openai openai-api whisper whisper-ai
Last synced: 2 months ago
JSON representation
Unofficial Deno wrapper for the Open Ai api
- Host: GitHub
- URL: https://github.com/load1n9/openai
- Owner: load1n9
- License: mit
- Created: 2021-06-14T14:07:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-01T18:12:55.000Z (about 1 year ago)
- Last Synced: 2024-11-08T14:05:11.562Z (2 months ago)
- Topics: ai, chatgpt, chatgpt-api, collaborate, dall-e, dalle2, gpt, gpt-3, gpt-35-turbo, gpt-4, gpt4, gptchat, openai, openai-api, whisper, whisper-ai
- Language: TypeScript
- Homepage:
- Size: 335 KB
- Stars: 73
- Watchers: 3
- Forks: 23
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unofficial 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
Your Open AI Api key ([found here](https://beta.openai.com/account/api-keys)) is
needed for this library to work. We recommend setting it as an environment
variable. Here is a configuration example.```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);
```### Completion
```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);
const completion = await openAI.createCompletion({
model: "davinci",
prompt: "The meaning of life is",
});console.log(completion.choices);
```### Chat Completion
```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";const openAI = new OpenAI(Deno.env.get("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(Deno.env.get("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(Deno.env.get("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(Deno.env.get("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(Deno.env.get("YOUR_API_KEY")!);
const imageVariation = await openAI.createImageVariation({
image: "@otter.png",
n: 2,
size: "1024x1024",
});console.log(imageVariation);
```### Audio Transcription
```ts
import { OpenAI } from "https://deno.land/x/openai/mod.ts";const openAI = new OpenAI(Deno.env.get("YOUR_API_KEY")!);
const transcription = await openAI.createTranscription({
model: "whisper-1",
file: "/path/to/your/audio/file.mp3",
});console.log(transcription);
```## Maintainers
- Dean Srebnik ([@load1n9](https://github.com/load1n9))
- Lino Le Van ([@lino-levan](https://github.com/lino-levan))## License
MIT