cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v5.2.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/ai-gateway/evaluations.ts

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