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