Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Commit 57733e9

Browse files
refactor
- index to mod - 処理をcoreに分離
1 parent acbcbbf commit 57733e9

21 files changed

+198
-206
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# gpt
22

3+
OpenAI API made easy !!
4+
now deno support !
5+
6+
<https://beta.openai.com/docs>
7+
38
## install
49

510
```bash
@@ -37,3 +42,9 @@ async function main() {
3742
}
3843
main();
3944
```
45+
46+
## deno
47+
48+
```ts
49+
import { openai } from 'https://cdn.skypack.dev/@hikae/gpt?dts'
50+
```

example/classification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { openai, App } from "../src/fp";
1+
import { openai, App } from "@hikae/gpt";
22

33
export const classification = async (app: App) => {
44
const result = await openai.classification({

example/completion.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { App, openai } from "../src/index";
2-
import { CompletionOpts } from "../src/types/index";
1+
import { App, openai, CompletionOpts } from "@hikae/gpt";
32

43
export const completion = async (app: App) => {
54
const completionOpts: CompletionOpts = {
File renamed without changes.

deno/main.ts renamed to example/deno/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { App, openai } from "https://cdn.skypack.dev/@hikae/gpt?dts";
2+
import "https://deno.land/x/dotenv/load.ts";
23

34
const key = Deno.env.get("OPENAI_API_KEY");
45
if (!key) {
@@ -18,5 +19,5 @@ const result = await openai.classification({
1819
model: "ada",
1920
})(app);
2021

21-
console.log(result.selected_examples);
22+
console.log(result.label);
2223
// result = 'Positive'

example/engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, openai } from "../src/index";
1+
import { App, openai } from "@hikae/gpt";
22

33
export const engine = async (app: App) => {
44
const result = await openai.engine()(app);

example/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { openai } from "../src/index";
1+
import { openai } from "@hikae/gpt";
22
import { classification } from "./classification";
33
import { completion } from "./completion";
44
import { engine } from "./engine";

example/search.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { App, openai } from "../src/index";
2-
import { SearchOpts } from "../src/types/index";
1+
import { App, openai, SearchOpts } from "@hikae/gpt";
32

43
export const search = async (app: App) => {
54
const searchOpts: SearchOpts = {

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"scripts": {
33
"test": "jest",
44
"dev": "esmo example/main.ts",
5-
"build": "rimraf dist && tsup src/index.ts --dts --format cjs,esm",
5+
"dev:deno": "deno run --unstable -A example/deno/main.ts",
6+
"build": "rimraf dist && tsup src/mod.ts --dts --format cjs,esm",
67
"package-check": "npx @skypack/package-check"
78
},
89
"dependencies": {
@@ -23,18 +24,18 @@
2324
"typescript": "^4.4.2"
2425
},
2526
"name": "@hikae/gpt",
26-
"version": "0.0.9",
27+
"version": "0.0.10",
2728
"description": "A framework to build OpenAPI apps using nodejs",
2829
"keywords": [
2930
"gpt3"
3031
],
31-
"main": "dist/index.js",
32-
"module": "dist/index.mjs",
33-
"types": "dist/index.d.ts",
32+
"main": "dist/mod.js",
33+
"module": "dist/mod.mjs",
34+
"types": "dist/mod.d.ts",
3435
"exports": {
35-
"require": "./dist/index.js",
36-
"import": "./dist/index.mjs",
37-
"default": "./dist/index.mjs"
36+
"require": "./dist/mod.js",
37+
"import": "./dist/mod.mjs",
38+
"default": "./dist/mod.mjs"
3839
},
3940
"files": [
4041
"dist"

src/class.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
engineListURL,
77
engineURL,
88
searchURL,
9-
} from "./lib/index";
9+
} from "./lib/mod";
1010
import {
1111
Completion,
1212
CompletionOpts,
@@ -16,7 +16,14 @@ import {
1616
ListEngine,
1717
Search,
1818
SearchOpts,
19-
} from "./types";
19+
} from "./types/mod";
20+
import {
21+
classification,
22+
completion,
23+
engine,
24+
listEngines,
25+
search,
26+
} from "./core/mod";
2027
import { Options } from "ky";
2128

2229
/** App initialization options */
@@ -54,11 +61,7 @@ export class App {
5461
* @link https://beta.openai.com/docs/guides/completion/completion
5562
*/
5663
async completion(opts: CompletionOpts) {
57-
const url = completionURL(this.engineId);
58-
const options: Options = {
59-
json: opts,
60-
};
61-
return await this.api.post(url, options).json<Completion>();
64+
return completion(opts)({ api: this.api, engineId: this.engineId });
6265
}
6366

6467
// search
@@ -68,11 +71,7 @@ export class App {
6871
* @link https://beta.openai.com/docs/guides/search/search
6972
*/
7073
async search(opts: SearchOpts) {
71-
const url = searchURL(this.engineId);
72-
const options: Options = {
73-
json: opts,
74-
};
75-
return await this.api.post(url, options).json<Search>();
74+
return search(opts)({ api: this.api, engineId: this.engineId });
7675
}
7776

7877
// Classification
@@ -82,11 +81,7 @@ export class App {
8281
* @link https://beta.openai.com/docs/api-reference/classifications/create
8382
*/
8483
async classification(opts: ClassificationOpts) {
85-
const url = classificationsURL();
86-
const options: Options = {
87-
json: opts,
88-
};
89-
return await this.api.post(url, options).json<Classification>();
84+
return classification(opts)({ api: this.api, engineId: this.engineId });
9085
}
9186

9287
// Engines
@@ -96,16 +91,14 @@ export class App {
9691
* @link https://beta.openai.com/docs/api-reference/engines/list
9792
*/
9893
async listEngines() {
99-
const url = engineListURL();
100-
return await this.api.get(url).json<ListEngine>();
94+
return listEngines()({ api: this.api, engineId: this.engineId });
10195
}
10296

10397
/**
10498
* Retrieve engine OR get current engine
10599
* @link https://beta.openai.com/docs/api-reference/engines/retrieve
106100
*/
107101
async engine(engineId?: string) {
108-
const url = engineURL(engineId ?? this.engineId);
109-
return await this.api.get(url).json<Engine>();
102+
return engine()({ api: this.api, engineId: engineId ?? this.engineId });
110103
}
111104
}

0 commit comments

Comments
 (0)