cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v4.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/ai-gateway/datasets.ts

532lines · modecode

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