openlayer 0.0.0 → 0.0.1-alpha.1

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.
Files changed (257) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +412 -0
  3. package/_shims/MultipartBody.d.ts +9 -0
  4. package/_shims/MultipartBody.d.ts.map +1 -0
  5. package/_shims/MultipartBody.js +16 -0
  6. package/_shims/MultipartBody.js.map +1 -0
  7. package/_shims/MultipartBody.mjs +12 -0
  8. package/_shims/MultipartBody.mjs.map +1 -0
  9. package/_shims/README.md +46 -0
  10. package/_shims/auto/runtime-bun.d.ts +5 -0
  11. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  12. package/_shims/auto/runtime-bun.js +21 -0
  13. package/_shims/auto/runtime-bun.js.map +1 -0
  14. package/_shims/auto/runtime-bun.mjs +2 -0
  15. package/_shims/auto/runtime-bun.mjs.map +1 -0
  16. package/_shims/auto/runtime-node.d.ts +5 -0
  17. package/_shims/auto/runtime-node.d.ts.map +1 -0
  18. package/_shims/auto/runtime-node.js +21 -0
  19. package/_shims/auto/runtime-node.js.map +1 -0
  20. package/_shims/auto/runtime-node.mjs +2 -0
  21. package/_shims/auto/runtime-node.mjs.map +1 -0
  22. package/_shims/auto/runtime.d.ts +5 -0
  23. package/_shims/auto/runtime.d.ts.map +1 -0
  24. package/_shims/auto/runtime.js +21 -0
  25. package/_shims/auto/runtime.js.map +1 -0
  26. package/_shims/auto/runtime.mjs +2 -0
  27. package/_shims/auto/runtime.mjs.map +1 -0
  28. package/_shims/auto/types-node.d.ts +5 -0
  29. package/_shims/auto/types-node.d.ts.map +1 -0
  30. package/_shims/auto/types-node.js +21 -0
  31. package/_shims/auto/types-node.js.map +1 -0
  32. package/_shims/auto/types-node.mjs +2 -0
  33. package/_shims/auto/types-node.mjs.map +1 -0
  34. package/_shims/auto/types.d.ts +101 -0
  35. package/_shims/auto/types.js +3 -0
  36. package/_shims/auto/types.mjs +3 -0
  37. package/_shims/bun-runtime.d.ts +6 -0
  38. package/_shims/bun-runtime.d.ts.map +1 -0
  39. package/_shims/bun-runtime.js +14 -0
  40. package/_shims/bun-runtime.js.map +1 -0
  41. package/_shims/bun-runtime.mjs +10 -0
  42. package/_shims/bun-runtime.mjs.map +1 -0
  43. package/_shims/index.d.ts +81 -0
  44. package/_shims/index.js +13 -0
  45. package/_shims/index.mjs +7 -0
  46. package/_shims/manual-types.d.ts +12 -0
  47. package/_shims/manual-types.js +3 -0
  48. package/_shims/manual-types.mjs +3 -0
  49. package/_shims/node-runtime.d.ts +3 -0
  50. package/_shims/node-runtime.d.ts.map +1 -0
  51. package/_shims/node-runtime.js +90 -0
  52. package/_shims/node-runtime.js.map +1 -0
  53. package/_shims/node-runtime.mjs +56 -0
  54. package/_shims/node-runtime.mjs.map +1 -0
  55. package/_shims/node-types.d.ts +42 -0
  56. package/_shims/node-types.js +3 -0
  57. package/_shims/node-types.mjs +3 -0
  58. package/_shims/registry.d.ts +37 -0
  59. package/_shims/registry.d.ts.map +1 -0
  60. package/_shims/registry.js +41 -0
  61. package/_shims/registry.js.map +1 -0
  62. package/_shims/registry.mjs +37 -0
  63. package/_shims/registry.mjs.map +1 -0
  64. package/_shims/web-runtime.d.ts +5 -0
  65. package/_shims/web-runtime.d.ts.map +1 -0
  66. package/_shims/web-runtime.js +78 -0
  67. package/_shims/web-runtime.js.map +1 -0
  68. package/_shims/web-runtime.mjs +71 -0
  69. package/_shims/web-runtime.mjs.map +1 -0
  70. package/_shims/web-types.d.ts +83 -0
  71. package/_shims/web-types.js +3 -0
  72. package/_shims/web-types.mjs +3 -0
  73. package/core.d.ts +237 -0
  74. package/core.d.ts.map +1 -0
  75. package/core.js +868 -0
  76. package/core.js.map +1 -0
  77. package/core.mjs +837 -0
  78. package/core.mjs.map +1 -0
  79. package/error.d.ts +53 -0
  80. package/error.d.ts.map +1 -0
  81. package/error.js +143 -0
  82. package/error.js.map +1 -0
  83. package/error.mjs +127 -0
  84. package/error.mjs.map +1 -0
  85. package/index.d.mts +114 -0
  86. package/index.d.ts +114 -0
  87. package/index.d.ts.map +1 -0
  88. package/index.js +119 -0
  89. package/index.js.map +1 -0
  90. package/index.mjs +91 -0
  91. package/index.mjs.map +1 -0
  92. package/lib/core/cli.d.ts +21 -0
  93. package/lib/core/cli.d.ts.map +1 -0
  94. package/lib/core/cli.js +90 -0
  95. package/lib/core/cli.js.map +1 -0
  96. package/lib/core/cli.mjs +65 -0
  97. package/lib/core/cli.mjs.map +1 -0
  98. package/lib/core/openai-monitor.d.ts +54 -0
  99. package/lib/core/openai-monitor.d.ts.map +1 -0
  100. package/lib/core/openai-monitor.js +376 -0
  101. package/lib/core/openai-monitor.js.map +1 -0
  102. package/lib/core/openai-monitor.mjs +371 -0
  103. package/lib/core/openai-monitor.mjs.map +1 -0
  104. package/package.json +102 -6
  105. package/resource.d.ts +6 -0
  106. package/resource.d.ts.map +1 -0
  107. package/resource.js +11 -0
  108. package/resource.js.map +1 -0
  109. package/resource.mjs +7 -0
  110. package/resource.mjs.map +1 -0
  111. package/resources/commits/commits.d.ts +11 -0
  112. package/resources/commits/commits.d.ts.map +1 -0
  113. package/resources/commits/commits.js +40 -0
  114. package/resources/commits/commits.js.map +1 -0
  115. package/resources/commits/commits.mjs +13 -0
  116. package/resources/commits/commits.mjs.map +1 -0
  117. package/resources/commits/index.d.ts +3 -0
  118. package/resources/commits/index.d.ts.map +1 -0
  119. package/resources/commits/index.js +9 -0
  120. package/resources/commits/index.js.map +1 -0
  121. package/resources/commits/index.mjs +4 -0
  122. package/resources/commits/index.mjs.map +1 -0
  123. package/resources/commits/test-results.d.ts +217 -0
  124. package/resources/commits/test-results.d.ts.map +1 -0
  125. package/resources/commits/test-results.js +18 -0
  126. package/resources/commits/test-results.js.map +1 -0
  127. package/resources/commits/test-results.mjs +14 -0
  128. package/resources/commits/test-results.mjs.map +1 -0
  129. package/resources/index.d.ts +4 -0
  130. package/resources/index.d.ts.map +1 -0
  131. package/resources/index.js +11 -0
  132. package/resources/index.js.map +1 -0
  133. package/resources/index.mjs +5 -0
  134. package/resources/index.mjs.map +1 -0
  135. package/resources/inference-pipelines/data.d.ts +228 -0
  136. package/resources/inference-pipelines/data.d.ts.map +1 -0
  137. package/resources/inference-pipelines/data.js +17 -0
  138. package/resources/inference-pipelines/data.js.map +1 -0
  139. package/resources/inference-pipelines/data.mjs +13 -0
  140. package/resources/inference-pipelines/data.mjs.map +1 -0
  141. package/resources/inference-pipelines/index.d.ts +4 -0
  142. package/resources/inference-pipelines/index.d.ts.map +1 -0
  143. package/resources/inference-pipelines/index.js +11 -0
  144. package/resources/inference-pipelines/index.js.map +1 -0
  145. package/resources/inference-pipelines/index.mjs +5 -0
  146. package/resources/inference-pipelines/index.mjs.map +1 -0
  147. package/resources/inference-pipelines/inference-pipelines.d.ts +16 -0
  148. package/resources/inference-pipelines/inference-pipelines.d.ts.map +1 -0
  149. package/resources/inference-pipelines/inference-pipelines.js +43 -0
  150. package/resources/inference-pipelines/inference-pipelines.js.map +1 -0
  151. package/resources/inference-pipelines/inference-pipelines.mjs +16 -0
  152. package/resources/inference-pipelines/inference-pipelines.mjs.map +1 -0
  153. package/resources/inference-pipelines/test-results.d.ts +217 -0
  154. package/resources/inference-pipelines/test-results.d.ts.map +1 -0
  155. package/resources/inference-pipelines/test-results.js +18 -0
  156. package/resources/inference-pipelines/test-results.js.map +1 -0
  157. package/resources/inference-pipelines/test-results.mjs +14 -0
  158. package/resources/inference-pipelines/test-results.mjs.map +1 -0
  159. package/resources/projects/commits.d.ts +171 -0
  160. package/resources/projects/commits.d.ts.map +1 -0
  161. package/resources/projects/commits.js +18 -0
  162. package/resources/projects/commits.js.map +1 -0
  163. package/resources/projects/commits.mjs +14 -0
  164. package/resources/projects/commits.mjs.map +1 -0
  165. package/resources/projects/index.d.ts +4 -0
  166. package/resources/projects/index.d.ts.map +1 -0
  167. package/resources/projects/index.js +11 -0
  168. package/resources/projects/index.js.map +1 -0
  169. package/resources/projects/index.mjs +5 -0
  170. package/resources/projects/index.mjs.map +1 -0
  171. package/resources/projects/inference-pipelines.d.ts +121 -0
  172. package/resources/projects/inference-pipelines.d.ts.map +1 -0
  173. package/resources/projects/inference-pipelines.js +18 -0
  174. package/resources/projects/inference-pipelines.js.map +1 -0
  175. package/resources/projects/inference-pipelines.mjs +14 -0
  176. package/resources/projects/inference-pipelines.mjs.map +1 -0
  177. package/resources/projects/projects.d.ts +172 -0
  178. package/resources/projects/projects.d.ts.map +1 -0
  179. package/resources/projects/projects.js +50 -0
  180. package/resources/projects/projects.js.map +1 -0
  181. package/resources/projects/projects.mjs +23 -0
  182. package/resources/projects/projects.mjs.map +1 -0
  183. package/shims/node.d.ts +29 -0
  184. package/shims/node.d.ts.map +1 -0
  185. package/shims/node.js +31 -0
  186. package/shims/node.js.map +1 -0
  187. package/shims/node.mjs +5 -0
  188. package/shims/node.mjs.map +1 -0
  189. package/shims/web.d.ts +26 -0
  190. package/shims/web.d.ts.map +1 -0
  191. package/shims/web.js +31 -0
  192. package/shims/web.js.map +1 -0
  193. package/shims/web.mjs +5 -0
  194. package/shims/web.mjs.map +1 -0
  195. package/src/_shims/MultipartBody.ts +9 -0
  196. package/src/_shims/README.md +46 -0
  197. package/src/_shims/auto/runtime-bun.ts +4 -0
  198. package/src/_shims/auto/runtime-node.ts +4 -0
  199. package/src/_shims/auto/runtime.ts +4 -0
  200. package/src/_shims/auto/types-node.ts +4 -0
  201. package/src/_shims/auto/types.d.ts +101 -0
  202. package/src/_shims/auto/types.js +3 -0
  203. package/src/_shims/auto/types.mjs +3 -0
  204. package/src/_shims/bun-runtime.ts +14 -0
  205. package/src/_shims/index.d.ts +81 -0
  206. package/src/_shims/index.js +13 -0
  207. package/src/_shims/index.mjs +7 -0
  208. package/src/_shims/manual-types.d.ts +12 -0
  209. package/src/_shims/manual-types.js +3 -0
  210. package/src/_shims/manual-types.mjs +3 -0
  211. package/src/_shims/node-runtime.ts +83 -0
  212. package/src/_shims/node-types.d.ts +42 -0
  213. package/src/_shims/node-types.js +3 -0
  214. package/src/_shims/node-types.mjs +3 -0
  215. package/src/_shims/registry.ts +67 -0
  216. package/src/_shims/web-runtime.ts +103 -0
  217. package/src/_shims/web-types.d.ts +83 -0
  218. package/src/_shims/web-types.js +3 -0
  219. package/src/_shims/web-types.mjs +3 -0
  220. package/src/core.ts +1146 -0
  221. package/src/error.ts +146 -0
  222. package/src/index.ts +199 -0
  223. package/src/lib/.keep +4 -0
  224. package/src/lib/core/cli.ts +96 -0
  225. package/src/lib/core/index.d.ts +2 -0
  226. package/src/lib/core/openai-monitor.ts +470 -0
  227. package/src/lib/index.d.ts +1 -0
  228. package/src/resource.ts +11 -0
  229. package/src/resources/commits/commits.ts +14 -0
  230. package/src/resources/commits/index.ts +4 -0
  231. package/src/resources/commits/test-results.ts +284 -0
  232. package/src/resources/index.ts +5 -0
  233. package/src/resources/inference-pipelines/data.ts +285 -0
  234. package/src/resources/inference-pipelines/index.ts +5 -0
  235. package/src/resources/inference-pipelines/inference-pipelines.ts +19 -0
  236. package/src/resources/inference-pipelines/test-results.ts +284 -0
  237. package/src/resources/projects/commits.ts +226 -0
  238. package/src/resources/projects/index.ts +9 -0
  239. package/src/resources/projects/inference-pipelines.ts +165 -0
  240. package/src/resources/projects/projects.ts +232 -0
  241. package/src/shims/node.ts +50 -0
  242. package/src/shims/web.ts +50 -0
  243. package/src/tsconfig.json +11 -0
  244. package/src/uploads.ts +248 -0
  245. package/src/version.ts +1 -0
  246. package/uploads.d.ts +75 -0
  247. package/uploads.d.ts.map +1 -0
  248. package/uploads.js +165 -0
  249. package/uploads.js.map +1 -0
  250. package/uploads.mjs +152 -0
  251. package/uploads.mjs.map +1 -0
  252. package/version.d.ts +2 -0
  253. package/version.d.ts.map +1 -0
  254. package/version.js +5 -0
  255. package/version.js.map +1 -0
  256. package/version.mjs +2 -0
  257. package/version.mjs.map +1 -0
package/src/error.ts ADDED
@@ -0,0 +1,146 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { castToError, Headers } from './core';
4
+
5
+ export class OpenlayerError extends Error {}
6
+
7
+ export class APIError extends OpenlayerError {
8
+ readonly status: number | undefined;
9
+ readonly headers: Headers | undefined;
10
+ readonly error: Object | undefined;
11
+
12
+ constructor(
13
+ status: number | undefined,
14
+ error: Object | undefined,
15
+ message: string | undefined,
16
+ headers: Headers | undefined,
17
+ ) {
18
+ super(`${APIError.makeMessage(status, error, message)}`);
19
+ this.status = status;
20
+ this.headers = headers;
21
+ this.error = error;
22
+ }
23
+
24
+ private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
25
+ const msg =
26
+ error?.message ?
27
+ typeof error.message === 'string' ?
28
+ error.message
29
+ : JSON.stringify(error.message)
30
+ : error ? JSON.stringify(error)
31
+ : message;
32
+
33
+ if (status && msg) {
34
+ return `${status} ${msg}`;
35
+ }
36
+ if (status) {
37
+ return `${status} status code (no body)`;
38
+ }
39
+ if (msg) {
40
+ return msg;
41
+ }
42
+ return '(no status code or body)';
43
+ }
44
+
45
+ static generate(
46
+ status: number | undefined,
47
+ errorResponse: Object | undefined,
48
+ message: string | undefined,
49
+ headers: Headers | undefined,
50
+ ) {
51
+ if (!status) {
52
+ return new APIConnectionError({ cause: castToError(errorResponse) });
53
+ }
54
+
55
+ const error = errorResponse as Record<string, any>;
56
+
57
+ if (status === 400) {
58
+ return new BadRequestError(status, error, message, headers);
59
+ }
60
+
61
+ if (status === 401) {
62
+ return new AuthenticationError(status, error, message, headers);
63
+ }
64
+
65
+ if (status === 403) {
66
+ return new PermissionDeniedError(status, error, message, headers);
67
+ }
68
+
69
+ if (status === 404) {
70
+ return new NotFoundError(status, error, message, headers);
71
+ }
72
+
73
+ if (status === 409) {
74
+ return new ConflictError(status, error, message, headers);
75
+ }
76
+
77
+ if (status === 422) {
78
+ return new UnprocessableEntityError(status, error, message, headers);
79
+ }
80
+
81
+ if (status === 429) {
82
+ return new RateLimitError(status, error, message, headers);
83
+ }
84
+
85
+ if (status >= 500) {
86
+ return new InternalServerError(status, error, message, headers);
87
+ }
88
+
89
+ return new APIError(status, error, message, headers);
90
+ }
91
+ }
92
+
93
+ export class APIUserAbortError extends APIError {
94
+ override readonly status: undefined = undefined;
95
+
96
+ constructor({ message }: { message?: string } = {}) {
97
+ super(undefined, undefined, message || 'Request was aborted.', undefined);
98
+ }
99
+ }
100
+
101
+ export class APIConnectionError extends APIError {
102
+ override readonly status: undefined = undefined;
103
+
104
+ constructor({ message, cause }: { message?: string; cause?: Error | undefined }) {
105
+ super(undefined, undefined, message || 'Connection error.', undefined);
106
+ // in some environments the 'cause' property is already declared
107
+ // @ts-ignore
108
+ if (cause) this.cause = cause;
109
+ }
110
+ }
111
+
112
+ export class APIConnectionTimeoutError extends APIConnectionError {
113
+ constructor({ message }: { message?: string } = {}) {
114
+ super({ message: message ?? 'Request timed out.' });
115
+ }
116
+ }
117
+
118
+ export class BadRequestError extends APIError {
119
+ override readonly status: 400 = 400;
120
+ }
121
+
122
+ export class AuthenticationError extends APIError {
123
+ override readonly status: 401 = 401;
124
+ }
125
+
126
+ export class PermissionDeniedError extends APIError {
127
+ override readonly status: 403 = 403;
128
+ }
129
+
130
+ export class NotFoundError extends APIError {
131
+ override readonly status: 404 = 404;
132
+ }
133
+
134
+ export class ConflictError extends APIError {
135
+ override readonly status: 409 = 409;
136
+ }
137
+
138
+ export class UnprocessableEntityError extends APIError {
139
+ override readonly status: 422 = 422;
140
+ }
141
+
142
+ export class RateLimitError extends APIError {
143
+ override readonly status: 429 = 429;
144
+ }
145
+
146
+ export class InternalServerError extends APIError {}
package/src/index.ts ADDED
@@ -0,0 +1,199 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Core from './core';
4
+ import * as Errors from './error';
5
+ import { type Agent } from './_shims/index';
6
+ import * as Uploads from './uploads';
7
+ import * as API from './resources/index';
8
+
9
+ export interface ClientOptions {
10
+ /**
11
+ * Defaults to process.env['OPENLAYER_API_KEY'].
12
+ */
13
+ apiKey?: string | null | undefined;
14
+
15
+ /**
16
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
17
+ *
18
+ * Defaults to process.env['OPENLAYER_BASE_URL'].
19
+ */
20
+ baseURL?: string | null | undefined;
21
+
22
+ /**
23
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
24
+ * from the server before timing out a single request.
25
+ *
26
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
27
+ * much longer than this timeout before the promise succeeds or fails.
28
+ */
29
+ timeout?: number;
30
+
31
+ /**
32
+ * An HTTP agent used to manage HTTP(S) connections.
33
+ *
34
+ * If not provided, an agent will be constructed by default in the Node.js environment,
35
+ * otherwise no agent is used.
36
+ */
37
+ httpAgent?: Agent;
38
+
39
+ /**
40
+ * Specify a custom `fetch` function implementation.
41
+ *
42
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
43
+ * defined globally.
44
+ */
45
+ fetch?: Core.Fetch | undefined;
46
+
47
+ /**
48
+ * The maximum number of times that the client will retry a request in case of a
49
+ * temporary failure, like a network error or a 5XX error from the server.
50
+ *
51
+ * @default 2
52
+ */
53
+ maxRetries?: number;
54
+
55
+ /**
56
+ * Default headers to include with every request to the API.
57
+ *
58
+ * These can be removed in individual requests by explicitly setting the
59
+ * header to `undefined` or `null` in request options.
60
+ */
61
+ defaultHeaders?: Core.Headers;
62
+
63
+ /**
64
+ * Default query parameters to include with every request to the API.
65
+ *
66
+ * These can be removed in individual requests by explicitly setting the
67
+ * param to `undefined` in request options.
68
+ */
69
+ defaultQuery?: Core.DefaultQuery;
70
+ }
71
+
72
+ /** API Client for interfacing with the Openlayer API. */
73
+ export class Openlayer extends Core.APIClient {
74
+ apiKey: string | null;
75
+
76
+ private _options: ClientOptions;
77
+
78
+ /**
79
+ * API Client for interfacing with the Openlayer API.
80
+ *
81
+ * @param {string | null | undefined} [opts.apiKey=process.env['OPENLAYER_API_KEY'] ?? null]
82
+ * @param {string} [opts.baseURL=process.env['OPENLAYER_BASE_URL'] ?? https://api.openlayer.com/v1] - Override the default base URL for the API.
83
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
84
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
85
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
86
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
87
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
88
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
89
+ */
90
+ constructor({
91
+ baseURL = Core.readEnv('OPENLAYER_BASE_URL'),
92
+ apiKey = Core.readEnv('OPENLAYER_API_KEY') ?? null,
93
+ ...opts
94
+ }: ClientOptions = {}) {
95
+ const options: ClientOptions = {
96
+ apiKey,
97
+ ...opts,
98
+ baseURL: baseURL || `https://api.openlayer.com/v1`,
99
+ };
100
+
101
+ super({
102
+ baseURL: options.baseURL!,
103
+ timeout: options.timeout ?? 60000 /* 1 minute */,
104
+ httpAgent: options.httpAgent,
105
+ maxRetries: options.maxRetries,
106
+ fetch: options.fetch,
107
+ });
108
+ this._options = options;
109
+
110
+ this.apiKey = apiKey;
111
+ }
112
+
113
+ projects: API.Projects = new API.Projects(this);
114
+ commits: API.Commits = new API.Commits(this);
115
+ inferencePipelines: API.InferencePipelines = new API.InferencePipelines(this);
116
+
117
+ protected override defaultQuery(): Core.DefaultQuery | undefined {
118
+ return this._options.defaultQuery;
119
+ }
120
+
121
+ protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
122
+ return {
123
+ ...super.defaultHeaders(opts),
124
+ ...this._options.defaultHeaders,
125
+ };
126
+ }
127
+
128
+ protected override validateHeaders(headers: Core.Headers, customHeaders: Core.Headers) {
129
+ if (this.apiKey && headers['authorization']) {
130
+ return;
131
+ }
132
+ if (customHeaders['authorization'] === null) {
133
+ return;
134
+ }
135
+
136
+ throw new Error(
137
+ 'Could not resolve authentication method. Expected the apiKey to be set. Or for the "Authorization" headers to be explicitly omitted',
138
+ );
139
+ }
140
+
141
+ protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
142
+ if (this.apiKey == null) {
143
+ return {};
144
+ }
145
+ return { Authorization: `Bearer ${this.apiKey}` };
146
+ }
147
+
148
+ static Openlayer = this;
149
+
150
+ static OpenlayerError = Errors.OpenlayerError;
151
+ static APIError = Errors.APIError;
152
+ static APIConnectionError = Errors.APIConnectionError;
153
+ static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
154
+ static APIUserAbortError = Errors.APIUserAbortError;
155
+ static NotFoundError = Errors.NotFoundError;
156
+ static ConflictError = Errors.ConflictError;
157
+ static RateLimitError = Errors.RateLimitError;
158
+ static BadRequestError = Errors.BadRequestError;
159
+ static AuthenticationError = Errors.AuthenticationError;
160
+ static InternalServerError = Errors.InternalServerError;
161
+ static PermissionDeniedError = Errors.PermissionDeniedError;
162
+ static UnprocessableEntityError = Errors.UnprocessableEntityError;
163
+
164
+ static toFile = Uploads.toFile;
165
+ static fileFromPath = Uploads.fileFromPath;
166
+ }
167
+
168
+ export const {
169
+ OpenlayerError,
170
+ APIError,
171
+ APIConnectionError,
172
+ APIConnectionTimeoutError,
173
+ APIUserAbortError,
174
+ NotFoundError,
175
+ ConflictError,
176
+ RateLimitError,
177
+ BadRequestError,
178
+ AuthenticationError,
179
+ InternalServerError,
180
+ PermissionDeniedError,
181
+ UnprocessableEntityError,
182
+ } = Errors;
183
+
184
+ export import toFile = Uploads.toFile;
185
+ export import fileFromPath = Uploads.fileFromPath;
186
+
187
+ export namespace Openlayer {
188
+ export import RequestOptions = Core.RequestOptions;
189
+
190
+ export import Projects = API.Projects;
191
+ export import ProjectListResponse = API.ProjectListResponse;
192
+ export import ProjectListParams = API.ProjectListParams;
193
+
194
+ export import Commits = API.Commits;
195
+
196
+ export import InferencePipelines = API.InferencePipelines;
197
+ }
198
+
199
+ export default Openlayer;
package/src/lib/.keep ADDED
@@ -0,0 +1,4 @@
1
+ File generated from our OpenAPI spec by Stainless.
2
+
3
+ This directory can be used to store custom files to expand the SDK.
4
+ It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
@@ -0,0 +1,96 @@
1
+ /*
2
+ * Description: This file contains the CLIHandler class which is responsible
3
+ * For handling the CLI input and output.
4
+ *
5
+ * Example Usage:
6
+ * // Initialize CLI handler with the user's model run method
7
+ * const cliHandler = new CLIHandler(model.run.bind(model));
8
+ *
9
+ * // Setup CLI and process dataset
10
+ * cliHandler.runFromCLI();
11
+ */
12
+
13
+ import { program } from 'commander';
14
+ import * as fs from 'fs';
15
+ import * as path from 'path';
16
+
17
+ // Define shared interfaces and utilities here
18
+ export interface RunReturn {
19
+ otherFields: { [key: string]: any };
20
+ output: any;
21
+ }
22
+
23
+ // Define an interface for the configuration object
24
+ export interface Config {
25
+ inputVariableNames?: string[];
26
+ metadata: {
27
+ outputTimestamp: number;
28
+ };
29
+ outputColumnName: string;
30
+ }
31
+
32
+ class CLIHandler {
33
+ private run: (...args: any[]) => Promise<any>;
34
+
35
+ constructor(runFunction: (...args: any[]) => Promise<any>) {
36
+ this.run = runFunction;
37
+ }
38
+
39
+ public runFromCLI() {
40
+ program
41
+ .requiredOption('--dataset-path <path>', 'Path to the dataset')
42
+ .requiredOption('--output-dir <path>', 'Directory to place results');
43
+
44
+ program.parse(process.argv);
45
+
46
+ const options = program.opts();
47
+ const { datasetPath, outputDir } = options;
48
+
49
+ // Load dataset
50
+ const datasetFullPath = path.resolve(datasetPath);
51
+ const rawData = fs.readFileSync(datasetFullPath, 'utf8');
52
+ const dataset = JSON.parse(rawData);
53
+
54
+ // Process each item in the dataset dynamically
55
+ Promise.all(
56
+ dataset.map(async (item: any) => {
57
+ const result = await this.run(item);
58
+ // Merge the original item fields with the result
59
+ return { ...item, ...result.otherFields, output: result.output };
60
+ }),
61
+ )
62
+ .then((results) => {
63
+ /*
64
+ * Wait for all rows to be run
65
+ * Write results now to output dir or log to console
66
+ */
67
+ this.writeOutput(results, outputDir);
68
+ console.log('Results processing completed. Check console for output.');
69
+ })
70
+ .catch((err) => {
71
+ console.error(`Error processing dataset: ${err}`);
72
+ });
73
+ }
74
+
75
+ private writeOutput(results: RunReturn[], outputDir: string) {
76
+ const config: Config = {
77
+ metadata: { outputTimestamp: Date.now() },
78
+ outputColumnName: 'output',
79
+ };
80
+
81
+ // Construct an output directory {outputDir}/{datasetName}/
82
+ const outputDirPath = path.resolve(outputDir);
83
+ fs.mkdirSync(outputDirPath, { recursive: true });
84
+
85
+ const datasetPath = path.join(outputDirPath, 'dataset.json');
86
+ const configPath = path.join(outputDirPath, 'config.json');
87
+
88
+ fs.writeFileSync(datasetPath, JSON.stringify(results, null, 4), 'utf8');
89
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 4), 'utf8');
90
+
91
+ console.info(`Output written to ${datasetPath}`);
92
+ console.info(`Config written to ${configPath}`);
93
+ }
94
+ }
95
+
96
+ export default CLIHandler;
@@ -0,0 +1,2 @@
1
+ export * as cli from './cli';
2
+ export * as openAiMonitor from './openai-monitor';