cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/ai-gateway/datasets.ts

512lines · 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 * Creates a new AI Gateway.
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 * Updates an existing AI Gateway 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 * Lists all AI Gateway evaluator types configured for the account.
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 * Deletes an AI Gateway 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 * Retrieves details for a specific AI Gateway 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 created_at: string;
170
171 enable: boolean;
172
173 filters: Array<DatasetCreateResponse.Filter>;
174
175 /**
176 * gateway id
177 */
178 gateway_id: string;
179
180 modified_at: string;
181
182 name: string;
183}
184
185export namespace DatasetCreateResponse {
186 export interface Filter {
187 key:
188 | 'created_at'
189 | 'request_content_type'
190 | 'response_content_type'
191 | 'success'
192 | 'cached'
193 | 'provider'
194 | 'model'
195 | 'cost'
196 | 'tokens'
197 | 'tokens_in'
198 | 'tokens_out'
199 | 'duration'
200 | 'feedback';
201
202 operator: 'eq' | 'contains' | 'lt' | 'gt';
203
204 value: Array<string | number | boolean>;
205 }
206}
207
208export interface DatasetUpdateResponse {
209 id: string;
210
211 created_at: string;
212
213 enable: boolean;
214
215 filters: Array<DatasetUpdateResponse.Filter>;
216
217 /**
218 * gateway id
219 */
220 gateway_id: string;
221
222 modified_at: string;
223
224 name: string;
225}
226
227export namespace DatasetUpdateResponse {
228 export interface Filter {
229 key:
230 | 'created_at'
231 | 'request_content_type'
232 | 'response_content_type'
233 | 'success'
234 | 'cached'
235 | 'provider'
236 | 'model'
237 | 'cost'
238 | 'tokens'
239 | 'tokens_in'
240 | 'tokens_out'
241 | 'duration'
242 | 'feedback';
243
244 operator: 'eq' | 'contains' | 'lt' | 'gt';
245
246 value: Array<string | number | boolean>;
247 }
248}
249
250export interface DatasetListResponse {
251 id: string;
252
253 created_at: string;
254
255 enable: boolean;
256
257 filters: Array<DatasetListResponse.Filter>;
258
259 /**
260 * gateway id
261 */
262 gateway_id: string;
263
264 modified_at: string;
265
266 name: string;
267}
268
269export namespace DatasetListResponse {
270 export interface Filter {
271 key:
272 | 'created_at'
273 | 'request_content_type'
274 | 'response_content_type'
275 | 'success'
276 | 'cached'
277 | 'provider'
278 | 'model'
279 | 'cost'
280 | 'tokens'
281 | 'tokens_in'
282 | 'tokens_out'
283 | 'duration'
284 | 'feedback';
285
286 operator: 'eq' | 'contains' | 'lt' | 'gt';
287
288 value: Array<string | number | boolean>;
289 }
290}
291
292export interface DatasetDeleteResponse {
293 id: string;
294
295 created_at: string;
296
297 enable: boolean;
298
299 filters: Array<DatasetDeleteResponse.Filter>;
300
301 /**
302 * gateway id
303 */
304 gateway_id: string;
305
306 modified_at: string;
307
308 name: string;
309}
310
311export namespace DatasetDeleteResponse {
312 export interface Filter {
313 key:
314 | 'created_at'
315 | 'request_content_type'
316 | 'response_content_type'
317 | 'success'
318 | 'cached'
319 | 'provider'
320 | 'model'
321 | 'cost'
322 | 'tokens'
323 | 'tokens_in'
324 | 'tokens_out'
325 | 'duration'
326 | 'feedback';
327
328 operator: 'eq' | 'contains' | 'lt' | 'gt';
329
330 value: Array<string | number | boolean>;
331 }
332}
333
334export interface DatasetGetResponse {
335 id: string;
336
337 created_at: string;
338
339 enable: boolean;
340
341 filters: Array<DatasetGetResponse.Filter>;
342
343 /**
344 * gateway id
345 */
346 gateway_id: string;
347
348 modified_at: string;
349
350 name: string;
351}
352
353export namespace DatasetGetResponse {
354 export interface Filter {
355 key:
356 | 'created_at'
357 | 'request_content_type'
358 | 'response_content_type'
359 | 'success'
360 | 'cached'
361 | 'provider'
362 | 'model'
363 | 'cost'
364 | 'tokens'
365 | 'tokens_in'
366 | 'tokens_out'
367 | 'duration'
368 | 'feedback';
369
370 operator: 'eq' | 'contains' | 'lt' | 'gt';
371
372 value: Array<string | number | boolean>;
373 }
374}
375
376export interface DatasetCreateParams {
377 /**
378 * Path param
379 */
380 account_id: string;
381
382 /**
383 * Body param
384 */
385 enable: boolean;
386
387 /**
388 * Body param
389 */
390 filters: Array<DatasetCreateParams.Filter>;
391
392 /**
393 * Body param
394 */
395 name: string;
396}
397
398export namespace DatasetCreateParams {
399 export interface Filter {
400 key:
401 | 'created_at'
402 | 'request_content_type'
403 | 'response_content_type'
404 | 'success'
405 | 'cached'
406 | 'provider'
407 | 'model'
408 | 'cost'
409 | 'tokens'
410 | 'tokens_in'
411 | 'tokens_out'
412 | 'duration'
413 | 'feedback';
414
415 operator: 'eq' | 'contains' | 'lt' | 'gt';
416
417 value: Array<string | number | boolean>;
418 }
419}
420
421export interface DatasetUpdateParams {
422 /**
423 * Path param
424 */
425 account_id: string;
426
427 /**
428 * Body param
429 */
430 enable: boolean;
431
432 /**
433 * Body param
434 */
435 filters: Array<DatasetUpdateParams.Filter>;
436
437 /**
438 * Body param
439 */
440 name: string;
441}
442
443export namespace DatasetUpdateParams {
444 export interface Filter {
445 key:
446 | 'created_at'
447 | 'request_content_type'
448 | 'response_content_type'
449 | 'success'
450 | 'cached'
451 | 'provider'
452 | 'model'
453 | 'cost'
454 | 'tokens'
455 | 'tokens_in'
456 | 'tokens_out'
457 | 'duration'
458 | 'feedback';
459
460 operator: 'eq' | 'contains' | 'lt' | 'gt';
461
462 value: Array<string | number | boolean>;
463 }
464}
465
466export interface DatasetListParams extends V4PagePaginationArrayParams {
467 /**
468 * Path param
469 */
470 account_id: string;
471
472 /**
473 * Query param
474 */
475 enable?: boolean;
476
477 /**
478 * Query param
479 */
480 name?: string;
481
482 /**
483 * Query param: Search by id, name, filters
484 */
485 search?: string;
486}
487
488export interface DatasetDeleteParams {
489 account_id: string;
490}
491
492export interface DatasetGetParams {
493 account_id: string;
494}
495
496Datasets.DatasetListResponsesV4PagePaginationArray = DatasetListResponsesV4PagePaginationArray;
497
498export declare namespace Datasets {
499 export {
500 type DatasetCreateResponse as DatasetCreateResponse,
501 type DatasetUpdateResponse as DatasetUpdateResponse,
502 type DatasetListResponse as DatasetListResponse,
503 type DatasetDeleteResponse as DatasetDeleteResponse,
504 type DatasetGetResponse as DatasetGetResponse,
505 DatasetListResponsesV4PagePaginationArray as DatasetListResponsesV4PagePaginationArray,
506 type DatasetCreateParams as DatasetCreateParams,
507 type DatasetUpdateParams as DatasetUpdateParams,
508 type DatasetListParams as DatasetListParams,
509 type DatasetDeleteParams as DatasetDeleteParams,
510 type DatasetGetParams as DatasetGetParams,
511 };
512}
513