Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite api to match modern specs #2

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci

on: [push, pull_request]

jobs:
build:
name: tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v2
- name: download deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: check format
if: matrix.os == 'ubuntu-latest'
run: deno fmt --check

- name: check linting
if: matrix.os == 'ubuntu-latest'
run: deno lint

# TODO: Testing
# - name: run tests
# run: deno task test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2023 Dean Srebnik

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# unofficial Deno wrapper for the Open Ai api

### usage:
[![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

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

const instance = new OpenAI('YOUR_API_KEY');
const openAI = new OpenAI("YOUR_API_KEY");

console.log(await instance.createCompletion('The meaning of life is'))
const completion = await openAI.createCompletion({
model: "davinci",
prompt: "The meaning of life is",
});

console.log(completion.choices);
```

### Maintainers

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

### License

MIT
3 changes: 3 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tasks": {}
}
18 changes: 18 additions & 0 deletions examples/chat_completion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { OpenAI } from "../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);
14 changes: 0 additions & 14 deletions examples/classification.ts

This file was deleted.

11 changes: 8 additions & 3 deletions examples/completion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { OpenAI } from '../mod.ts';
import { OpenAI } from "../mod.ts";

const instance = new OpenAI('YOUR_API_KEY');
const openAI = new OpenAI("YOUR_API_KEY");

console.log(await instance.createCompletion('The meaning of life is'))
const completion = await openAI.createCompletion({
model: "davinci",
prompt: "The meaning of life is",
});

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

const openAI = new OpenAI("YOUR_API_KEY");

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

console.log(image);
5 changes: 0 additions & 5 deletions examples/search.ts

This file was deleted.

4 changes: 3 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { OpenAI } from './src/openai.ts';
export { OpenAI } from "./src/openai.ts";

export * from "./src/types.ts";
Loading