cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/ai-gateway/evaluations.ts
551lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { APIResource } from '../../resource'; |
| 4 | import * as Core from '../../core'; |
| 5 | import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination'; |
| 6 | |
| 7 | export class Evaluations extends APIResource { |
| 8 | /** |
| 9 | * Creates a new AI Gateway. |
| 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 | * Lists all AI Gateway evaluator types configured for the account. |
| 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 | * Deletes an AI Gateway dataset. |
| 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 | * Retrieves details for a specific AI Gateway dataset. |
| 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 | |
| 119 | export class EvaluationListResponsesV4PagePaginationArray extends V4PagePaginationArray<EvaluationListResponse> {} |
| 120 | |
| 121 | export interface EvaluationCreateResponse { |
| 122 | id: string; |
| 123 | |
| 124 | created_at: string; |
| 125 | |
| 126 | datasets: Array<EvaluationCreateResponse.Dataset>; |
| 127 | |
| 128 | /** |
| 129 | * gateway id |
| 130 | */ |
| 131 | gateway_id: string; |
| 132 | |
| 133 | modified_at: string; |
| 134 | |
| 135 | name: string; |
| 136 | |
| 137 | processed: boolean; |
| 138 | |
| 139 | results: Array<EvaluationCreateResponse.Result>; |
| 140 | |
| 141 | total_logs: number; |
| 142 | } |
| 143 | |
| 144 | export namespace EvaluationCreateResponse { |
| 145 | export interface Dataset { |
| 146 | id: string; |
| 147 | |
| 148 | account_id: string; |
| 149 | |
| 150 | account_tag: string; |
| 151 | |
| 152 | created_at: string; |
| 153 | |
| 154 | enable: boolean; |
| 155 | |
| 156 | filters: Array<Dataset.Filter>; |
| 157 | |
| 158 | /** |
| 159 | * gateway id |
| 160 | */ |
| 161 | gateway_id: string; |
| 162 | |
| 163 | modified_at: string; |
| 164 | |
| 165 | name: string; |
| 166 | } |
| 167 | |
| 168 | export namespace Dataset { |
| 169 | export interface Filter { |
| 170 | key: |
| 171 | | 'created_at' |
| 172 | | 'request_content_type' |
| 173 | | 'response_content_type' |
| 174 | | 'success' |
| 175 | | 'cached' |
| 176 | | 'provider' |
| 177 | | 'model' |
| 178 | | 'cost' |
| 179 | | 'tokens' |
| 180 | | 'tokens_in' |
| 181 | | 'tokens_out' |
| 182 | | 'duration' |
| 183 | | 'feedback'; |
| 184 | |
| 185 | operator: 'eq' | 'contains' | 'lt' | 'gt'; |
| 186 | |
| 187 | value: Array<string | number | boolean>; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | export interface Result { |
| 192 | id: string; |
| 193 | |
| 194 | created_at: string; |
| 195 | |
| 196 | evaluation_id: string; |
| 197 | |
| 198 | evaluation_type_id: string; |
| 199 | |
| 200 | modified_at: string; |
| 201 | |
| 202 | result: string; |
| 203 | |
| 204 | status: number; |
| 205 | |
| 206 | status_description: string; |
| 207 | |
| 208 | total_logs: number; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | export interface EvaluationListResponse { |
| 213 | id: string; |
| 214 | |
| 215 | created_at: string; |
| 216 | |
| 217 | datasets: Array<EvaluationListResponse.Dataset>; |
| 218 | |
| 219 | /** |
| 220 | * gateway id |
| 221 | */ |
| 222 | gateway_id: string; |
| 223 | |
| 224 | modified_at: string; |
| 225 | |
| 226 | name: string; |
| 227 | |
| 228 | processed: boolean; |
| 229 | |
| 230 | results: Array<EvaluationListResponse.Result>; |
| 231 | |
| 232 | total_logs: number; |
| 233 | } |
| 234 | |
| 235 | export namespace EvaluationListResponse { |
| 236 | export interface Dataset { |
| 237 | id: string; |
| 238 | |
| 239 | account_id: string; |
| 240 | |
| 241 | account_tag: string; |
| 242 | |
| 243 | created_at: string; |
| 244 | |
| 245 | enable: boolean; |
| 246 | |
| 247 | filters: Array<Dataset.Filter>; |
| 248 | |
| 249 | /** |
| 250 | * gateway id |
| 251 | */ |
| 252 | gateway_id: string; |
| 253 | |
| 254 | modified_at: string; |
| 255 | |
| 256 | name: string; |
| 257 | } |
| 258 | |
| 259 | export namespace Dataset { |
| 260 | export interface Filter { |
| 261 | key: |
| 262 | | 'created_at' |
| 263 | | 'request_content_type' |
| 264 | | 'response_content_type' |
| 265 | | 'success' |
| 266 | | 'cached' |
| 267 | | 'provider' |
| 268 | | 'model' |
| 269 | | 'cost' |
| 270 | | 'tokens' |
| 271 | | 'tokens_in' |
| 272 | | 'tokens_out' |
| 273 | | 'duration' |
| 274 | | 'feedback'; |
| 275 | |
| 276 | operator: 'eq' | 'contains' | 'lt' | 'gt'; |
| 277 | |
| 278 | value: Array<string | number | boolean>; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | export interface Result { |
| 283 | id: string; |
| 284 | |
| 285 | created_at: string; |
| 286 | |
| 287 | evaluation_id: string; |
| 288 | |
| 289 | evaluation_type_id: string; |
| 290 | |
| 291 | modified_at: string; |
| 292 | |
| 293 | result: string; |
| 294 | |
| 295 | status: number; |
| 296 | |
| 297 | status_description: string; |
| 298 | |
| 299 | total_logs: number; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | export interface EvaluationDeleteResponse { |
| 304 | id: string; |
| 305 | |
| 306 | created_at: string; |
| 307 | |
| 308 | datasets: Array<EvaluationDeleteResponse.Dataset>; |
| 309 | |
| 310 | /** |
| 311 | * gateway id |
| 312 | */ |
| 313 | gateway_id: string; |
| 314 | |
| 315 | modified_at: string; |
| 316 | |
| 317 | name: string; |
| 318 | |
| 319 | processed: boolean; |
| 320 | |
| 321 | results: Array<EvaluationDeleteResponse.Result>; |
| 322 | |
| 323 | total_logs: number; |
| 324 | } |
| 325 | |
| 326 | export namespace EvaluationDeleteResponse { |
| 327 | export interface Dataset { |
| 328 | id: string; |
| 329 | |
| 330 | account_id: string; |
| 331 | |
| 332 | account_tag: string; |
| 333 | |
| 334 | created_at: string; |
| 335 | |
| 336 | enable: boolean; |
| 337 | |
| 338 | filters: Array<Dataset.Filter>; |
| 339 | |
| 340 | /** |
| 341 | * gateway id |
| 342 | */ |
| 343 | gateway_id: string; |
| 344 | |
| 345 | modified_at: string; |
| 346 | |
| 347 | name: string; |
| 348 | } |
| 349 | |
| 350 | export namespace Dataset { |
| 351 | export interface Filter { |
| 352 | key: |
| 353 | | 'created_at' |
| 354 | | 'request_content_type' |
| 355 | | 'response_content_type' |
| 356 | | 'success' |
| 357 | | 'cached' |
| 358 | | 'provider' |
| 359 | | 'model' |
| 360 | | 'cost' |
| 361 | | 'tokens' |
| 362 | | 'tokens_in' |
| 363 | | 'tokens_out' |
| 364 | | 'duration' |
| 365 | | 'feedback'; |
| 366 | |
| 367 | operator: 'eq' | 'contains' | 'lt' | 'gt'; |
| 368 | |
| 369 | value: Array<string | number | boolean>; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | export interface Result { |
| 374 | id: string; |
| 375 | |
| 376 | created_at: string; |
| 377 | |
| 378 | evaluation_id: string; |
| 379 | |
| 380 | evaluation_type_id: string; |
| 381 | |
| 382 | modified_at: string; |
| 383 | |
| 384 | result: string; |
| 385 | |
| 386 | status: number; |
| 387 | |
| 388 | status_description: string; |
| 389 | |
| 390 | total_logs: number; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | export interface EvaluationGetResponse { |
| 395 | id: string; |
| 396 | |
| 397 | created_at: string; |
| 398 | |
| 399 | datasets: Array<EvaluationGetResponse.Dataset>; |
| 400 | |
| 401 | /** |
| 402 | * gateway id |
| 403 | */ |
| 404 | gateway_id: string; |
| 405 | |
| 406 | modified_at: string; |
| 407 | |
| 408 | name: string; |
| 409 | |
| 410 | processed: boolean; |
| 411 | |
| 412 | results: Array<EvaluationGetResponse.Result>; |
| 413 | |
| 414 | total_logs: number; |
| 415 | } |
| 416 | |
| 417 | export namespace EvaluationGetResponse { |
| 418 | export interface Dataset { |
| 419 | id: string; |
| 420 | |
| 421 | account_id: string; |
| 422 | |
| 423 | account_tag: string; |
| 424 | |
| 425 | created_at: string; |
| 426 | |
| 427 | enable: boolean; |
| 428 | |
| 429 | filters: Array<Dataset.Filter>; |
| 430 | |
| 431 | /** |
| 432 | * gateway id |
| 433 | */ |
| 434 | gateway_id: string; |
| 435 | |
| 436 | modified_at: string; |
| 437 | |
| 438 | name: string; |
| 439 | } |
| 440 | |
| 441 | export namespace Dataset { |
| 442 | export interface Filter { |
| 443 | key: |
| 444 | | 'created_at' |
| 445 | | 'request_content_type' |
| 446 | | 'response_content_type' |
| 447 | | 'success' |
| 448 | | 'cached' |
| 449 | | 'provider' |
| 450 | | 'model' |
| 451 | | 'cost' |
| 452 | | 'tokens' |
| 453 | | 'tokens_in' |
| 454 | | 'tokens_out' |
| 455 | | 'duration' |
| 456 | | 'feedback'; |
| 457 | |
| 458 | operator: 'eq' | 'contains' | 'lt' | 'gt'; |
| 459 | |
| 460 | value: Array<string | number | boolean>; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | export interface Result { |
| 465 | id: string; |
| 466 | |
| 467 | created_at: string; |
| 468 | |
| 469 | evaluation_id: string; |
| 470 | |
| 471 | evaluation_type_id: string; |
| 472 | |
| 473 | modified_at: string; |
| 474 | |
| 475 | result: string; |
| 476 | |
| 477 | status: number; |
| 478 | |
| 479 | status_description: string; |
| 480 | |
| 481 | total_logs: number; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | export interface EvaluationCreateParams { |
| 486 | /** |
| 487 | * Path param |
| 488 | */ |
| 489 | account_id: string; |
| 490 | |
| 491 | /** |
| 492 | * Body param |
| 493 | */ |
| 494 | dataset_ids: Array<string>; |
| 495 | |
| 496 | /** |
| 497 | * Body param |
| 498 | */ |
| 499 | evaluation_type_ids: Array<string>; |
| 500 | |
| 501 | /** |
| 502 | * Body param |
| 503 | */ |
| 504 | name: string; |
| 505 | } |
| 506 | |
| 507 | export interface EvaluationListParams extends V4PagePaginationArrayParams { |
| 508 | /** |
| 509 | * Path param |
| 510 | */ |
| 511 | account_id: string; |
| 512 | |
| 513 | /** |
| 514 | * Query param |
| 515 | */ |
| 516 | name?: string; |
| 517 | |
| 518 | /** |
| 519 | * Query param |
| 520 | */ |
| 521 | processed?: boolean; |
| 522 | |
| 523 | /** |
| 524 | * Query param: Search by id, name |
| 525 | */ |
| 526 | search?: string; |
| 527 | } |
| 528 | |
| 529 | export interface EvaluationDeleteParams { |
| 530 | account_id: string; |
| 531 | } |
| 532 | |
| 533 | export interface EvaluationGetParams { |
| 534 | account_id: string; |
| 535 | } |
| 536 | |
| 537 | Evaluations.EvaluationListResponsesV4PagePaginationArray = EvaluationListResponsesV4PagePaginationArray; |
| 538 | |
| 539 | export declare namespace Evaluations { |
| 540 | export { |
| 541 | type EvaluationCreateResponse as EvaluationCreateResponse, |
| 542 | type EvaluationListResponse as EvaluationListResponse, |
| 543 | type EvaluationDeleteResponse as EvaluationDeleteResponse, |
| 544 | type EvaluationGetResponse as EvaluationGetResponse, |
| 545 | EvaluationListResponsesV4PagePaginationArray as EvaluationListResponsesV4PagePaginationArray, |
| 546 | type EvaluationCreateParams as EvaluationCreateParams, |
| 547 | type EvaluationListParams as EvaluationListParams, |
| 548 | type EvaluationDeleteParams as EvaluationDeleteParams, |
| 549 | type EvaluationGetParams as EvaluationGetParams, |
| 550 | }; |
| 551 | } |
| 552 | |