6
6
engineListURL ,
7
7
engineURL ,
8
8
searchURL ,
9
- } from "./lib/index " ;
9
+ } from "./lib/mod " ;
10
10
import {
11
11
Completion ,
12
12
CompletionOpts ,
@@ -16,7 +16,14 @@ import {
16
16
ListEngine ,
17
17
Search ,
18
18
SearchOpts ,
19
- } from "./types" ;
19
+ } from "./types/mod" ;
20
+ import {
21
+ classification ,
22
+ completion ,
23
+ engine ,
24
+ listEngines ,
25
+ search ,
26
+ } from "./core/mod" ;
20
27
import { Options } from "ky" ;
21
28
22
29
/** App initialization options */
@@ -54,11 +61,7 @@ export class App {
54
61
* @link https://beta.openai.com/docs/guides/completion/completion
55
62
*/
56
63
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 } ) ;
62
65
}
63
66
64
67
// search
@@ -68,11 +71,7 @@ export class App {
68
71
* @link https://beta.openai.com/docs/guides/search/search
69
72
*/
70
73
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 } ) ;
76
75
}
77
76
78
77
// Classification
@@ -82,11 +81,7 @@ export class App {
82
81
* @link https://beta.openai.com/docs/api-reference/classifications/create
83
82
*/
84
83
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 } ) ;
90
85
}
91
86
92
87
// Engines
@@ -96,16 +91,14 @@ export class App {
96
91
* @link https://beta.openai.com/docs/api-reference/engines/list
97
92
*/
98
93
async listEngines ( ) {
99
- const url = engineListURL ( ) ;
100
- return await this . api . get ( url ) . json < ListEngine > ( ) ;
94
+ return listEngines ( ) ( { api : this . api , engineId : this . engineId } ) ;
101
95
}
102
96
103
97
/**
104
98
* Retrieve engine OR get current engine
105
99
* @link https://beta.openai.com/docs/api-reference/engines/retrieve
106
100
*/
107
101
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 } ) ;
110
103
}
111
104
}
0 commit comments