openai 1.1.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/base.ts ADDED
@@ -0,0 +1,71 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * OpenAI API
5
+ * APIs for sampling from and fine-tuning language models
6
+ *
7
+ * The version of the OpenAPI document: 1.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ import { Configuration } from "./configuration";
17
+ // Some imports not used depending on template conditions
18
+ // @ts-ignore
19
+ import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
20
+
21
+ export const BASE_PATH = "https://api.openai.com/v1".replace(/\/+$/, "");
22
+
23
+ /**
24
+ *
25
+ * @export
26
+ */
27
+ export const COLLECTION_FORMATS = {
28
+ csv: ",",
29
+ ssv: " ",
30
+ tsv: "\t",
31
+ pipes: "|",
32
+ };
33
+
34
+ /**
35
+ *
36
+ * @export
37
+ * @interface RequestArgs
38
+ */
39
+ export interface RequestArgs {
40
+ url: string;
41
+ options: AxiosRequestConfig;
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @export
47
+ * @class BaseAPI
48
+ */
49
+ export class BaseAPI {
50
+ protected configuration: Configuration | undefined;
51
+
52
+ constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
53
+ if (configuration) {
54
+ this.configuration = configuration;
55
+ this.basePath = configuration.basePath || this.basePath;
56
+ }
57
+ }
58
+ };
59
+
60
+ /**
61
+ *
62
+ * @export
63
+ * @class RequiredError
64
+ * @extends {Error}
65
+ */
66
+ export class RequiredError extends Error {
67
+ name: "RequiredError" = "RequiredError";
68
+ constructor(public field: string, msg?: string) {
69
+ super(msg);
70
+ }
71
+ }
package/common.ts ADDED
@@ -0,0 +1,138 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * OpenAI API
5
+ * APIs for sampling from and fine-tuning language models
6
+ *
7
+ * The version of the OpenAPI document: 1.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ import { Configuration } from "./configuration";
17
+ import { RequiredError, RequestArgs } from "./base";
18
+ import { AxiosInstance, AxiosResponse } from 'axios';
19
+
20
+ /**
21
+ *
22
+ * @export
23
+ */
24
+ export const DUMMY_BASE_URL = 'https://example.com'
25
+
26
+ /**
27
+ *
28
+ * @throws {RequiredError}
29
+ * @export
30
+ */
31
+ export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
32
+ if (paramValue === null || paramValue === undefined) {
33
+ throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
34
+ }
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @export
40
+ */
41
+ export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
42
+ if (configuration && configuration.apiKey) {
43
+ const localVarApiKeyValue = typeof configuration.apiKey === 'function'
44
+ ? await configuration.apiKey(keyParamName)
45
+ : await configuration.apiKey;
46
+ object[keyParamName] = localVarApiKeyValue;
47
+ }
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @export
53
+ */
54
+ export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
55
+ if (configuration && (configuration.username || configuration.password)) {
56
+ object["auth"] = { username: configuration.username, password: configuration.password };
57
+ }
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @export
63
+ */
64
+ export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
65
+ if (configuration && configuration.accessToken) {
66
+ const accessToken = typeof configuration.accessToken === 'function'
67
+ ? await configuration.accessToken()
68
+ : await configuration.accessToken;
69
+ object["Authorization"] = "Bearer " + accessToken;
70
+ }
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @export
76
+ */
77
+ export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
78
+ if (configuration && configuration.accessToken) {
79
+ const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
80
+ ? await configuration.accessToken(name, scopes)
81
+ : await configuration.accessToken;
82
+ object["Authorization"] = "Bearer " + localVarAccessTokenValue;
83
+ }
84
+ }
85
+
86
+ /**
87
+ *
88
+ * @export
89
+ */
90
+ export const setSearchParams = function (url: URL, ...objects: any[]) {
91
+ const searchParams = new URLSearchParams(url.search);
92
+ for (const object of objects) {
93
+ for (const key in object) {
94
+ if (Array.isArray(object[key])) {
95
+ searchParams.delete(key);
96
+ for (const item of object[key]) {
97
+ searchParams.append(key, item);
98
+ }
99
+ } else {
100
+ searchParams.set(key, object[key]);
101
+ }
102
+ }
103
+ }
104
+ url.search = searchParams.toString();
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @export
110
+ */
111
+ export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
112
+ const nonString = typeof value !== 'string';
113
+ const needsSerialization = nonString && configuration && configuration.isJsonMime
114
+ ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
115
+ : nonString;
116
+ return needsSerialization
117
+ ? JSON.stringify(value !== undefined ? value : {})
118
+ : (value || "");
119
+ }
120
+
121
+ /**
122
+ *
123
+ * @export
124
+ */
125
+ export const toPathString = function (url: URL) {
126
+ return url.pathname + url.search + url.hash
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @export
132
+ */
133
+ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
134
+ return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
135
+ const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
136
+ return axios.request<T, R>(axiosRequestArgs);
137
+ };
138
+ }
@@ -0,0 +1,127 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * OpenAI API
5
+ * APIs for sampling from and fine-tuning language models
6
+ *
7
+ * The version of the OpenAPI document: 1.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ const packageJson = require("../package.json");
17
+
18
+ export interface ConfigurationParameters {
19
+ apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
20
+ organization?: string;
21
+ username?: string;
22
+ password?: string;
23
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
24
+ basePath?: string;
25
+ baseOptions?: any;
26
+ formDataCtor?: new () => any;
27
+ }
28
+
29
+ export class Configuration {
30
+ /**
31
+ * parameter for apiKey security
32
+ * @param name security name
33
+ * @memberof Configuration
34
+ */
35
+ apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
36
+ /**
37
+ * OpenAI organization id
38
+ *
39
+ * @type {string}
40
+ * @memberof Configuration
41
+ */
42
+ organization?: string;
43
+ /**
44
+ * parameter for basic security
45
+ *
46
+ * @type {string}
47
+ * @memberof Configuration
48
+ */
49
+ username?: string;
50
+ /**
51
+ * parameter for basic security
52
+ *
53
+ * @type {string}
54
+ * @memberof Configuration
55
+ */
56
+ password?: string;
57
+ /**
58
+ * parameter for oauth2 security
59
+ * @param name security name
60
+ * @param scopes oauth2 scope
61
+ * @memberof Configuration
62
+ */
63
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
64
+ /**
65
+ * override base path
66
+ *
67
+ * @type {string}
68
+ * @memberof Configuration
69
+ */
70
+ basePath?: string;
71
+ /**
72
+ * base options for axios calls
73
+ *
74
+ * @type {any}
75
+ * @memberof Configuration
76
+ */
77
+ baseOptions?: any;
78
+ /**
79
+ * The FormData constructor that will be used to create multipart form data
80
+ * requests. You can inject this here so that execution environments that
81
+ * do not support the FormData class can still run the generated client.
82
+ *
83
+ * @type {new () => FormData}
84
+ */
85
+ formDataCtor?: new () => any;
86
+
87
+ constructor(param: ConfigurationParameters = {}) {
88
+ this.apiKey = param.apiKey;
89
+ this.organization = param.organization;
90
+ this.username = param.username;
91
+ this.password = param.password;
92
+ this.accessToken = param.accessToken;
93
+ this.basePath = param.basePath;
94
+ this.baseOptions = param.baseOptions;
95
+ this.formDataCtor = param.formDataCtor;
96
+
97
+ if (!this.baseOptions) {
98
+ this.baseOptions = {};
99
+ }
100
+ this.baseOptions.headers = {
101
+ 'User-Agent': `OpenAI/NodeJS/${packageJson.version}`,
102
+ 'Authorization': `Bearer ${this.apiKey}`,
103
+ ...this.baseOptions.headers,
104
+ }
105
+ if (this.organization) {
106
+ this.baseOptions.headers['OpenAI-Organization'] = this.organization;
107
+ }
108
+ if (!this.formDataCtor) {
109
+ this.formDataCtor = require("form-data");
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Check if the given MIME is a JSON MIME.
115
+ * JSON MIME examples:
116
+ * application/json
117
+ * application/json; charset=UTF8
118
+ * APPLICATION/JSON
119
+ * application/vnd.company+json
120
+ * @param mime - MIME (Multipurpose Internet Mail Extensions)
121
+ * @return True if the given MIME is JSON, false otherwise.
122
+ */
123
+ public isJsonMime(mime: string): boolean {
124
+ const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
125
+ return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
126
+ }
127
+ }