cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.0.0-beta.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/resources/ai-gateway/datasets.ts

549lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { APIResource } from '../../resource';
4import { isRequestOptions } from '../../core';
5import * as Core from '../../core';
6import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination';
7
8export class Datasets extends APIResource {
9 /**
10 * Creates a new AI Gateway.
11 *
12 * @example
13 * ```ts
14 * const dataset = await client.aiGateway.datasets.create(
15 * 'my-gateway',
16 * {
17 * account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0',
18 * enable: true,
19 * filters: [
20 * {
21 * key: 'created_at',
22 * operator: 'eq',
23 * value: ['string'],
24 * },
25 * ],
26 * name: 'name',
27 * },
28 * );
29 * ```
30 */
31 create(
32 gatewayId: string,
33 params: DatasetCreateParams,
34 options?: Core.RequestOptions,
35 ): Core.APIPromise<DatasetCreateResponse> {
36 const { account_id = this._client.accountId, ...body } = params;
37 return (
38 this._client.post(`/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/datasets`, {
39 body,
40 ...options,
41 }) as Core.APIPromise<{ result: DatasetCreateResponse }>
42 )._thenUnwrap((obj) => obj.result);
43 }
44
45 /**
46 * Updates an existing AI Gateway dataset.
47 *
48 * @example
49 * ```ts
50 * const dataset = await client.aiGateway.datasets.update(
51 * 'my-gateway',
52 * 'id',
53 * {
54 * account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0',
55 * enable: true,
56 * filters: [
57 * {
58 * key: 'created_at',
59 * operator: 'eq',
60 * value: ['string'],
61 * },
62 * ],
63 * name: 'name',
64 * },
65 * );
66 * ```
67 */
68 update(
69 gatewayId: string,
70 id: string,
71 params: DatasetUpdateParams,
72 options?: Core.RequestOptions,
73 ): Core.APIPromise<DatasetUpdateResponse> {
74 const { account_id = this._client.accountId, ...body } = params;
75 return (
76 this._client.put(`/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/datasets/${id}`, {
77 body,
78 ...options,
79 }) as Core.APIPromise<{ result: DatasetUpdateResponse }>
80 )._thenUnwrap((obj) => obj.result);
81 }
82
83 /**
84 * Lists all AI Gateway evaluator types configured for the account.
85 *
86 * @example
87 * ```ts
88 * // Automatically fetches more pages as needed.
89 * for await (const datasetListResponse of client.aiGateway.datasets.list(
90 * 'my-gateway',
91 * { account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0' },
92 * )) {
93 * // ...
94 * }
95 * ```
96 */
97 list(
98 gatewayId: string,
99 params?: DatasetListParams,
100 options?: Core.RequestOptions,
101 ): Core.PagePromise<DatasetListResponsesV4PagePaginationArray, DatasetListResponse>;
102 list(
103 gatewayId: string,
104 options?: Core.RequestOptions,
105 ): Core.PagePromise<DatasetListResponsesV4PagePaginationArray, DatasetListResponse>;
106 list(
107 gatewayId: string,
108 params: DatasetListParams | Core.RequestOptions = {},
109 options?: Core.RequestOptions,
110 ): Core.PagePromise<DatasetListResponsesV4PagePaginationArray, DatasetListResponse> {
111 if (isRequestOptions(params)) {
112 return this.list(gatewayId, {}, params);
113 }
114 const { account_id = this._client.accountId, ...query } = params;
115 return this._client.getAPIList(
116 `/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/datasets`,
117 DatasetListResponsesV4PagePaginationArray,
118 { query, ...options },
119 );
120 }
121
122 /**
123 * Deletes an AI Gateway dataset.
124 *
125 * @example
126 * ```ts
127 * const dataset = await client.aiGateway.datasets.delete(
128 * 'my-gateway',
129 * 'id',
130 * { account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0' },
131 * );
132 * ```
133 */
134 delete(
135 gatewayId: string,
136 id: string,
137 params?: DatasetDeleteParams,
138 options?: Core.RequestOptions,
139 ): Core.APIPromise<DatasetDeleteResponse>;
140 delete(
141 gatewayId: string,
142 id: string,
143 options?: Core.RequestOptions,
144 ): Core.APIPromise<DatasetDeleteResponse>;
145 delete(
146 gatewayId: string,
147 id: string,
148 params: DatasetDeleteParams | Core.RequestOptions = {},
149 options?: Core.RequestOptions,
150 ): Core.APIPromise<DatasetDeleteResponse> {
151 if (isRequestOptions(params)) {
152 return this.delete(gatewayId, id, {}, params);
153 }
154 const { account_id = this._client.accountId } = params;
155 return (
156 this._client.delete(
157 `/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/datasets/${id}`,
158 options,
159 ) as Core.APIPromise<{ result: DatasetDeleteResponse }>
160 )._thenUnwrap((obj) => obj.result);
161 }
162
163 /**
164 * Retrieves details for a specific AI Gateway dataset.
165 *
166 * @example
167 * ```ts
168 * const dataset = await client.aiGateway.datasets.get(
169 * 'my-gateway',
170 * 'id',
171 * { account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0' },
172 * );
173 * ```
174 */
175 get(
176 gatewayId: string,
177 id: string,
178 params?: DatasetGetParams,
179 options?: Core.RequestOptions,
180 ): Core.APIPromise<DatasetGetResponse>;
181 get(gatewayId: string, id: string, options?: Core.RequestOptions): Core.APIPromise<DatasetGetResponse>;
182 get(
183 gatewayId: string,
184 id: string,
185 params: DatasetGetParams | Core.RequestOptions = {},
186 options?: Core.RequestOptions,
187 ): Core.APIPromise<DatasetGetResponse> {
188 if (isRequestOptions(params)) {
189 return this.get(gatewayId, id, {}, params);
190 }
191 const { account_id = this._client.accountId } = params;
192 return (
193 this._client.get(
194 `/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/datasets/${id}`,
195 options,
196 ) as Core.APIPromise<{ result: DatasetGetResponse }>
197 )._thenUnwrap((obj) => obj.result);
198 }
199}
200
201export class DatasetListResponsesV4PagePaginationArray extends V4PagePaginationArray<DatasetListResponse> {}
202
203export interface DatasetCreateResponse {
204 id: string;
205
206 created_at: string;
207
208 enable: boolean;
209
210 filters: Array<DatasetCreateResponse.Filter>;
211
212 /**
213 * gateway id
214 */
215 gateway_id: string;
216
217 modified_at: string;
218
219 name: string;
220}
221
222export namespace DatasetCreateResponse {
223 export interface Filter {
224 key:
225 | 'created_at'
226 | 'request_content_type'
227 | 'response_content_type'
228 | 'success'
229 | 'cached'
230 | 'provider'
231 | 'model'
232 | 'cost'
233 | 'tokens'
234 | 'tokens_in'
235 | 'tokens_out'
236 | 'duration'
237 | 'feedback';
238
239 operator: 'eq' | 'contains' | 'lt' | 'gt';
240
241 value: Array<string | number | boolean>;
242 }
243}
244
245export interface DatasetUpdateResponse {
246 id: string;
247
248 created_at: string;
249
250 enable: boolean;
251
252 filters: Array<DatasetUpdateResponse.Filter>;
253
254 /**
255 * gateway id
256 */
257 gateway_id: string;
258
259 modified_at: string;
260
261 name: string;
262}
263
264export namespace DatasetUpdateResponse {
265 export interface Filter {
266 key:
267 | 'created_at'
268 | 'request_content_type'
269 | 'response_content_type'
270 | 'success'
271 | 'cached'
272 | 'provider'
273 | 'model'
274 | 'cost'
275 | 'tokens'
276 | 'tokens_in'
277 | 'tokens_out'
278 | 'duration'
279 | 'feedback';
280
281 operator: 'eq' | 'contains' | 'lt' | 'gt';
282
283 value: Array<string | number | boolean>;
284 }
285}
286
287export interface DatasetListResponse {
288 id: string;
289
290 created_at: string;
291
292 enable: boolean;
293
294 filters: Array<DatasetListResponse.Filter>;
295
296 /**
297 * gateway id
298 */
299 gateway_id: string;
300
301 modified_at: string;
302
303 name: string;
304}
305
306export namespace DatasetListResponse {
307 export interface Filter {
308 key:
309 | 'created_at'
310 | 'request_content_type'
311 | 'response_content_type'
312 | 'success'
313 | 'cached'
314 | 'provider'
315 | 'model'
316 | 'cost'
317 | 'tokens'
318 | 'tokens_in'
319 | 'tokens_out'
320 | 'duration'
321 | 'feedback';
322
323 operator: 'eq' | 'contains' | 'lt' | 'gt';
324
325 value: Array<string | number | boolean>;
326 }
327}
328
329export interface DatasetDeleteResponse {
330 id: string;
331
332 created_at: string;
333
334 enable: boolean;
335
336 filters: Array<DatasetDeleteResponse.Filter>;
337
338 /**
339 * gateway id
340 */
341 gateway_id: string;
342
343 modified_at: string;
344
345 name: string;
346}
347
348export namespace DatasetDeleteResponse {
349 export interface Filter {
350 key:
351 | 'created_at'
352 | 'request_content_type'
353 | 'response_content_type'
354 | 'success'
355 | 'cached'
356 | 'provider'
357 | 'model'
358 | 'cost'
359 | 'tokens'
360 | 'tokens_in'
361 | 'tokens_out'
362 | 'duration'
363 | 'feedback';
364
365 operator: 'eq' | 'contains' | 'lt' | 'gt';
366
367 value: Array<string | number | boolean>;
368 }
369}
370
371export interface DatasetGetResponse {
372 id: string;
373
374 created_at: string;
375
376 enable: boolean;
377
378 filters: Array<DatasetGetResponse.Filter>;
379
380 /**
381 * gateway id
382 */
383 gateway_id: string;
384
385 modified_at: string;
386
387 name: string;
388}
389
390export namespace DatasetGetResponse {
391 export interface Filter {
392 key:
393 | 'created_at'
394 | 'request_content_type'
395 | 'response_content_type'
396 | 'success'
397 | 'cached'
398 | 'provider'
399 | 'model'
400 | 'cost'
401 | 'tokens'
402 | 'tokens_in'
403 | 'tokens_out'
404 | 'duration'
405 | 'feedback';
406
407 operator: 'eq' | 'contains' | 'lt' | 'gt';
408
409 value: Array<string | number | boolean>;
410 }
411}
412
413export interface DatasetCreateParams {
414 /**
415 * Path param
416 */
417 account_id?: string;
418
419 /**
420 * Body param
421 */
422 enable: boolean;
423
424 /**
425 * Body param
426 */
427 filters: Array<DatasetCreateParams.Filter>;
428
429 /**
430 * Body param
431 */
432 name: string;
433}
434
435export namespace DatasetCreateParams {
436 export interface Filter {
437 key:
438 | 'created_at'
439 | 'request_content_type'
440 | 'response_content_type'
441 | 'success'
442 | 'cached'
443 | 'provider'
444 | 'model'
445 | 'cost'
446 | 'tokens'
447 | 'tokens_in'
448 | 'tokens_out'
449 | 'duration'
450 | 'feedback';
451
452 operator: 'eq' | 'contains' | 'lt' | 'gt';
453
454 value: Array<string | number | boolean>;
455 }
456}
457
458export interface DatasetUpdateParams {
459 /**
460 * Path param
461 */
462 account_id?: string;
463
464 /**
465 * Body param
466 */
467 enable: boolean;
468
469 /**
470 * Body param
471 */
472 filters: Array<DatasetUpdateParams.Filter>;
473
474 /**
475 * Body param
476 */
477 name: string;
478}
479
480export namespace DatasetUpdateParams {
481 export interface Filter {
482 key:
483 | 'created_at'
484 | 'request_content_type'
485 | 'response_content_type'
486 | 'success'
487 | 'cached'
488 | 'provider'
489 | 'model'
490 | 'cost'
491 | 'tokens'
492 | 'tokens_in'
493 | 'tokens_out'
494 | 'duration'
495 | 'feedback';
496
497 operator: 'eq' | 'contains' | 'lt' | 'gt';
498
499 value: Array<string | number | boolean>;
500 }
501}
502
503export interface DatasetListParams extends V4PagePaginationArrayParams {
504 /**
505 * Path param
506 */
507 account_id?: string;
508
509 /**
510 * Query param
511 */
512 enable?: boolean;
513
514 /**
515 * Query param
516 */
517 name?: string;
518
519 /**
520 * Query param: Search by id, name, filters
521 */
522 search?: string;
523}
524
525export interface DatasetDeleteParams {
526 account_id?: string;
527}
528
529export interface DatasetGetParams {
530 account_id?: string;
531}
532
533Datasets.DatasetListResponsesV4PagePaginationArray = DatasetListResponsesV4PagePaginationArray;
534
535export declare namespace Datasets {
536 export {
537 type DatasetCreateResponse as DatasetCreateResponse,
538 type DatasetUpdateResponse as DatasetUpdateResponse,
539 type DatasetListResponse as DatasetListResponse,
540 type DatasetDeleteResponse as DatasetDeleteResponse,
541 type DatasetGetResponse as DatasetGetResponse,
542 DatasetListResponsesV4PagePaginationArray as DatasetListResponsesV4PagePaginationArray,
543 type DatasetCreateParams as DatasetCreateParams,
544 type DatasetUpdateParams as DatasetUpdateParams,
545 type DatasetListParams as DatasetListParams,
546 type DatasetDeleteParams as DatasetDeleteParams,
547 type DatasetGetParams as DatasetGetParams,
548 };
549}
550