From a69875817d67a60a612df14bf3ea06352e2fa265 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 14:27:15 +0000 Subject: [PATCH 1/5] chore(tests): improve enum examples (#416) --- .../openai/models/images/ImageCreateVariationParamsTest.kt | 6 +++--- .../kotlin/com/openai/models/images/ImageEditParamsTest.kt | 6 +++--- .../com/openai/models/images/ImageGenerateParamsTest.kt | 6 +++--- .../com/openai/services/async/ImageServiceAsyncTest.kt | 6 +++--- .../kotlin/com/openai/services/blocking/ImageServiceTest.kt | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/images/ImageCreateVariationParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/images/ImageCreateVariationParamsTest.kt index 2f6b01ac..640c01f4 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/images/ImageCreateVariationParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/images/ImageCreateVariationParamsTest.kt @@ -16,7 +16,7 @@ internal class ImageCreateVariationParamsTest { .model(ImageModel.DALL_E_2) .n(1L) .responseFormat(ImageCreateVariationParams.ResponseFormat.URL) - .size(ImageCreateVariationParams.Size._256X256) + .size(ImageCreateVariationParams.Size._1024X1024) .user("user-1234") .build() } @@ -29,7 +29,7 @@ internal class ImageCreateVariationParamsTest { .model(ImageModel.DALL_E_2) .n(1L) .responseFormat(ImageCreateVariationParams.ResponseFormat.URL) - .size(ImageCreateVariationParams.Size._256X256) + .size(ImageCreateVariationParams.Size._1024X1024) .user("user-1234") .build() @@ -50,7 +50,7 @@ internal class ImageCreateVariationParamsTest { "n" to MultipartField.of(1L), "response_format" to MultipartField.of(ImageCreateVariationParams.ResponseFormat.URL), - "size" to MultipartField.of(ImageCreateVariationParams.Size._256X256), + "size" to MultipartField.of(ImageCreateVariationParams.Size._1024X1024), "user" to MultipartField.of("user-1234"), ) .mapValues { (_, field) -> diff --git a/openai-java-core/src/test/kotlin/com/openai/models/images/ImageEditParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/images/ImageEditParamsTest.kt index 057ad7b5..dd3140d0 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/images/ImageEditParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/images/ImageEditParamsTest.kt @@ -18,7 +18,7 @@ internal class ImageEditParamsTest { .model(ImageModel.DALL_E_2) .n(1L) .responseFormat(ImageEditParams.ResponseFormat.URL) - .size(ImageEditParams.Size._256X256) + .size(ImageEditParams.Size._1024X1024) .user("user-1234") .build() } @@ -33,7 +33,7 @@ internal class ImageEditParamsTest { .model(ImageModel.DALL_E_2) .n(1L) .responseFormat(ImageEditParams.ResponseFormat.URL) - .size(ImageEditParams.Size._256X256) + .size(ImageEditParams.Size._1024X1024) .user("user-1234") .build() @@ -55,7 +55,7 @@ internal class ImageEditParamsTest { "model" to MultipartField.of(ImageModel.DALL_E_2), "n" to MultipartField.of(1L), "response_format" to MultipartField.of(ImageEditParams.ResponseFormat.URL), - "size" to MultipartField.of(ImageEditParams.Size._256X256), + "size" to MultipartField.of(ImageEditParams.Size._1024X1024), "user" to MultipartField.of("user-1234"), ) .mapValues { (_, field) -> diff --git a/openai-java-core/src/test/kotlin/com/openai/models/images/ImageGenerateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/images/ImageGenerateParamsTest.kt index 3584a8fa..259c4ca1 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/images/ImageGenerateParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/images/ImageGenerateParamsTest.kt @@ -15,7 +15,7 @@ internal class ImageGenerateParamsTest { .n(1L) .quality(ImageGenerateParams.Quality.STANDARD) .responseFormat(ImageGenerateParams.ResponseFormat.URL) - .size(ImageGenerateParams.Size._256X256) + .size(ImageGenerateParams.Size._1024X1024) .style(ImageGenerateParams.Style.VIVID) .user("user-1234") .build() @@ -30,7 +30,7 @@ internal class ImageGenerateParamsTest { .n(1L) .quality(ImageGenerateParams.Quality.STANDARD) .responseFormat(ImageGenerateParams.ResponseFormat.URL) - .size(ImageGenerateParams.Size._256X256) + .size(ImageGenerateParams.Size._1024X1024) .style(ImageGenerateParams.Style.VIVID) .user("user-1234") .build() @@ -42,7 +42,7 @@ internal class ImageGenerateParamsTest { assertThat(body.n()).contains(1L) assertThat(body.quality()).contains(ImageGenerateParams.Quality.STANDARD) assertThat(body.responseFormat()).contains(ImageGenerateParams.ResponseFormat.URL) - assertThat(body.size()).contains(ImageGenerateParams.Size._256X256) + assertThat(body.size()).contains(ImageGenerateParams.Size._1024X1024) assertThat(body.style()).contains(ImageGenerateParams.Style.VIVID) assertThat(body.user()).contains("user-1234") } diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/ImageServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/ImageServiceAsyncTest.kt index 9e33b5c1..5a685d23 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/ImageServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/ImageServiceAsyncTest.kt @@ -30,7 +30,7 @@ internal class ImageServiceAsyncTest { .model(ImageModel.DALL_E_2) .n(1L) .responseFormat(ImageCreateVariationParams.ResponseFormat.URL) - .size(ImageCreateVariationParams.Size._256X256) + .size(ImageCreateVariationParams.Size._1024X1024) .user("user-1234") .build() ) @@ -57,7 +57,7 @@ internal class ImageServiceAsyncTest { .model(ImageModel.DALL_E_2) .n(1L) .responseFormat(ImageEditParams.ResponseFormat.URL) - .size(ImageEditParams.Size._256X256) + .size(ImageEditParams.Size._1024X1024) .user("user-1234") .build() ) @@ -83,7 +83,7 @@ internal class ImageServiceAsyncTest { .n(1L) .quality(ImageGenerateParams.Quality.STANDARD) .responseFormat(ImageGenerateParams.ResponseFormat.URL) - .size(ImageGenerateParams.Size._256X256) + .size(ImageGenerateParams.Size._1024X1024) .style(ImageGenerateParams.Style.VIVID) .user("user-1234") .build() diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/ImageServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/ImageServiceTest.kt index 899fb4fa..74ed3ff0 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/ImageServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/ImageServiceTest.kt @@ -30,7 +30,7 @@ internal class ImageServiceTest { .model(ImageModel.DALL_E_2) .n(1L) .responseFormat(ImageCreateVariationParams.ResponseFormat.URL) - .size(ImageCreateVariationParams.Size._256X256) + .size(ImageCreateVariationParams.Size._1024X1024) .user("user-1234") .build() ) @@ -56,7 +56,7 @@ internal class ImageServiceTest { .model(ImageModel.DALL_E_2) .n(1L) .responseFormat(ImageEditParams.ResponseFormat.URL) - .size(ImageEditParams.Size._256X256) + .size(ImageEditParams.Size._1024X1024) .user("user-1234") .build() ) @@ -81,7 +81,7 @@ internal class ImageServiceTest { .n(1L) .quality(ImageGenerateParams.Quality.STANDARD) .responseFormat(ImageGenerateParams.ResponseFormat.URL) - .size(ImageGenerateParams.Size._256X256) + .size(ImageGenerateParams.Size._1024X1024) .style(ImageGenerateParams.Style.VIVID) .user("user-1234") .build() From b56799843d71a81b8d99fae6fb04c0dff731afce Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 17:13:15 -0400 Subject: [PATCH 2/5] feat(api): Add evalapi to sdk --- .stats.yml | 8 +- .../kotlin/com/openai/client/OpenAIClient.kt | 5 + .../com/openai/client/OpenAIClientAsync.kt | 5 + .../openai/client/OpenAIClientAsyncImpl.kt | 12 + .../com/openai/client/OpenAIClientImpl.kt | 12 + .../kotlin/com/openai/models/AllModels.kt | 57 +- .../com/openai/models/ResponsesModel.kt | 55 +- .../openai/models/evals/EvalCreateParams.kt | 4672 +++++++++++++++ .../openai/models/evals/EvalCreateResponse.kt | 1145 ++++ .../evals/EvalCustomDataSourceConfig.kt | 329 ++ .../openai/models/evals/EvalDeleteParams.kt | 230 + .../openai/models/evals/EvalDeleteResponse.kt | 235 + .../models/evals/EvalLabelModelGrader.kt | 2108 +++++++ .../com/openai/models/evals/EvalListPage.kt | 199 + .../openai/models/evals/EvalListPageAsync.kt | 212 + .../com/openai/models/evals/EvalListParams.kt | 513 ++ .../openai/models/evals/EvalListResponse.kt | 1145 ++++ .../openai/models/evals/EvalRetrieveParams.kt | 196 + .../models/evals/EvalRetrieveResponse.kt | 1145 ++++ .../EvalStoredCompletionsDataSourceConfig.kt | 492 ++ .../models/evals/EvalStringCheckGrader.kt | 467 ++ .../models/evals/EvalTextSimilarityGrader.kt | 562 ++ .../openai/models/evals/EvalUpdateParams.kt | 615 ++ .../openai/models/evals/EvalUpdateResponse.kt | 1145 ++++ .../CreateEvalCompletionsRunDataSource.kt | 5102 +++++++++++++++++ .../runs/CreateEvalJsonlRunDataSource.kt | 1244 ++++ .../openai/models/evals/runs/EvalApiError.kt | 209 + .../models/evals/runs/RunCancelParams.kt | 241 + .../models/evals/runs/RunCancelResponse.kt | 1991 +++++++ .../models/evals/runs/RunCreateParams.kt | 955 +++ .../models/evals/runs/RunCreateResponse.kt | 1991 +++++++ .../models/evals/runs/RunDeleteParams.kt | 241 + .../models/evals/runs/RunDeleteResponse.kt | 212 + .../openai/models/evals/runs/RunListPage.kt | 199 + .../models/evals/runs/RunListPageAsync.kt | 212 + .../openai/models/evals/runs/RunListParams.kt | 556 ++ .../models/evals/runs/RunListResponse.kt | 1991 +++++++ .../models/evals/runs/RunRetrieveParams.kt | 207 + .../models/evals/runs/RunRetrieveResponse.kt | 1991 +++++++ .../runs/outputitems/OutputItemListPage.kt | 202 + .../outputitems/OutputItemListPageAsync.kt | 217 + .../runs/outputitems/OutputItemListParams.kt | 551 ++ .../outputitems/OutputItemListResponse.kt | 1987 +++++++ .../outputitems/OutputItemRetrieveParams.kt | 218 + .../outputitems/OutputItemRetrieveResponse.kt | 1987 +++++++ .../permissions/PermissionCreatePage.kt | 206 + .../permissions/PermissionCreatePageAsync.kt | 221 + .../permissions/PermissionCreateParams.kt | 464 ++ .../permissions/PermissionCreateResponse.kt | 284 + .../permissions/PermissionDeleteParams.kt | 238 + .../permissions/PermissionDeleteResponse.kt | 247 + .../permissions/PermissionRetrieveParams.kt | 403 ++ .../permissions/PermissionRetrieveResponse.kt | 600 ++ .../com/openai/models/responses/Response.kt | 5 +- .../models/responses/ResponseCreateParams.kt | 9 +- .../openai/services/async/EvalServiceAsync.kt | 195 + .../services/async/EvalServiceAsyncImpl.kt | 248 + .../services/async/FineTuningServiceAsync.kt | 5 + .../async/FineTuningServiceAsyncImpl.kt | 14 + .../services/async/evals/RunServiceAsync.kt | 162 + .../async/evals/RunServiceAsyncImpl.kt | 246 + .../evals/runs/OutputItemServiceAsync.kt | 82 + .../evals/runs/OutputItemServiceAsyncImpl.kt | 131 + .../finetuning/CheckpointServiceAsync.kt | 24 + .../finetuning/CheckpointServiceAsyncImpl.kt | 33 + .../checkpoints/PermissionServiceAsync.kt | 128 + .../checkpoints/PermissionServiceAsyncImpl.kt | 175 + .../openai/services/blocking/EvalService.kt | 177 + .../services/blocking/EvalServiceImpl.kt | 222 + .../services/blocking/FineTuningService.kt | 5 + .../blocking/FineTuningServiceImpl.kt | 12 + .../services/blocking/evals/RunService.kt | 155 + .../services/blocking/evals/RunServiceImpl.kt | 222 + .../blocking/evals/runs/OutputItemService.kt | 74 + .../evals/runs/OutputItemServiceImpl.kt | 118 + .../blocking/finetuning/CheckpointService.kt | 21 + .../finetuning/CheckpointServiceImpl.kt | 31 + .../checkpoints/PermissionService.kt | 119 + .../checkpoints/PermissionServiceImpl.kt | 161 + .../kotlin/com/openai/models/AllModelsTest.kt | 16 +- .../com/openai/models/ResponsesModelTest.kt | 16 +- .../models/evals/EvalCreateParamsTest.kt | 189 + .../models/evals/EvalCreateResponseTest.kt | 158 + .../evals/EvalCustomDataSourceConfigTest.kt | 52 + .../models/evals/EvalDeleteParamsTest.kt | 23 + .../models/evals/EvalDeleteResponseTest.kt | 44 + .../models/evals/EvalLabelModelGraderTest.kt | 92 + .../openai/models/evals/EvalListParamsTest.kt | 52 + .../models/evals/EvalListResponseTest.kt | 158 + .../models/evals/EvalRetrieveParamsTest.kt | 23 + .../models/evals/EvalRetrieveResponseTest.kt | 158 + ...alStoredCompletionsDataSourceConfigTest.kt | 69 + .../models/evals/EvalStringCheckGraderTest.kt | 47 + .../evals/EvalTextSimilarityGraderTest.kt | 51 + .../models/evals/EvalUpdateParamsTest.kt | 63 + .../models/evals/EvalUpdateResponseTest.kt | 158 + .../CreateEvalCompletionsRunDataSourceTest.kt | 173 + .../runs/CreateEvalJsonlRunDataSourceTest.kt | 95 + .../models/evals/runs/EvalApiErrorTest.kt | 33 + .../models/evals/runs/RunCancelParamsTest.kt | 24 + .../evals/runs/RunCancelResponseTest.kt | 217 + .../models/evals/runs/RunCreateParamsTest.kt | 192 + .../evals/runs/RunCreateResponseTest.kt | 217 + .../models/evals/runs/RunDeleteParamsTest.kt | 24 + .../evals/runs/RunDeleteResponseTest.kt | 44 + .../models/evals/runs/RunListParamsTest.kt | 63 + .../models/evals/runs/RunListResponseTest.kt | 217 + .../evals/runs/RunRetrieveParamsTest.kt | 24 + .../evals/runs/RunRetrieveResponseTest.kt | 217 + .../outputitems/OutputItemListParamsTest.kt | 66 + .../outputitems/OutputItemListResponseTest.kt | 181 + .../OutputItemRetrieveParamsTest.kt | 34 + .../OutputItemRetrieveResponseTest.kt | 181 + .../permissions/PermissionCreateParamsTest.kt | 43 + .../PermissionCreateResponseTest.kt | 44 + .../permissions/PermissionDeleteParamsTest.kt | 28 + .../PermissionDeleteResponseTest.kt | 35 + .../PermissionRetrieveParamsTest.kt | 69 + .../PermissionRetrieveResponseTest.kt | 66 + .../services/async/EvalServiceAsyncTest.kt | 142 + .../async/evals/RunServiceAsyncTest.kt | 139 + .../evals/runs/OutputItemServiceAsyncTest.kt | 54 + .../checkpoints/PermissionServiceAsyncTest.kt | 82 + .../services/blocking/EvalServiceTest.kt | 135 + .../services/blocking/evals/RunServiceTest.kt | 130 + .../evals/runs/OutputItemServiceTest.kt | 52 + .../checkpoints/PermissionServiceTest.kt | 79 + 127 files changed, 47893 insertions(+), 81 deletions(-) create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCustomDataSourceConfig.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalDeleteParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalDeleteResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalLabelModelGrader.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPage.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalStoredCompletionsDataSourceConfig.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalStringCheckGrader.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalTextSimilarityGrader.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSource.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalJsonlRunDataSource.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/EvalApiError.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCancelParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCancelResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunDeleteParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunDeleteResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPage.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPageAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPage.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePage.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreateParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreateResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionDeleteParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionDeleteResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionRetrieveParams.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionRetrieveResponse.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/EvalServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/EvalServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/evals/RunServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/evals/RunServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/evals/runs/OutputItemServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/evals/runs/OutputItemServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/CheckpointServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/CheckpointServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/checkpoints/PermissionServiceAsync.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/checkpoints/PermissionServiceAsyncImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/EvalService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/EvalServiceImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/RunService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/RunServiceImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/runs/OutputItemService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/runs/OutputItemServiceImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/CheckpointService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/CheckpointServiceImpl.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/checkpoints/PermissionService.kt create mode 100644 openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/checkpoints/PermissionServiceImpl.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalCreateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalCreateResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalCustomDataSourceConfigTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalDeleteParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalDeleteResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalLabelModelGraderTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalListParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalListResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalStoredCompletionsDataSourceConfigTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalStringCheckGraderTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalTextSimilarityGraderTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalUpdateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/EvalUpdateResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSourceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/CreateEvalJsonlRunDataSourceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/EvalApiErrorTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunCancelParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunCancelResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunCreateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunCreateResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunDeleteParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunDeleteResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunListParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunListResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreateParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreateResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionDeleteParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionDeleteResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionRetrieveParamsTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionRetrieveResponseTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/EvalServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/evals/RunServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/evals/runs/OutputItemServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/async/finetuning/checkpoints/PermissionServiceAsyncTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/EvalServiceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/evals/RunServiceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/evals/runs/OutputItemServiceTest.kt create mode 100644 openai-java-core/src/test/kotlin/com/openai/services/blocking/finetuning/checkpoints/PermissionServiceTest.kt diff --git a/.stats.yml b/.stats.yml index e0e1a71e..037cba0b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 80 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-4bce8217a697c729ac98046d4caf2c9e826b54c427fb0ab4f98e549a2e0ce31c.yml -openapi_spec_hash: 7996d2c34cc44fe2ce9ffe93c0ab774e -config_hash: bcd2cacdcb9fae9938f273cd167f613c +configured_endpoints: 95 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-44b20fa9d24544217fe6bb48852037537030a1ad29b202936425110744fe66fb.yml +openapi_spec_hash: ea86343b5e9858a74e85da8ab2c532f6 +config_hash: 69e3afd56ccb0f0f822a7a9dc130fc99 diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt index 8a033491..3995c9ea 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt @@ -8,6 +8,7 @@ import com.openai.services.blocking.BetaService import com.openai.services.blocking.ChatService import com.openai.services.blocking.CompletionService import com.openai.services.blocking.EmbeddingService +import com.openai.services.blocking.EvalService import com.openai.services.blocking.FileService import com.openai.services.blocking.FineTuningService import com.openai.services.blocking.ImageService @@ -74,6 +75,8 @@ interface OpenAIClient { fun responses(): ResponseService + fun evals(): EvalService + /** * Closes this client, relinquishing any underlying resources. * @@ -117,5 +120,7 @@ interface OpenAIClient { fun uploads(): UploadService.WithRawResponse fun responses(): ResponseService.WithRawResponse + + fun evals(): EvalService.WithRawResponse } } diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt index 72f1c4d6..2a2d5894 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt @@ -8,6 +8,7 @@ import com.openai.services.async.BetaServiceAsync import com.openai.services.async.ChatServiceAsync import com.openai.services.async.CompletionServiceAsync import com.openai.services.async.EmbeddingServiceAsync +import com.openai.services.async.EvalServiceAsync import com.openai.services.async.FileServiceAsync import com.openai.services.async.FineTuningServiceAsync import com.openai.services.async.ImageServiceAsync @@ -74,6 +75,8 @@ interface OpenAIClientAsync { fun responses(): ResponseServiceAsync + fun evals(): EvalServiceAsync + /** * Closes this client, relinquishing any underlying resources. * @@ -117,5 +120,7 @@ interface OpenAIClientAsync { fun uploads(): UploadServiceAsync.WithRawResponse fun responses(): ResponseServiceAsync.WithRawResponse + + fun evals(): EvalServiceAsync.WithRawResponse } } diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt index be1a312a..2bbeb00b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt @@ -16,6 +16,8 @@ import com.openai.services.async.CompletionServiceAsync import com.openai.services.async.CompletionServiceAsyncImpl import com.openai.services.async.EmbeddingServiceAsync import com.openai.services.async.EmbeddingServiceAsyncImpl +import com.openai.services.async.EvalServiceAsync +import com.openai.services.async.EvalServiceAsyncImpl import com.openai.services.async.FileServiceAsync import com.openai.services.async.FileServiceAsyncImpl import com.openai.services.async.FineTuningServiceAsync @@ -100,6 +102,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl ResponseServiceAsyncImpl(clientOptionsWithUserAgent) } + private val evals: EvalServiceAsync by lazy { EvalServiceAsyncImpl(clientOptionsWithUserAgent) } + override fun sync(): OpenAIClient = sync override fun withRawResponse(): OpenAIClientAsync.WithRawResponse = withRawResponse @@ -132,6 +136,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl override fun responses(): ResponseServiceAsync = responses + override fun evals(): EvalServiceAsync = evals + override fun close() = clientOptions.httpClient.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : @@ -193,6 +199,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl ResponseServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val evals: EvalServiceAsync.WithRawResponse by lazy { + EvalServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun completions(): CompletionServiceAsync.WithRawResponse = completions override fun chat(): ChatServiceAsync.WithRawResponse = chat @@ -220,5 +230,7 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl override fun uploads(): UploadServiceAsync.WithRawResponse = uploads override fun responses(): ResponseServiceAsync.WithRawResponse = responses + + override fun evals(): EvalServiceAsync.WithRawResponse = evals } } diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt index f415526a..17ad13b4 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt @@ -16,6 +16,8 @@ import com.openai.services.blocking.CompletionService import com.openai.services.blocking.CompletionServiceImpl import com.openai.services.blocking.EmbeddingService import com.openai.services.blocking.EmbeddingServiceImpl +import com.openai.services.blocking.EvalService +import com.openai.services.blocking.EvalServiceImpl import com.openai.services.blocking.FileService import com.openai.services.blocking.FileServiceImpl import com.openai.services.blocking.FineTuningService @@ -90,6 +92,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient ResponseServiceImpl(clientOptionsWithUserAgent) } + private val evals: EvalService by lazy { EvalServiceImpl(clientOptionsWithUserAgent) } + override fun async(): OpenAIClientAsync = async override fun withRawResponse(): OpenAIClient.WithRawResponse = withRawResponse @@ -122,6 +126,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient override fun responses(): ResponseService = responses + override fun evals(): EvalService = evals + override fun close() = clientOptions.httpClient.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : @@ -183,6 +189,10 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient ResponseServiceImpl.WithRawResponseImpl(clientOptions) } + private val evals: EvalService.WithRawResponse by lazy { + EvalServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun completions(): CompletionService.WithRawResponse = completions override fun chat(): ChatService.WithRawResponse = chat @@ -210,5 +220,7 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient override fun uploads(): UploadService.WithRawResponse = uploads override fun responses(): ResponseService.WithRawResponse = responses + + override fun evals(): EvalService.WithRawResponse = evals } } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt b/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt index b9077106..000b68bc 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt @@ -27,7 +27,7 @@ class AllModels private constructor( private val string: String? = null, private val chatModel: ChatModel? = null, - private val unionMember2: UnionMember2? = null, + private val responsesOnlyModel: ResponsesOnlyModel? = null, private val _json: JsonValue? = null, ) { @@ -35,19 +35,20 @@ private constructor( fun chatModel(): Optional = Optional.ofNullable(chatModel) - fun unionMember2(): Optional = Optional.ofNullable(unionMember2) + fun responsesOnlyModel(): Optional = Optional.ofNullable(responsesOnlyModel) fun isString(): Boolean = string != null fun isChatModel(): Boolean = chatModel != null - fun isUnionMember2(): Boolean = unionMember2 != null + fun isResponsesOnlyModel(): Boolean = responsesOnlyModel != null fun asString(): String = string.getOrThrow("string") fun asChatModel(): ChatModel = chatModel.getOrThrow("chatModel") - fun asUnionMember2(): UnionMember2 = unionMember2.getOrThrow("unionMember2") + fun asResponsesOnlyModel(): ResponsesOnlyModel = + responsesOnlyModel.getOrThrow("responsesOnlyModel") fun _json(): Optional = Optional.ofNullable(_json) @@ -55,7 +56,7 @@ private constructor( when { string != null -> visitor.visitString(string) chatModel != null -> visitor.visitChatModel(chatModel) - unionMember2 != null -> visitor.visitUnionMember2(unionMember2) + responsesOnlyModel != null -> visitor.visitResponsesOnlyModel(responsesOnlyModel) else -> visitor.unknown(_json) } @@ -74,8 +75,8 @@ private constructor( chatModel.validate() } - override fun visitUnionMember2(unionMember2: UnionMember2) { - unionMember2.validate() + override fun visitResponsesOnlyModel(responsesOnlyModel: ResponsesOnlyModel) { + responsesOnlyModel.validate() } } ) @@ -103,7 +104,8 @@ private constructor( override fun visitChatModel(chatModel: ChatModel) = chatModel.validity() - override fun visitUnionMember2(unionMember2: UnionMember2) = unionMember2.validity() + override fun visitResponsesOnlyModel(responsesOnlyModel: ResponsesOnlyModel) = + responsesOnlyModel.validity() override fun unknown(json: JsonValue?) = 0 } @@ -114,16 +116,16 @@ private constructor( return true } - return /* spotless:off */ other is AllModels && string == other.string && chatModel == other.chatModel && unionMember2 == other.unionMember2 /* spotless:on */ + return /* spotless:off */ other is AllModels && string == other.string && chatModel == other.chatModel && responsesOnlyModel == other.responsesOnlyModel /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chatModel, unionMember2) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chatModel, responsesOnlyModel) /* spotless:on */ override fun toString(): String = when { string != null -> "AllModels{string=$string}" chatModel != null -> "AllModels{chatModel=$chatModel}" - unionMember2 != null -> "AllModels{unionMember2=$unionMember2}" + responsesOnlyModel != null -> "AllModels{responsesOnlyModel=$responsesOnlyModel}" _json != null -> "AllModels{_unknown=$_json}" else -> throw IllegalStateException("Invalid AllModels") } @@ -135,7 +137,8 @@ private constructor( @JvmStatic fun ofChatModel(chatModel: ChatModel) = AllModels(chatModel = chatModel) @JvmStatic - fun ofUnionMember2(unionMember2: UnionMember2) = AllModels(unionMember2 = unionMember2) + fun ofResponsesOnlyModel(responsesOnlyModel: ResponsesOnlyModel) = + AllModels(responsesOnlyModel = responsesOnlyModel) } /** An interface that defines how to map each variant of [AllModels] to a value of type [T]. */ @@ -145,7 +148,7 @@ private constructor( fun visitChatModel(chatModel: ChatModel): T - fun visitUnionMember2(unionMember2: UnionMember2): T + fun visitResponsesOnlyModel(responsesOnlyModel: ResponsesOnlyModel): T /** * Maps an unknown variant of [AllModels] to a value of type [T]. @@ -171,8 +174,8 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { AllModels(chatModel = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef())?.let { - AllModels(unionMember2 = it, _json = json) + tryDeserialize(node, jacksonTypeRef())?.let { + AllModels(responsesOnlyModel = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { AllModels(string = it, _json = json) @@ -203,15 +206,16 @@ private constructor( when { value.string != null -> generator.writeObject(value.string) value.chatModel != null -> generator.writeObject(value.chatModel) - value.unionMember2 != null -> generator.writeObject(value.unionMember2) + value.responsesOnlyModel != null -> generator.writeObject(value.responsesOnlyModel) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid AllModels") } } } - class UnionMember2 @JsonCreator private constructor(private val value: JsonField) : - Enum { + class ResponsesOnlyModel + @JsonCreator + private constructor(private val value: JsonField) : Enum { /** * Returns this class instance's raw value. @@ -233,10 +237,10 @@ private constructor( @JvmField val COMPUTER_USE_PREVIEW_2025_03_11 = of("computer-use-preview-2025-03-11") - @JvmStatic fun of(value: String) = UnionMember2(JsonField.of(value)) + @JvmStatic fun of(value: String) = ResponsesOnlyModel(JsonField.of(value)) } - /** An enum containing [UnionMember2]'s known values. */ + /** An enum containing [ResponsesOnlyModel]'s known values. */ enum class Known { O1_PRO, O1_PRO_2025_03_19, @@ -245,9 +249,9 @@ private constructor( } /** - * An enum containing [UnionMember2]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [ResponsesOnlyModel]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [UnionMember2] can contain an unknown value in a couple of cases: + * An instance of [ResponsesOnlyModel] can contain an unknown value in a couple of cases: * - It was deserialized from data that doesn't match any known member. For example, if the * SDK is on an older version than the API, then the API may respond with new members that * the SDK is unaware of. @@ -259,7 +263,8 @@ private constructor( COMPUTER_USE_PREVIEW, COMPUTER_USE_PREVIEW_2025_03_11, /** - * An enum member indicating that [UnionMember2] was instantiated with an unknown value. + * An enum member indicating that [ResponsesOnlyModel] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -295,7 +300,7 @@ private constructor( O1_PRO_2025_03_19 -> Known.O1_PRO_2025_03_19 COMPUTER_USE_PREVIEW -> Known.COMPUTER_USE_PREVIEW COMPUTER_USE_PREVIEW_2025_03_11 -> Known.COMPUTER_USE_PREVIEW_2025_03_11 - else -> throw OpenAIInvalidDataException("Unknown UnionMember2: $value") + else -> throw OpenAIInvalidDataException("Unknown ResponsesOnlyModel: $value") } /** @@ -312,7 +317,7 @@ private constructor( private var validated: Boolean = false - fun validate(): UnionMember2 = apply { + fun validate(): ResponsesOnlyModel = apply { if (validated) { return@apply } @@ -342,7 +347,7 @@ private constructor( return true } - return /* spotless:off */ other is UnionMember2 && value == other.value /* spotless:on */ + return /* spotless:off */ other is ResponsesOnlyModel && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt b/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt index c8479556..9ee5211f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt @@ -27,7 +27,7 @@ class ResponsesModel private constructor( private val string: String? = null, private val chat: ChatModel? = null, - private val unionMember2: UnionMember2? = null, + private val only: ResponsesOnlyModel? = null, private val _json: JsonValue? = null, ) { @@ -35,19 +35,19 @@ private constructor( fun chat(): Optional = Optional.ofNullable(chat) - fun unionMember2(): Optional = Optional.ofNullable(unionMember2) + fun only(): Optional = Optional.ofNullable(only) fun isString(): Boolean = string != null fun isChat(): Boolean = chat != null - fun isUnionMember2(): Boolean = unionMember2 != null + fun isOnly(): Boolean = only != null fun asString(): String = string.getOrThrow("string") fun asChat(): ChatModel = chat.getOrThrow("chat") - fun asUnionMember2(): UnionMember2 = unionMember2.getOrThrow("unionMember2") + fun asOnly(): ResponsesOnlyModel = only.getOrThrow("only") fun _json(): Optional = Optional.ofNullable(_json) @@ -55,7 +55,7 @@ private constructor( when { string != null -> visitor.visitString(string) chat != null -> visitor.visitChat(chat) - unionMember2 != null -> visitor.visitUnionMember2(unionMember2) + only != null -> visitor.visitOnly(only) else -> visitor.unknown(_json) } @@ -74,8 +74,8 @@ private constructor( chat.validate() } - override fun visitUnionMember2(unionMember2: UnionMember2) { - unionMember2.validate() + override fun visitOnly(only: ResponsesOnlyModel) { + only.validate() } } ) @@ -103,7 +103,7 @@ private constructor( override fun visitChat(chat: ChatModel) = chat.validity() - override fun visitUnionMember2(unionMember2: UnionMember2) = unionMember2.validity() + override fun visitOnly(only: ResponsesOnlyModel) = only.validity() override fun unknown(json: JsonValue?) = 0 } @@ -114,16 +114,16 @@ private constructor( return true } - return /* spotless:off */ other is ResponsesModel && string == other.string && chat == other.chat && unionMember2 == other.unionMember2 /* spotless:on */ + return /* spotless:off */ other is ResponsesModel && string == other.string && chat == other.chat && only == other.only /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chat, unionMember2) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chat, only) /* spotless:on */ override fun toString(): String = when { string != null -> "ResponsesModel{string=$string}" chat != null -> "ResponsesModel{chat=$chat}" - unionMember2 != null -> "ResponsesModel{unionMember2=$unionMember2}" + only != null -> "ResponsesModel{only=$only}" _json != null -> "ResponsesModel{_unknown=$_json}" else -> throw IllegalStateException("Invalid ResponsesModel") } @@ -134,8 +134,7 @@ private constructor( @JvmStatic fun ofChat(chat: ChatModel) = ResponsesModel(chat = chat) - @JvmStatic - fun ofUnionMember2(unionMember2: UnionMember2) = ResponsesModel(unionMember2 = unionMember2) + @JvmStatic fun ofOnly(only: ResponsesOnlyModel) = ResponsesModel(only = only) } /** @@ -147,7 +146,7 @@ private constructor( fun visitChat(chat: ChatModel): T - fun visitUnionMember2(unionMember2: UnionMember2): T + fun visitOnly(only: ResponsesOnlyModel): T /** * Maps an unknown variant of [ResponsesModel] to a value of type [T]. @@ -174,8 +173,8 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { ResponsesModel(chat = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef())?.let { - ResponsesModel(unionMember2 = it, _json = json) + tryDeserialize(node, jacksonTypeRef())?.let { + ResponsesModel(only = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { ResponsesModel(string = it, _json = json) @@ -206,15 +205,16 @@ private constructor( when { value.string != null -> generator.writeObject(value.string) value.chat != null -> generator.writeObject(value.chat) - value.unionMember2 != null -> generator.writeObject(value.unionMember2) + value.only != null -> generator.writeObject(value.only) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid ResponsesModel") } } } - class UnionMember2 @JsonCreator private constructor(private val value: JsonField) : - Enum { + class ResponsesOnlyModel + @JsonCreator + private constructor(private val value: JsonField) : Enum { /** * Returns this class instance's raw value. @@ -236,10 +236,10 @@ private constructor( @JvmField val COMPUTER_USE_PREVIEW_2025_03_11 = of("computer-use-preview-2025-03-11") - @JvmStatic fun of(value: String) = UnionMember2(JsonField.of(value)) + @JvmStatic fun of(value: String) = ResponsesOnlyModel(JsonField.of(value)) } - /** An enum containing [UnionMember2]'s known values. */ + /** An enum containing [ResponsesOnlyModel]'s known values. */ enum class Known { O1_PRO, O1_PRO_2025_03_19, @@ -248,9 +248,9 @@ private constructor( } /** - * An enum containing [UnionMember2]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [ResponsesOnlyModel]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [UnionMember2] can contain an unknown value in a couple of cases: + * An instance of [ResponsesOnlyModel] can contain an unknown value in a couple of cases: * - It was deserialized from data that doesn't match any known member. For example, if the * SDK is on an older version than the API, then the API may respond with new members that * the SDK is unaware of. @@ -262,7 +262,8 @@ private constructor( COMPUTER_USE_PREVIEW, COMPUTER_USE_PREVIEW_2025_03_11, /** - * An enum member indicating that [UnionMember2] was instantiated with an unknown value. + * An enum member indicating that [ResponsesOnlyModel] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -298,7 +299,7 @@ private constructor( O1_PRO_2025_03_19 -> Known.O1_PRO_2025_03_19 COMPUTER_USE_PREVIEW -> Known.COMPUTER_USE_PREVIEW COMPUTER_USE_PREVIEW_2025_03_11 -> Known.COMPUTER_USE_PREVIEW_2025_03_11 - else -> throw OpenAIInvalidDataException("Unknown UnionMember2: $value") + else -> throw OpenAIInvalidDataException("Unknown ResponsesOnlyModel: $value") } /** @@ -315,7 +316,7 @@ private constructor( private var validated: Boolean = false - fun validate(): UnionMember2 = apply { + fun validate(): ResponsesOnlyModel = apply { if (validated) { return@apply } @@ -345,7 +346,7 @@ private constructor( return true } - return /* spotless:off */ other is UnionMember2 && value == other.value /* spotless:on */ + return /* spotless:off */ other is ResponsesOnlyModel && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateParams.kt new file mode 100644 index 00000000..e2302685 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateParams.kt @@ -0,0 +1,4672 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.allMaxBy +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Create the structure of an evaluation that can be used to test a model's performance. An + * evaluation is a set of testing criteria and a datasource. After creating an evaluation, you can + * run it on different models and model parameters. We support several types of graders and + * datasources. For more information, see the + * [Evals guide](https://platform.openai.com/docs/guides/evals). + */ +class EvalCreateParams +private constructor( + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * The configuration for the data source used for the evaluation runs. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dataSourceConfig(): DataSourceConfig = body.dataSourceConfig() + + /** + * A list of graders for all eval runs in this group. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun testingCriteria(): List = body.testingCriteria() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = body.metadata() + + /** + * The name of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = body.name() + + /** + * Indicates whether the evaluation is shared with OpenAI. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun shareWithOpenAI(): Optional = body.shareWithOpenAI() + + /** + * Returns the raw JSON value of [dataSourceConfig]. + * + * Unlike [dataSourceConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _dataSourceConfig(): JsonField = body._dataSourceConfig() + + /** + * Returns the raw JSON value of [testingCriteria]. + * + * Unlike [testingCriteria], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _testingCriteria(): JsonField> = body._testingCriteria() + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _metadata(): JsonField = body._metadata() + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _name(): JsonField = body._name() + + /** + * Returns the raw JSON value of [shareWithOpenAI]. + * + * Unlike [shareWithOpenAI], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _shareWithOpenAI(): JsonField = body._shareWithOpenAI() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalCreateParams]. + * + * The following fields are required: + * ```java + * .dataSourceConfig() + * .testingCriteria() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(evalCreateParams: EvalCreateParams) = apply { + body = evalCreateParams.body.toBuilder() + additionalHeaders = evalCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = evalCreateParams.additionalQueryParams.toBuilder() + } + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [dataSourceConfig] + * - [testingCriteria] + * - [metadata] + * - [name] + * - [shareWithOpenAI] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The configuration for the data source used for the evaluation runs. */ + fun dataSourceConfig(dataSourceConfig: DataSourceConfig) = apply { + body.dataSourceConfig(dataSourceConfig) + } + + /** + * Sets [Builder.dataSourceConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.dataSourceConfig] with a well-typed [DataSourceConfig] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dataSourceConfig(dataSourceConfig: JsonField) = apply { + body.dataSourceConfig(dataSourceConfig) + } + + /** Alias for calling [dataSourceConfig] with `DataSourceConfig.ofCustom(custom)`. */ + fun dataSourceConfig(custom: DataSourceConfig.Custom) = apply { + body.dataSourceConfig(custom) + } + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * DataSourceConfig.Custom.builder() + * .itemSchema(itemSchema) + * .build() + * ``` + */ + fun customDataSourceConfig(itemSchema: DataSourceConfig.Custom.ItemSchema) = apply { + body.customDataSourceConfig(itemSchema) + } + + /** + * Alias for calling [dataSourceConfig] with + * `DataSourceConfig.ofStoredCompletions(storedCompletions)`. + */ + fun dataSourceConfig(storedCompletions: DataSourceConfig.StoredCompletions) = apply { + body.dataSourceConfig(storedCompletions) + } + + /** A list of graders for all eval runs in this group. */ + fun testingCriteria(testingCriteria: List) = apply { + body.testingCriteria(testingCriteria) + } + + /** + * Sets [Builder.testingCriteria] to an arbitrary JSON value. + * + * You should usually call [Builder.testingCriteria] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun testingCriteria(testingCriteria: JsonField>) = apply { + body.testingCriteria(testingCriteria) + } + + /** + * Adds a single [TestingCriterion] to [testingCriteria]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTestingCriterion(testingCriterion: TestingCriterion) = apply { + body.addTestingCriterion(testingCriterion) + } + + /** + * Alias for calling [addTestingCriterion] with `TestingCriterion.ofLabelModel(labelModel)`. + */ + fun addTestingCriterion(labelModel: TestingCriterion.LabelModel) = apply { + body.addTestingCriterion(labelModel) + } + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofStringCheck(stringCheck)`. + */ + fun addTestingCriterion(stringCheck: EvalStringCheckGrader) = apply { + body.addTestingCriterion(stringCheck) + } + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofTextSimilarity(textSimilarity)`. + */ + fun addTestingCriterion(textSimilarity: EvalTextSimilarityGrader) = apply { + body.addTestingCriterion(textSimilarity) + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + + /** The name of the evaluation. */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + /** Indicates whether the evaluation is shared with OpenAI. */ + fun shareWithOpenAI(shareWithOpenAI: Boolean) = apply { + body.shareWithOpenAI(shareWithOpenAI) + } + + /** + * Sets [Builder.shareWithOpenAI] to an arbitrary JSON value. + * + * You should usually call [Builder.shareWithOpenAI] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun shareWithOpenAI(shareWithOpenAI: JsonField) = apply { + body.shareWithOpenAI(shareWithOpenAI) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [EvalCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .dataSourceConfig() + * .testingCriteria() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalCreateParams = + EvalCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val dataSourceConfig: JsonField, + private val testingCriteria: JsonField>, + private val metadata: JsonField, + private val name: JsonField, + private val shareWithOpenAI: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("data_source_config") + @ExcludeMissing + dataSourceConfig: JsonField = JsonMissing.of(), + @JsonProperty("testing_criteria") + @ExcludeMissing + testingCriteria: JsonField> = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("share_with_openai") + @ExcludeMissing + shareWithOpenAI: JsonField = JsonMissing.of(), + ) : this(dataSourceConfig, testingCriteria, metadata, name, shareWithOpenAI, mutableMapOf()) + + /** + * The configuration for the data source used for the evaluation runs. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dataSourceConfig(): DataSourceConfig = + dataSourceConfig.getRequired("data_source_config") + + /** + * A list of graders for all eval runs in this group. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun testingCriteria(): List = + testingCriteria.getRequired("testing_criteria") + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * The name of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Indicates whether the evaluation is shared with OpenAI. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun shareWithOpenAI(): Optional = shareWithOpenAI.getOptional("share_with_openai") + + /** + * Returns the raw JSON value of [dataSourceConfig]. + * + * Unlike [dataSourceConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("data_source_config") + @ExcludeMissing + fun _dataSourceConfig(): JsonField = dataSourceConfig + + /** + * Returns the raw JSON value of [testingCriteria]. + * + * Unlike [testingCriteria], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("testing_criteria") + @ExcludeMissing + fun _testingCriteria(): JsonField> = testingCriteria + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [shareWithOpenAI]. + * + * Unlike [shareWithOpenAI], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("share_with_openai") + @ExcludeMissing + fun _shareWithOpenAI(): JsonField = shareWithOpenAI + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .dataSourceConfig() + * .testingCriteria() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var dataSourceConfig: JsonField? = null + private var testingCriteria: JsonField>? = null + private var metadata: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var shareWithOpenAI: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + dataSourceConfig = body.dataSourceConfig + testingCriteria = body.testingCriteria.map { it.toMutableList() } + metadata = body.metadata + name = body.name + shareWithOpenAI = body.shareWithOpenAI + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The configuration for the data source used for the evaluation runs. */ + fun dataSourceConfig(dataSourceConfig: DataSourceConfig) = + dataSourceConfig(JsonField.of(dataSourceConfig)) + + /** + * Sets [Builder.dataSourceConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.dataSourceConfig] with a well-typed + * [DataSourceConfig] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun dataSourceConfig(dataSourceConfig: JsonField) = apply { + this.dataSourceConfig = dataSourceConfig + } + + /** Alias for calling [dataSourceConfig] with `DataSourceConfig.ofCustom(custom)`. */ + fun dataSourceConfig(custom: DataSourceConfig.Custom) = + dataSourceConfig(DataSourceConfig.ofCustom(custom)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * DataSourceConfig.Custom.builder() + * .itemSchema(itemSchema) + * .build() + * ``` + */ + fun customDataSourceConfig(itemSchema: DataSourceConfig.Custom.ItemSchema) = + dataSourceConfig(DataSourceConfig.Custom.builder().itemSchema(itemSchema).build()) + + /** + * Alias for calling [dataSourceConfig] with + * `DataSourceConfig.ofStoredCompletions(storedCompletions)`. + */ + fun dataSourceConfig(storedCompletions: DataSourceConfig.StoredCompletions) = + dataSourceConfig(DataSourceConfig.ofStoredCompletions(storedCompletions)) + + /** A list of graders for all eval runs in this group. */ + fun testingCriteria(testingCriteria: List) = + testingCriteria(JsonField.of(testingCriteria)) + + /** + * Sets [Builder.testingCriteria] to an arbitrary JSON value. + * + * You should usually call [Builder.testingCriteria] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun testingCriteria(testingCriteria: JsonField>) = apply { + this.testingCriteria = testingCriteria.map { it.toMutableList() } + } + + /** + * Adds a single [TestingCriterion] to [testingCriteria]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTestingCriterion(testingCriterion: TestingCriterion) = apply { + testingCriteria = + (testingCriteria ?: JsonField.of(mutableListOf())).also { + checkKnown("testingCriteria", it).add(testingCriterion) + } + } + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofLabelModel(labelModel)`. + */ + fun addTestingCriterion(labelModel: TestingCriterion.LabelModel) = + addTestingCriterion(TestingCriterion.ofLabelModel(labelModel)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofStringCheck(stringCheck)`. + */ + fun addTestingCriterion(stringCheck: EvalStringCheckGrader) = + addTestingCriterion(TestingCriterion.ofStringCheck(stringCheck)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofTextSimilarity(textSimilarity)`. + */ + fun addTestingCriterion(textSimilarity: EvalTextSimilarityGrader) = + addTestingCriterion(TestingCriterion.ofTextSimilarity(textSimilarity)) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying + * for objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** The name of the evaluation. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** Indicates whether the evaluation is shared with OpenAI. */ + fun shareWithOpenAI(shareWithOpenAI: Boolean) = + shareWithOpenAI(JsonField.of(shareWithOpenAI)) + + /** + * Sets [Builder.shareWithOpenAI] to an arbitrary JSON value. + * + * You should usually call [Builder.shareWithOpenAI] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun shareWithOpenAI(shareWithOpenAI: JsonField) = apply { + this.shareWithOpenAI = shareWithOpenAI + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .dataSourceConfig() + * .testingCriteria() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("dataSourceConfig", dataSourceConfig), + checkRequired("testingCriteria", testingCriteria).map { it.toImmutable() }, + metadata, + name, + shareWithOpenAI, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + dataSourceConfig().validate() + testingCriteria().forEach { it.validate() } + metadata().ifPresent { it.validate() } + name() + shareWithOpenAI() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (dataSourceConfig.asKnown().getOrNull()?.validity() ?: 0) + + (testingCriteria.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (shareWithOpenAI.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && dataSourceConfig == other.dataSourceConfig && testingCriteria == other.testingCriteria && metadata == other.metadata && name == other.name && shareWithOpenAI == other.shareWithOpenAI && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(dataSourceConfig, testingCriteria, metadata, name, shareWithOpenAI, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{dataSourceConfig=$dataSourceConfig, testingCriteria=$testingCriteria, metadata=$metadata, name=$name, shareWithOpenAI=$shareWithOpenAI, additionalProperties=$additionalProperties}" + } + + /** The configuration for the data source used for the evaluation runs. */ + @JsonDeserialize(using = DataSourceConfig.Deserializer::class) + @JsonSerialize(using = DataSourceConfig.Serializer::class) + class DataSourceConfig + private constructor( + private val custom: Custom? = null, + private val storedCompletions: StoredCompletions? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A CustomDataSourceConfig object that defines the schema for the data source used for the + * evaluation runs. This schema is used to define the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun custom(): Optional = Optional.ofNullable(custom) + + /** + * A data source config which specifies the metadata property of your stored completions + * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. + */ + fun storedCompletions(): Optional = + Optional.ofNullable(storedCompletions) + + fun isCustom(): Boolean = custom != null + + fun isStoredCompletions(): Boolean = storedCompletions != null + + /** + * A CustomDataSourceConfig object that defines the schema for the data source used for the + * evaluation runs. This schema is used to define the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun asCustom(): Custom = custom.getOrThrow("custom") + + /** + * A data source config which specifies the metadata property of your stored completions + * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. + */ + fun asStoredCompletions(): StoredCompletions = + storedCompletions.getOrThrow("storedCompletions") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + custom != null -> visitor.visitCustom(custom) + storedCompletions != null -> visitor.visitStoredCompletions(storedCompletions) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): DataSourceConfig = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustom(custom: Custom) { + custom.validate() + } + + override fun visitStoredCompletions(storedCompletions: StoredCompletions) { + storedCompletions.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCustom(custom: Custom) = custom.validity() + + override fun visitStoredCompletions(storedCompletions: StoredCompletions) = + storedCompletions.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DataSourceConfig && custom == other.custom && storedCompletions == other.storedCompletions /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(custom, storedCompletions) /* spotless:on */ + + override fun toString(): String = + when { + custom != null -> "DataSourceConfig{custom=$custom}" + storedCompletions != null -> + "DataSourceConfig{storedCompletions=$storedCompletions}" + _json != null -> "DataSourceConfig{_unknown=$_json}" + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + + companion object { + + /** + * A CustomDataSourceConfig object that defines the schema for the data source used for + * the evaluation runs. This schema is used to define the shape of the data that will + * be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + @JvmStatic fun ofCustom(custom: Custom) = DataSourceConfig(custom = custom) + + /** + * A data source config which specifies the metadata property of your stored completions + * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. + */ + @JvmStatic + fun ofStoredCompletions(storedCompletions: StoredCompletions) = + DataSourceConfig(storedCompletions = storedCompletions) + } + + /** + * An interface that defines how to map each variant of [DataSourceConfig] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A CustomDataSourceConfig object that defines the schema for the data source used for + * the evaluation runs. This schema is used to define the shape of the data that will + * be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun visitCustom(custom: Custom): T + + /** + * A data source config which specifies the metadata property of your stored completions + * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. + */ + fun visitStoredCompletions(storedCompletions: StoredCompletions): T + + /** + * Maps an unknown variant of [DataSourceConfig] to a value of type [T]. + * + * An instance of [DataSourceConfig] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown DataSourceConfig: $json") + } + } + + internal class Deserializer : BaseDeserializer(DataSourceConfig::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): DataSourceConfig { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "custom" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + DataSourceConfig(custom = it, _json = json) + } ?: DataSourceConfig(_json = json) + } + "stored_completions" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + DataSourceConfig(storedCompletions = it, _json = json) + } ?: DataSourceConfig(_json = json) + } + } + + return DataSourceConfig(_json = json) + } + } + + internal class Serializer : BaseSerializer(DataSourceConfig::class) { + + override fun serialize( + value: DataSourceConfig, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.custom != null -> generator.writeObject(value.custom) + value.storedCompletions != null -> + generator.writeObject(value.storedCompletions) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + } + } + + /** + * A CustomDataSourceConfig object that defines the schema for the data source used for the + * evaluation runs. This schema is used to define the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + class Custom + private constructor( + private val itemSchema: JsonField, + private val type: JsonValue, + private val includeSampleSchema: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("item_schema") + @ExcludeMissing + itemSchema: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("include_sample_schema") + @ExcludeMissing + includeSampleSchema: JsonField = JsonMissing.of(), + ) : this(itemSchema, type, includeSampleSchema, mutableMapOf()) + + /** + * The json schema for the run data source items. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun itemSchema(): ItemSchema = itemSchema.getRequired("item_schema") + + /** + * The type of data source. Always `custom`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("custom") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Whether to include the sample schema in the data source. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun includeSampleSchema(): Optional = + includeSampleSchema.getOptional("include_sample_schema") + + /** + * Returns the raw JSON value of [itemSchema]. + * + * Unlike [itemSchema], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("item_schema") + @ExcludeMissing + fun _itemSchema(): JsonField = itemSchema + + /** + * Returns the raw JSON value of [includeSampleSchema]. + * + * Unlike [includeSampleSchema], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("include_sample_schema") + @ExcludeMissing + fun _includeSampleSchema(): JsonField = includeSampleSchema + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Custom]. + * + * The following fields are required: + * ```java + * .itemSchema() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Custom]. */ + class Builder internal constructor() { + + private var itemSchema: JsonField? = null + private var type: JsonValue = JsonValue.from("custom") + private var includeSampleSchema: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(custom: Custom) = apply { + itemSchema = custom.itemSchema + type = custom.type + includeSampleSchema = custom.includeSampleSchema + additionalProperties = custom.additionalProperties.toMutableMap() + } + + /** The json schema for the run data source items. */ + fun itemSchema(itemSchema: ItemSchema) = itemSchema(JsonField.of(itemSchema)) + + /** + * Sets [Builder.itemSchema] to an arbitrary JSON value. + * + * You should usually call [Builder.itemSchema] with a well-typed [ItemSchema] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun itemSchema(itemSchema: JsonField) = apply { + this.itemSchema = itemSchema + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("custom") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Whether to include the sample schema in the data source. */ + fun includeSampleSchema(includeSampleSchema: Boolean) = + includeSampleSchema(JsonField.of(includeSampleSchema)) + + /** + * Sets [Builder.includeSampleSchema] to an arbitrary JSON value. + * + * You should usually call [Builder.includeSampleSchema] with a well-typed [Boolean] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun includeSampleSchema(includeSampleSchema: JsonField) = apply { + this.includeSampleSchema = includeSampleSchema + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Custom]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .itemSchema() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Custom = + Custom( + checkRequired("itemSchema", itemSchema), + type, + includeSampleSchema, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Custom = apply { + if (validated) { + return@apply + } + + itemSchema().validate() + _type().let { + if (it != JsonValue.from("custom")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + includeSampleSchema() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (itemSchema.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("custom")) 1 else 0 } + + (if (includeSampleSchema.asKnown().isPresent) 1 else 0) + + /** The json schema for the run data source items. */ + class ItemSchema + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [ItemSchema]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ItemSchema]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(itemSchema: ItemSchema) = apply { + additionalProperties = itemSchema.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ItemSchema]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): ItemSchema = ItemSchema(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): ItemSchema = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ItemSchema && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "ItemSchema{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Custom && itemSchema == other.itemSchema && type == other.type && includeSampleSchema == other.includeSampleSchema && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(itemSchema, type, includeSampleSchema, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Custom{itemSchema=$itemSchema, type=$type, includeSampleSchema=$includeSampleSchema, additionalProperties=$additionalProperties}" + } + + /** + * A data source config which specifies the metadata property of your stored completions + * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. + */ + class StoredCompletions + private constructor( + private val type: JsonValue, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this(type, metadata, mutableMapOf()) + + /** + * The type of data source. Always `stored_completions`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("stored_completions") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying + * for objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [StoredCompletions]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StoredCompletions]. */ + class Builder internal constructor() { + + private var type: JsonValue = JsonValue.from("stored_completions") + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(storedCompletions: StoredCompletions) = apply { + type = storedCompletions.type + metadata = storedCompletions.metadata + additionalProperties = storedCompletions.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("stored_completions") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful + * for storing additional information about the object in a structured format, and + * querying for objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with + * a maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [StoredCompletions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): StoredCompletions = + StoredCompletions(type, metadata, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): StoredCompletions = apply { + if (validated) { + return@apply + } + + _type().let { + if (it != JsonValue.from("stored_completions")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + metadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + type.let { if (it == JsonValue.from("stored_completions")) 1 else 0 } + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying + * for objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StoredCompletions && type == other.type && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StoredCompletions{type=$type, metadata=$metadata, additionalProperties=$additionalProperties}" + } + } + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the evaluation. + */ + @JsonDeserialize(using = TestingCriterion.Deserializer::class) + @JsonSerialize(using = TestingCriterion.Serializer::class) + class TestingCriterion + private constructor( + private val labelModel: LabelModel? = null, + private val stringCheck: EvalStringCheckGrader? = null, + private val textSimilarity: EvalTextSimilarityGrader? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun labelModel(): Optional = Optional.ofNullable(labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun stringCheck(): Optional = Optional.ofNullable(stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun textSimilarity(): Optional = + Optional.ofNullable(textSimilarity) + + fun isLabelModel(): Boolean = labelModel != null + + fun isStringCheck(): Boolean = stringCheck != null + + fun isTextSimilarity(): Boolean = textSimilarity != null + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun asLabelModel(): LabelModel = labelModel.getOrThrow("labelModel") + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun asStringCheck(): EvalStringCheckGrader = stringCheck.getOrThrow("stringCheck") + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun asTextSimilarity(): EvalTextSimilarityGrader = + textSimilarity.getOrThrow("textSimilarity") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + labelModel != null -> visitor.visitLabelModel(labelModel) + stringCheck != null -> visitor.visitStringCheck(stringCheck) + textSimilarity != null -> visitor.visitTextSimilarity(textSimilarity) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): TestingCriterion = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitLabelModel(labelModel: LabelModel) { + labelModel.validate() + } + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) { + stringCheck.validate() + } + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) { + textSimilarity.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitLabelModel(labelModel: LabelModel) = labelModel.validity() + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) = + stringCheck.validity() + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + textSimilarity.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TestingCriterion && labelModel == other.labelModel && stringCheck == other.stringCheck && textSimilarity == other.textSimilarity /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(labelModel, stringCheck, textSimilarity) /* spotless:on */ + + override fun toString(): String = + when { + labelModel != null -> "TestingCriterion{labelModel=$labelModel}" + stringCheck != null -> "TestingCriterion{stringCheck=$stringCheck}" + textSimilarity != null -> "TestingCriterion{textSimilarity=$textSimilarity}" + _json != null -> "TestingCriterion{_unknown=$_json}" + else -> throw IllegalStateException("Invalid TestingCriterion") + } + + companion object { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + @JvmStatic + fun ofLabelModel(labelModel: LabelModel) = TestingCriterion(labelModel = labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + @JvmStatic + fun ofStringCheck(stringCheck: EvalStringCheckGrader) = + TestingCriterion(stringCheck = stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + @JvmStatic + fun ofTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + TestingCriterion(textSimilarity = textSimilarity) + } + + /** + * An interface that defines how to map each variant of [TestingCriterion] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun visitLabelModel(labelModel: LabelModel): T + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + fun visitStringCheck(stringCheck: EvalStringCheckGrader): T + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader): T + + /** + * Maps an unknown variant of [TestingCriterion] to a value of type [T]. + * + * An instance of [TestingCriterion] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown TestingCriterion: $json") + } + } + + internal class Deserializer : BaseDeserializer(TestingCriterion::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): TestingCriterion { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "label_model" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(labelModel = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "string_check" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(stringCheck = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "text_similarity" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { TestingCriterion(textSimilarity = it, _json = json) } + ?: TestingCriterion(_json = json) + } + } + + return TestingCriterion(_json = json) + } + } + + internal class Serializer : BaseSerializer(TestingCriterion::class) { + + override fun serialize( + value: TestingCriterion, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.labelModel != null -> generator.writeObject(value.labelModel) + value.stringCheck != null -> generator.writeObject(value.stringCheck) + value.textSimilarity != null -> generator.writeObject(value.textSimilarity) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid TestingCriterion") + } + } + } + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + class LabelModel + private constructor( + private val input: JsonField>, + private val labels: JsonField>, + private val model: JsonField, + private val name: JsonField, + private val passingLabels: JsonField>, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("input") + @ExcludeMissing + input: JsonField> = JsonMissing.of(), + @JsonProperty("labels") + @ExcludeMissing + labels: JsonField> = JsonMissing.of(), + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("passing_labels") + @ExcludeMissing + passingLabels: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(input, labels, model, name, passingLabels, type, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun input(): List = input.getRequired("input") + + /** + * The labels to classify to each item in the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun labels(): List = labels.getRequired("labels") + + /** + * The model to use for the evaluation. Must support structured outputs. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun model(): String = model.getRequired("model") + + /** + * The name of the grader. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun name(): String = name.getRequired("name") + + /** + * The labels that indicate a passing result. Must be a subset of labels. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun passingLabels(): List = passingLabels.getRequired("passing_labels") + + /** + * The object type, which is always `label_model`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("label_model") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [input]. + * + * Unlike [input], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input") @ExcludeMissing fun _input(): JsonField> = input + + /** + * Returns the raw JSON value of [labels]. + * + * Unlike [labels], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("labels") @ExcludeMissing fun _labels(): JsonField> = labels + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [passingLabels]. + * + * Unlike [passingLabels], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("passing_labels") + @ExcludeMissing + fun _passingLabels(): JsonField> = passingLabels + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [LabelModel]. + * + * The following fields are required: + * ```java + * .input() + * .labels() + * .model() + * .name() + * .passingLabels() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [LabelModel]. */ + class Builder internal constructor() { + + private var input: JsonField>? = null + private var labels: JsonField>? = null + private var model: JsonField? = null + private var name: JsonField? = null + private var passingLabels: JsonField>? = null + private var type: JsonValue = JsonValue.from("label_model") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(labelModel: LabelModel) = apply { + input = labelModel.input.map { it.toMutableList() } + labels = labelModel.labels.map { it.toMutableList() } + model = labelModel.model + name = labelModel.name + passingLabels = labelModel.passingLabels.map { it.toMutableList() } + type = labelModel.type + additionalProperties = labelModel.additionalProperties.toMutableMap() + } + + fun input(input: List) = input(JsonField.of(input)) + + /** + * Sets [Builder.input] to an arbitrary JSON value. + * + * You should usually call [Builder.input] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun input(input: JsonField>) = apply { + this.input = input.map { it.toMutableList() } + } + + /** + * Adds a single [Input] to [Builder.input]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInput(input: Input) = apply { + this.input = + (this.input ?: JsonField.of(mutableListOf())).also { + checkKnown("input", it).add(input) + } + } + + /** + * Alias for calling [addInput] with + * `Input.ofSimpleInputMessage(simpleInputMessage)`. + */ + fun addInput(simpleInputMessage: Input.SimpleInputMessage) = + addInput(Input.ofSimpleInputMessage(simpleInputMessage)) + + /** Alias for calling [addInput] with `Input.ofMessage(message)`. */ + fun addInput(message: Input.InputMessage) = addInput(Input.ofMessage(message)) + + /** Alias for calling [addInput] with `Input.ofOutputMessage(outputMessage)`. */ + fun addInput(outputMessage: Input.OutputMessage) = + addInput(Input.ofOutputMessage(outputMessage)) + + /** The labels to classify to each item in the evaluation. */ + fun labels(labels: List) = labels(JsonField.of(labels)) + + /** + * Sets [Builder.labels] to an arbitrary JSON value. + * + * You should usually call [Builder.labels] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun labels(labels: JsonField>) = apply { + this.labels = labels.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [labels]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addLabel(label: String) = apply { + labels = + (labels ?: JsonField.of(mutableListOf())).also { + checkKnown("labels", it).add(label) + } + } + + /** The model to use for the evaluation. Must support structured outputs. */ + fun model(model: String) = model(JsonField.of(model)) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** The name of the grader. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** The labels that indicate a passing result. Must be a subset of labels. */ + fun passingLabels(passingLabels: List) = + passingLabels(JsonField.of(passingLabels)) + + /** + * Sets [Builder.passingLabels] to an arbitrary JSON value. + * + * You should usually call [Builder.passingLabels] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun passingLabels(passingLabels: JsonField>) = apply { + this.passingLabels = passingLabels.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [passingLabels]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPassingLabel(passingLabel: String) = apply { + passingLabels = + (passingLabels ?: JsonField.of(mutableListOf())).also { + checkKnown("passingLabels", it).add(passingLabel) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("label_model") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [LabelModel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .input() + * .labels() + * .model() + * .name() + * .passingLabels() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): LabelModel = + LabelModel( + checkRequired("input", input).map { it.toImmutable() }, + checkRequired("labels", labels).map { it.toImmutable() }, + checkRequired("model", model), + checkRequired("name", name), + checkRequired("passingLabels", passingLabels).map { it.toImmutable() }, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): LabelModel = apply { + if (validated) { + return@apply + } + + input().forEach { it.validate() } + labels() + model() + name() + passingLabels() + _type().let { + if (it != JsonValue.from("label_model")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (input.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (labels.asKnown().getOrNull()?.size ?: 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (passingLabels.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("label_model")) 1 else 0 } + + @JsonDeserialize(using = Input.Deserializer::class) + @JsonSerialize(using = Input.Serializer::class) + class Input + private constructor( + private val simpleInputMessage: SimpleInputMessage? = null, + private val message: InputMessage? = null, + private val outputMessage: OutputMessage? = null, + private val _json: JsonValue? = null, + ) { + + fun simpleInputMessage(): Optional = + Optional.ofNullable(simpleInputMessage) + + fun message(): Optional = Optional.ofNullable(message) + + fun outputMessage(): Optional = Optional.ofNullable(outputMessage) + + fun isSimpleInputMessage(): Boolean = simpleInputMessage != null + + fun isMessage(): Boolean = message != null + + fun isOutputMessage(): Boolean = outputMessage != null + + fun asSimpleInputMessage(): SimpleInputMessage = + simpleInputMessage.getOrThrow("simpleInputMessage") + + fun asMessage(): InputMessage = message.getOrThrow("message") + + fun asOutputMessage(): OutputMessage = outputMessage.getOrThrow("outputMessage") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + simpleInputMessage != null -> + visitor.visitSimpleInputMessage(simpleInputMessage) + message != null -> visitor.visitMessage(message) + outputMessage != null -> visitor.visitOutputMessage(outputMessage) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Input = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitSimpleInputMessage( + simpleInputMessage: SimpleInputMessage + ) { + simpleInputMessage.validate() + } + + override fun visitMessage(message: InputMessage) { + message.validate() + } + + override fun visitOutputMessage(outputMessage: OutputMessage) { + outputMessage.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitSimpleInputMessage( + simpleInputMessage: SimpleInputMessage + ) = simpleInputMessage.validity() + + override fun visitMessage(message: InputMessage) = message.validity() + + override fun visitOutputMessage(outputMessage: OutputMessage) = + outputMessage.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Input && simpleInputMessage == other.simpleInputMessage && message == other.message && outputMessage == other.outputMessage /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(simpleInputMessage, message, outputMessage) /* spotless:on */ + + override fun toString(): String = + when { + simpleInputMessage != null -> + "Input{simpleInputMessage=$simpleInputMessage}" + message != null -> "Input{message=$message}" + outputMessage != null -> "Input{outputMessage=$outputMessage}" + _json != null -> "Input{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Input") + } + + companion object { + + @JvmStatic + fun ofSimpleInputMessage(simpleInputMessage: SimpleInputMessage) = + Input(simpleInputMessage = simpleInputMessage) + + @JvmStatic fun ofMessage(message: InputMessage) = Input(message = message) + + @JvmStatic + fun ofOutputMessage(outputMessage: OutputMessage) = + Input(outputMessage = outputMessage) + } + + /** + * An interface that defines how to map each variant of [Input] to a value of type + * [T]. + */ + interface Visitor { + + fun visitSimpleInputMessage(simpleInputMessage: SimpleInputMessage): T + + fun visitMessage(message: InputMessage): T + + fun visitOutputMessage(outputMessage: OutputMessage): T + + /** + * Maps an unknown variant of [Input] to a value of type [T]. + * + * An instance of [Input] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on + * an older version than the API, then the API may respond with new variants + * that the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Input: $json") + } + } + + internal class Deserializer : BaseDeserializer(Input::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Input { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef()) + ?.let { Input(simpleInputMessage = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + Input(message = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Input(outputMessage = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> Input(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Input::class) { + + override fun serialize( + value: Input, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.simpleInputMessage != null -> + generator.writeObject(value.simpleInputMessage) + value.message != null -> generator.writeObject(value.message) + value.outputMessage != null -> + generator.writeObject(value.outputMessage) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Input") + } + } + } + + class SimpleInputMessage + private constructor( + private val content: JsonField, + private val role: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + ) : this(content, role, mutableMapOf()) + + /** + * The content of the message. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun content(): String = content.getRequired("content") + + /** + * The role of the message (e.g. "system", "assistant", "user"). + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun role(): String = role.getRequired("role") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("content") + @ExcludeMissing + fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [role]. + * + * Unlike [role], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("role") @ExcludeMissing fun _role(): JsonField = role + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [SimpleInputMessage]. + * + * The following fields are required: + * ```java + * .content() + * .role() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SimpleInputMessage]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var role: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(simpleInputMessage: SimpleInputMessage) = apply { + content = simpleInputMessage.content + role = simpleInputMessage.role + additionalProperties = + simpleInputMessage.additionalProperties.toMutableMap() + } + + /** The content of the message. */ + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** The role of the message (e.g. "system", "assistant", "user"). */ + fun role(role: String) = role(JsonField.of(role)) + + /** + * Sets [Builder.role] to an arbitrary JSON value. + * + * You should usually call [Builder.role] with a well-typed [String] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun role(role: JsonField) = apply { this.role = role } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [SimpleInputMessage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .role() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SimpleInputMessage = + SimpleInputMessage( + checkRequired("content", content), + checkRequired("role", role), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SimpleInputMessage = apply { + if (validated) { + return@apply + } + + content() + role() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (content.asKnown().isPresent) 1 else 0) + + (if (role.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SimpleInputMessage && content == other.content && role == other.role && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(content, role, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SimpleInputMessage{content=$content, role=$role, additionalProperties=$additionalProperties}" + } + + class InputMessage + private constructor( + private val content: JsonField, + private val role: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(content, role, type, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun content(): Content = content.getRequired("content") + + /** + * The role of the message. One of `user`, `system`, or `developer`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun role(): Role = role.getRequired("role") + + /** + * The type of item, which is always `message`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("content") + @ExcludeMissing + fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [role]. + * + * Unlike [role], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("role") @ExcludeMissing fun _role(): JsonField = role + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [InputMessage]. + * + * The following fields are required: + * ```java + * .content() + * .role() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputMessage]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var role: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(inputMessage: InputMessage) = apply { + content = inputMessage.content + role = inputMessage.role + type = inputMessage.type + additionalProperties = inputMessage.additionalProperties.toMutableMap() + } + + fun content(content: Content) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [Content] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** The role of the message. One of `user`, `system`, or `developer`. */ + fun role(role: Role) = role(JsonField.of(role)) + + /** + * Sets [Builder.role] to an arbitrary JSON value. + * + * You should usually call [Builder.role] with a well-typed [Role] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun role(role: JsonField) = apply { this.role = role } + + /** The type of item, which is always `message`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputMessage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .role() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InputMessage = + InputMessage( + checkRequired("content", content), + checkRequired("role", role), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InputMessage = apply { + if (validated) { + return@apply + } + + content().validate() + role().validate() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (content.asKnown().getOrNull()?.validity() ?: 0) + + (role.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Content + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") + @ExcludeMissing + text: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * The text content. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun text(): String = text.getRequired("text") + + /** + * The type of content, which is always `input_text`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Content]. + * + * The following fields are required: + * ```java + * .text() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Content]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(content: Content) = apply { + text = content.text + type = content.type + additionalProperties = content.additionalProperties.toMutableMap() + } + + /** The text content. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** The type of content, which is always `input_text`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Content]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .text() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Content = + Content( + checkRequired("text", text), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Content = apply { + if (validated) { + return@apply + } + + text() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (text.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** The type of content, which is always `input_text`. */ + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val INPUT_TEXT = of("input_text") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + INPUT_TEXT + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Type] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INPUT_TEXT, + /** + * An enum member indicating that [Type] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INPUT_TEXT -> Value.INPUT_TEXT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is + * a not a known member. + */ + fun known(): Known = + when (this) { + INPUT_TEXT -> Known.INPUT_TEXT + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Content && text == other.text && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Content{text=$text, type=$type, additionalProperties=$additionalProperties}" + } + + /** The role of the message. One of `user`, `system`, or `developer`. */ + class Role + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data + * that doesn't match any known member, and you want to know that value. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val USER = of("user") + + @JvmField val SYSTEM = of("system") + + @JvmField val DEVELOPER = of("developer") + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + /** An enum containing [Role]'s known values. */ + enum class Known { + USER, + SYSTEM, + DEVELOPER, + } + + /** + * An enum containing [Role]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Role] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API + * may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USER, + SYSTEM, + DEVELOPER, + /** + * An enum member indicating that [Role] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USER -> Value.USER + SYSTEM -> Value.SYSTEM + DEVELOPER -> Value.DEVELOPER + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always + * known and don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + USER -> Known.USER + SYSTEM -> Known.SYSTEM + DEVELOPER -> Known.DEVELOPER + else -> throw OpenAIInvalidDataException("Unknown Role: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily + * for debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The type of item, which is always `message`. */ + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data + * that doesn't match any known member, and you want to know that value. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val MESSAGE = of("message") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MESSAGE + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API + * may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MESSAGE, + /** + * An enum member indicating that [Type] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MESSAGE -> Value.MESSAGE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always + * known and don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + MESSAGE -> Known.MESSAGE + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily + * for debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is InputMessage && content == other.content && role == other.role && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(content, role, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InputMessage{content=$content, role=$role, type=$type, additionalProperties=$additionalProperties}" + } + + class OutputMessage + private constructor( + private val content: JsonField, + private val role: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("role") + @ExcludeMissing + role: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(content, role, type, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun content(): Content = content.getRequired("content") + + /** + * The role of the message. Must be `assistant` for output. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun role(): Role = role.getRequired("role") + + /** + * The type of item, which is always `message`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type + * or is unexpectedly missing or null (e.g. if the server responded with an + * unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("content") + @ExcludeMissing + fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [role]. + * + * Unlike [role], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("role") @ExcludeMissing fun _role(): JsonField = role + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [OutputMessage]. + * + * The following fields are required: + * ```java + * .content() + * .role() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OutputMessage]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var role: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(outputMessage: OutputMessage) = apply { + content = outputMessage.content + role = outputMessage.role + type = outputMessage.type + additionalProperties = outputMessage.additionalProperties.toMutableMap() + } + + fun content(content: Content) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [Content] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** The role of the message. Must be `assistant` for output. */ + fun role(role: Role) = role(JsonField.of(role)) + + /** + * Sets [Builder.role] to an arbitrary JSON value. + * + * You should usually call [Builder.role] with a well-typed [Role] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun role(role: JsonField) = apply { this.role = role } + + /** The type of item, which is always `message`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [OutputMessage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .role() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OutputMessage = + OutputMessage( + checkRequired("content", content), + checkRequired("role", role), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): OutputMessage = apply { + if (validated) { + return@apply + } + + content().validate() + role().validate() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (content.asKnown().getOrNull()?.validity() ?: 0) + + (role.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Content + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") + @ExcludeMissing + text: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * The text content. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun text(): String = text.getRequired("text") + + /** + * The type of content, which is always `output_text`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected + * type or is unexpectedly missing or null (e.g. if the server responded + * with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Content]. + * + * The following fields are required: + * ```java + * .text() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Content]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(content: Content) = apply { + text = content.text + type = content.type + additionalProperties = content.additionalProperties.toMutableMap() + } + + /** The text content. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] + * value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** The type of content, which is always `output_text`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Content]. + * + * Further updates to this [Builder] will not mutate the returned + * instance. + * + * The following fields are required: + * ```java + * .text() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Content = + Content( + checkRequired("text", text), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Content = apply { + if (validated) { + return@apply + } + + text() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (text.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** The type of content, which is always `output_text`. */ + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from + * data that doesn't match any known member, and you want to know that + * value. For example, if the SDK is on an older version than the API, + * then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val OUTPUT_TEXT = of("output_text") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + OUTPUT_TEXT + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Type] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. + * For example, if the SDK is on an older version than the API, then + * the API may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + OUTPUT_TEXT, + /** + * An enum member indicating that [Type] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, + * or [Value._UNKNOWN] if the class was instantiated with an unknown + * value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + OUTPUT_TEXT -> Value.OUTPUT_TEXT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is + * always known and don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is + * a not a known member. + */ + fun known(): Known = + when (this) { + OUTPUT_TEXT -> Known.OUTPUT_TEXT + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is + * primarily for debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value + * does not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in + * this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Content && text == other.text && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Content{text=$text, type=$type, additionalProperties=$additionalProperties}" + } + + /** The role of the message. Must be `assistant` for output. */ + class Role + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data + * that doesn't match any known member, and you want to know that value. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val ASSISTANT = of("assistant") + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + /** An enum containing [Role]'s known values. */ + enum class Known { + ASSISTANT + } + + /** + * An enum containing [Role]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Role] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API + * may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ASSISTANT, + /** + * An enum member indicating that [Role] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always + * known and don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> throw OpenAIInvalidDataException("Unknown Role: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily + * for debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The type of item, which is always `message`. */ + class Type + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data + * that doesn't match any known member, and you want to know that value. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val MESSAGE = of("message") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MESSAGE + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API + * may respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MESSAGE, + /** + * An enum member indicating that [Type] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always + * known or if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MESSAGE -> Value.MESSAGE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always + * known and don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a + * not a known member. + */ + fun known(): Known = + when (this) { + MESSAGE -> Known.MESSAGE + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily + * for debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does + * not have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OutputMessage && content == other.content && role == other.role && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(content, role, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OutputMessage{content=$content, role=$role, type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is LabelModel && input == other.input && labels == other.labels && model == other.model && name == other.name && passingLabels == other.passingLabels && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(input, labels, model, name, passingLabels, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "LabelModel{input=$input, labels=$labels, model=$model, name=$name, passingLabels=$passingLabels, type=$type, additionalProperties=$additionalProperties}" + } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "EvalCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateResponse.kt new file mode 100644 index 00000000..213a026b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateResponse.kt @@ -0,0 +1,1145 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * An Eval object with a data source config and testing criteria. An Eval represents a task to be + * done for your LLM integration. Like: + * - Improve the quality of my chatbot + * - See how well my chatbot handles customer support + * - Check if o3-mini is better at my usecase than gpt-4o + */ +class EvalCreateResponse +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val dataSourceConfig: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val object_: JsonValue, + private val shareWithOpenAI: JsonField, + private val testingCriteria: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("data_source_config") + @ExcludeMissing + dataSourceConfig: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("share_with_openai") + @ExcludeMissing + shareWithOpenAI: JsonField = JsonMissing.of(), + @JsonProperty("testing_criteria") + @ExcludeMissing + testingCriteria: JsonField> = JsonMissing.of(), + ) : this( + id, + createdAt, + dataSourceConfig, + metadata, + name, + object_, + shareWithOpenAI, + testingCriteria, + mutableMapOf(), + ) + + /** + * Unique identifier for the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * The Unix timestamp (in seconds) for when the eval was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Long = createdAt.getRequired("created_at") + + /** + * Configuration of data sources used in runs of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dataSourceConfig(): DataSourceConfig = dataSourceConfig.getRequired("data_source_config") + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * The name of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The object type. + * + * Expected to always return the following: + * ```java + * JsonValue.from("eval") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Indicates whether the evaluation is shared with OpenAI. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun shareWithOpenAI(): Boolean = shareWithOpenAI.getRequired("share_with_openai") + + /** + * A list of testing criteria. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun testingCriteria(): List = testingCriteria.getRequired("testing_criteria") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [dataSourceConfig]. + * + * Unlike [dataSourceConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("data_source_config") + @ExcludeMissing + fun _dataSourceConfig(): JsonField = dataSourceConfig + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [shareWithOpenAI]. + * + * Unlike [shareWithOpenAI], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("share_with_openai") + @ExcludeMissing + fun _shareWithOpenAI(): JsonField = shareWithOpenAI + + /** + * Returns the raw JSON value of [testingCriteria]. + * + * Unlike [testingCriteria], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("testing_criteria") + @ExcludeMissing + fun _testingCriteria(): JsonField> = testingCriteria + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalCreateResponse]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .dataSourceConfig() + * .metadata() + * .name() + * .shareWithOpenAI() + * .testingCriteria() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalCreateResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var dataSourceConfig: JsonField? = null + private var metadata: JsonField? = null + private var name: JsonField? = null + private var object_: JsonValue = JsonValue.from("eval") + private var shareWithOpenAI: JsonField? = null + private var testingCriteria: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalCreateResponse: EvalCreateResponse) = apply { + id = evalCreateResponse.id + createdAt = evalCreateResponse.createdAt + dataSourceConfig = evalCreateResponse.dataSourceConfig + metadata = evalCreateResponse.metadata + name = evalCreateResponse.name + object_ = evalCreateResponse.object_ + shareWithOpenAI = evalCreateResponse.shareWithOpenAI + testingCriteria = evalCreateResponse.testingCriteria.map { it.toMutableList() } + additionalProperties = evalCreateResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier for the evaluation. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** The Unix timestamp (in seconds) for when the eval was created. */ + fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Configuration of data sources used in runs of the evaluation. */ + fun dataSourceConfig(dataSourceConfig: DataSourceConfig) = + dataSourceConfig(JsonField.of(dataSourceConfig)) + + /** + * Sets [Builder.dataSourceConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.dataSourceConfig] with a well-typed [DataSourceConfig] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dataSourceConfig(dataSourceConfig: JsonField) = apply { + this.dataSourceConfig = dataSourceConfig + } + + /** Alias for calling [dataSourceConfig] with `DataSourceConfig.ofCustom(custom)`. */ + fun dataSourceConfig(custom: EvalCustomDataSourceConfig) = + dataSourceConfig(DataSourceConfig.ofCustom(custom)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * EvalCustomDataSourceConfig.builder() + * .schema(schema) + * .build() + * ``` + */ + fun customDataSourceConfig(schema: EvalCustomDataSourceConfig.Schema) = + dataSourceConfig(EvalCustomDataSourceConfig.builder().schema(schema).build()) + + /** + * Alias for calling [dataSourceConfig] with + * `DataSourceConfig.ofStoredCompletions(storedCompletions)`. + */ + fun dataSourceConfig(storedCompletions: EvalStoredCompletionsDataSourceConfig) = + dataSourceConfig(DataSourceConfig.ofStoredCompletions(storedCompletions)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * EvalStoredCompletionsDataSourceConfig.builder() + * .schema(schema) + * .build() + * ``` + */ + fun storedCompletionsDataSourceConfig( + schema: EvalStoredCompletionsDataSourceConfig.Schema + ) = dataSourceConfig(EvalStoredCompletionsDataSourceConfig.builder().schema(schema).build()) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** The name of the evaluation. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("eval") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Indicates whether the evaluation is shared with OpenAI. */ + fun shareWithOpenAI(shareWithOpenAI: Boolean) = + shareWithOpenAI(JsonField.of(shareWithOpenAI)) + + /** + * Sets [Builder.shareWithOpenAI] to an arbitrary JSON value. + * + * You should usually call [Builder.shareWithOpenAI] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun shareWithOpenAI(shareWithOpenAI: JsonField) = apply { + this.shareWithOpenAI = shareWithOpenAI + } + + /** A list of testing criteria. */ + fun testingCriteria(testingCriteria: List) = + testingCriteria(JsonField.of(testingCriteria)) + + /** + * Sets [Builder.testingCriteria] to an arbitrary JSON value. + * + * You should usually call [Builder.testingCriteria] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun testingCriteria(testingCriteria: JsonField>) = apply { + this.testingCriteria = testingCriteria.map { it.toMutableList() } + } + + /** + * Adds a single [TestingCriterion] to [testingCriteria]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTestingCriterion(testingCriterion: TestingCriterion) = apply { + testingCriteria = + (testingCriteria ?: JsonField.of(mutableListOf())).also { + checkKnown("testingCriteria", it).add(testingCriterion) + } + } + + /** + * Alias for calling [addTestingCriterion] with `TestingCriterion.ofLabelModel(labelModel)`. + */ + fun addTestingCriterion(labelModel: EvalLabelModelGrader) = + addTestingCriterion(TestingCriterion.ofLabelModel(labelModel)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofStringCheck(stringCheck)`. + */ + fun addTestingCriterion(stringCheck: EvalStringCheckGrader) = + addTestingCriterion(TestingCriterion.ofStringCheck(stringCheck)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofTextSimilarity(textSimilarity)`. + */ + fun addTestingCriterion(textSimilarity: EvalTextSimilarityGrader) = + addTestingCriterion(TestingCriterion.ofTextSimilarity(textSimilarity)) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalCreateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .dataSourceConfig() + * .metadata() + * .name() + * .shareWithOpenAI() + * .testingCriteria() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalCreateResponse = + EvalCreateResponse( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("dataSourceConfig", dataSourceConfig), + checkRequired("metadata", metadata), + checkRequired("name", name), + object_, + checkRequired("shareWithOpenAI", shareWithOpenAI), + checkRequired("testingCriteria", testingCriteria).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalCreateResponse = apply { + if (validated) { + return@apply + } + + id() + createdAt() + dataSourceConfig().validate() + metadata().ifPresent { it.validate() } + name() + _object_().let { + if (it != JsonValue.from("eval")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + shareWithOpenAI() + testingCriteria().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (dataSourceConfig.asKnown().getOrNull()?.validity() ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("eval")) 1 else 0 } + + (if (shareWithOpenAI.asKnown().isPresent) 1 else 0) + + (testingCriteria.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration of data sources used in runs of the evaluation. */ + @JsonDeserialize(using = DataSourceConfig.Deserializer::class) + @JsonSerialize(using = DataSourceConfig.Serializer::class) + class DataSourceConfig + private constructor( + private val custom: EvalCustomDataSourceConfig? = null, + private val storedCompletions: EvalStoredCompletionsDataSourceConfig? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun custom(): Optional = Optional.ofNullable(custom) + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both defined + * when using this data source config. + */ + fun storedCompletions(): Optional = + Optional.ofNullable(storedCompletions) + + fun isCustom(): Boolean = custom != null + + fun isStoredCompletions(): Boolean = storedCompletions != null + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun asCustom(): EvalCustomDataSourceConfig = custom.getOrThrow("custom") + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both defined + * when using this data source config. + */ + fun asStoredCompletions(): EvalStoredCompletionsDataSourceConfig = + storedCompletions.getOrThrow("storedCompletions") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + custom != null -> visitor.visitCustom(custom) + storedCompletions != null -> visitor.visitStoredCompletions(storedCompletions) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): DataSourceConfig = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustom(custom: EvalCustomDataSourceConfig) { + custom.validate() + } + + override fun visitStoredCompletions( + storedCompletions: EvalStoredCompletionsDataSourceConfig + ) { + storedCompletions.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCustom(custom: EvalCustomDataSourceConfig) = custom.validity() + + override fun visitStoredCompletions( + storedCompletions: EvalStoredCompletionsDataSourceConfig + ) = storedCompletions.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DataSourceConfig && custom == other.custom && storedCompletions == other.storedCompletions /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(custom, storedCompletions) /* spotless:on */ + + override fun toString(): String = + when { + custom != null -> "DataSourceConfig{custom=$custom}" + storedCompletions != null -> + "DataSourceConfig{storedCompletions=$storedCompletions}" + _json != null -> "DataSourceConfig{_unknown=$_json}" + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + + companion object { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + @JvmStatic + fun ofCustom(custom: EvalCustomDataSourceConfig) = DataSourceConfig(custom = custom) + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your + * stored completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both + * defined when using this data source config. + */ + @JvmStatic + fun ofStoredCompletions(storedCompletions: EvalStoredCompletionsDataSourceConfig) = + DataSourceConfig(storedCompletions = storedCompletions) + } + + /** + * An interface that defines how to map each variant of [DataSourceConfig] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun visitCustom(custom: EvalCustomDataSourceConfig): T + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your + * stored completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both + * defined when using this data source config. + */ + fun visitStoredCompletions(storedCompletions: EvalStoredCompletionsDataSourceConfig): T + + /** + * Maps an unknown variant of [DataSourceConfig] to a value of type [T]. + * + * An instance of [DataSourceConfig] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown DataSourceConfig: $json") + } + } + + internal class Deserializer : BaseDeserializer(DataSourceConfig::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): DataSourceConfig { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "custom" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { DataSourceConfig(custom = it, _json = json) } + ?: DataSourceConfig(_json = json) + } + "stored_completions" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { DataSourceConfig(storedCompletions = it, _json = json) } + ?: DataSourceConfig(_json = json) + } + } + + return DataSourceConfig(_json = json) + } + } + + internal class Serializer : BaseSerializer(DataSourceConfig::class) { + + override fun serialize( + value: DataSourceConfig, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.custom != null -> generator.writeObject(value.custom) + value.storedCompletions != null -> + generator.writeObject(value.storedCompletions) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + } + } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the evaluation. + */ + @JsonDeserialize(using = TestingCriterion.Deserializer::class) + @JsonSerialize(using = TestingCriterion.Serializer::class) + class TestingCriterion + private constructor( + private val labelModel: EvalLabelModelGrader? = null, + private val stringCheck: EvalStringCheckGrader? = null, + private val textSimilarity: EvalTextSimilarityGrader? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun labelModel(): Optional = Optional.ofNullable(labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun stringCheck(): Optional = Optional.ofNullable(stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun textSimilarity(): Optional = + Optional.ofNullable(textSimilarity) + + fun isLabelModel(): Boolean = labelModel != null + + fun isStringCheck(): Boolean = stringCheck != null + + fun isTextSimilarity(): Boolean = textSimilarity != null + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun asLabelModel(): EvalLabelModelGrader = labelModel.getOrThrow("labelModel") + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun asStringCheck(): EvalStringCheckGrader = stringCheck.getOrThrow("stringCheck") + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun asTextSimilarity(): EvalTextSimilarityGrader = + textSimilarity.getOrThrow("textSimilarity") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + labelModel != null -> visitor.visitLabelModel(labelModel) + stringCheck != null -> visitor.visitStringCheck(stringCheck) + textSimilarity != null -> visitor.visitTextSimilarity(textSimilarity) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): TestingCriterion = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitLabelModel(labelModel: EvalLabelModelGrader) { + labelModel.validate() + } + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) { + stringCheck.validate() + } + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) { + textSimilarity.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitLabelModel(labelModel: EvalLabelModelGrader) = + labelModel.validity() + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) = + stringCheck.validity() + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + textSimilarity.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TestingCriterion && labelModel == other.labelModel && stringCheck == other.stringCheck && textSimilarity == other.textSimilarity /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(labelModel, stringCheck, textSimilarity) /* spotless:on */ + + override fun toString(): String = + when { + labelModel != null -> "TestingCriterion{labelModel=$labelModel}" + stringCheck != null -> "TestingCriterion{stringCheck=$stringCheck}" + textSimilarity != null -> "TestingCriterion{textSimilarity=$textSimilarity}" + _json != null -> "TestingCriterion{_unknown=$_json}" + else -> throw IllegalStateException("Invalid TestingCriterion") + } + + companion object { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + @JvmStatic + fun ofLabelModel(labelModel: EvalLabelModelGrader) = + TestingCriterion(labelModel = labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + @JvmStatic + fun ofStringCheck(stringCheck: EvalStringCheckGrader) = + TestingCriterion(stringCheck = stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + @JvmStatic + fun ofTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + TestingCriterion(textSimilarity = textSimilarity) + } + + /** + * An interface that defines how to map each variant of [TestingCriterion] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun visitLabelModel(labelModel: EvalLabelModelGrader): T + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + fun visitStringCheck(stringCheck: EvalStringCheckGrader): T + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader): T + + /** + * Maps an unknown variant of [TestingCriterion] to a value of type [T]. + * + * An instance of [TestingCriterion] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown TestingCriterion: $json") + } + } + + internal class Deserializer : BaseDeserializer(TestingCriterion::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): TestingCriterion { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "label_model" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(labelModel = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "string_check" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(stringCheck = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "text_similarity" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { TestingCriterion(textSimilarity = it, _json = json) } + ?: TestingCriterion(_json = json) + } + } + + return TestingCriterion(_json = json) + } + } + + internal class Serializer : BaseSerializer(TestingCriterion::class) { + + override fun serialize( + value: TestingCriterion, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.labelModel != null -> generator.writeObject(value.labelModel) + value.stringCheck != null -> generator.writeObject(value.stringCheck) + value.textSimilarity != null -> generator.writeObject(value.textSimilarity) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid TestingCriterion") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalCreateResponse && id == other.id && createdAt == other.createdAt && dataSourceConfig == other.dataSourceConfig && metadata == other.metadata && name == other.name && object_ == other.object_ && shareWithOpenAI == other.shareWithOpenAI && testingCriteria == other.testingCriteria && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, createdAt, dataSourceConfig, metadata, name, object_, shareWithOpenAI, testingCriteria, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalCreateResponse{id=$id, createdAt=$createdAt, dataSourceConfig=$dataSourceConfig, metadata=$metadata, name=$name, object_=$object_, shareWithOpenAI=$shareWithOpenAI, testingCriteria=$testingCriteria, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCustomDataSourceConfig.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCustomDataSourceConfig.kt new file mode 100644 index 00000000..5eea5f90 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCustomDataSourceConfig.kt @@ -0,0 +1,329 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally `sample` + * namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ +class EvalCustomDataSourceConfig +private constructor( + private val schema: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("schema") @ExcludeMissing schema: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(schema, type, mutableMapOf()) + + /** + * The json schema for the run data source items. Learn how to build JSON schemas + * [here](https://json-schema.org/). + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun schema(): Schema = schema.getRequired("schema") + + /** + * The type of data source. Always `custom`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("custom") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [schema]. + * + * Unlike [schema], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("schema") @ExcludeMissing fun _schema(): JsonField = schema + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalCustomDataSourceConfig]. + * + * The following fields are required: + * ```java + * .schema() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalCustomDataSourceConfig]. */ + class Builder internal constructor() { + + private var schema: JsonField? = null + private var type: JsonValue = JsonValue.from("custom") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalCustomDataSourceConfig: EvalCustomDataSourceConfig) = apply { + schema = evalCustomDataSourceConfig.schema + type = evalCustomDataSourceConfig.type + additionalProperties = evalCustomDataSourceConfig.additionalProperties.toMutableMap() + } + + /** + * The json schema for the run data source items. Learn how to build JSON schemas + * [here](https://json-schema.org/). + */ + fun schema(schema: Schema) = schema(JsonField.of(schema)) + + /** + * Sets [Builder.schema] to an arbitrary JSON value. + * + * You should usually call [Builder.schema] with a well-typed [Schema] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun schema(schema: JsonField) = apply { this.schema = schema } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("custom") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalCustomDataSourceConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .schema() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalCustomDataSourceConfig = + EvalCustomDataSourceConfig( + checkRequired("schema", schema), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalCustomDataSourceConfig = apply { + if (validated) { + return@apply + } + + schema().validate() + _type().let { + if (it != JsonValue.from("custom")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (schema.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("custom")) 1 else 0 } + + /** + * The json schema for the run data source items. Learn how to build JSON schemas + * [here](https://json-schema.org/). + */ + class Schema + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Schema]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Schema]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(schema: Schema) = apply { + additionalProperties = schema.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Schema]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Schema = Schema(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Schema = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Schema && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Schema{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalCustomDataSourceConfig && schema == other.schema && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(schema, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalCustomDataSourceConfig{schema=$schema, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalDeleteParams.kt new file mode 100644 index 00000000..7220bde2 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalDeleteParams.kt @@ -0,0 +1,230 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +/** Delete an evaluation. */ +class EvalDeleteParams +private constructor( + private val evalId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun evalId(): String = evalId + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalDeleteParams]. + * + * The following fields are required: + * ```java + * .evalId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalDeleteParams]. */ + class Builder internal constructor() { + + private var evalId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalDeleteParams: EvalDeleteParams) = apply { + evalId = evalDeleteParams.evalId + additionalHeaders = evalDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = evalDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = evalDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun evalId(evalId: String) = apply { this.evalId = evalId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [EvalDeleteParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .evalId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalDeleteParams = + EvalDeleteParams( + checkRequired("evalId", evalId), + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> evalId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalDeleteParams && evalId == other.evalId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(evalId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + + override fun toString() = + "EvalDeleteParams{evalId=$evalId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalDeleteResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalDeleteResponse.kt new file mode 100644 index 00000000..3dc989f4 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalDeleteResponse.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects + +class EvalDeleteResponse +private constructor( + private val deleted: JsonField, + private val evalId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("deleted") @ExcludeMissing deleted: JsonField = JsonMissing.of(), + @JsonProperty("eval_id") @ExcludeMissing evalId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(deleted, evalId, object_, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun deleted(): Boolean = deleted.getRequired("deleted") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun evalId(): String = evalId.getRequired("eval_id") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [deleted]. + * + * Unlike [deleted], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("deleted") @ExcludeMissing fun _deleted(): JsonField = deleted + + /** + * Returns the raw JSON value of [evalId]. + * + * Unlike [evalId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("eval_id") @ExcludeMissing fun _evalId(): JsonField = evalId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalDeleteResponse]. + * + * The following fields are required: + * ```java + * .deleted() + * .evalId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalDeleteResponse]. */ + class Builder internal constructor() { + + private var deleted: JsonField? = null + private var evalId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalDeleteResponse: EvalDeleteResponse) = apply { + deleted = evalDeleteResponse.deleted + evalId = evalDeleteResponse.evalId + object_ = evalDeleteResponse.object_ + additionalProperties = evalDeleteResponse.additionalProperties.toMutableMap() + } + + fun deleted(deleted: Boolean) = deleted(JsonField.of(deleted)) + + /** + * Sets [Builder.deleted] to an arbitrary JSON value. + * + * You should usually call [Builder.deleted] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun deleted(deleted: JsonField) = apply { this.deleted = deleted } + + fun evalId(evalId: String) = evalId(JsonField.of(evalId)) + + /** + * Sets [Builder.evalId] to an arbitrary JSON value. + * + * You should usually call [Builder.evalId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun evalId(evalId: JsonField) = apply { this.evalId = evalId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalDeleteResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .deleted() + * .evalId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalDeleteResponse = + EvalDeleteResponse( + checkRequired("deleted", deleted), + checkRequired("evalId", evalId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalDeleteResponse = apply { + if (validated) { + return@apply + } + + deleted() + evalId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (deleted.asKnown().isPresent) 1 else 0) + + (if (evalId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalDeleteResponse && deleted == other.deleted && evalId == other.evalId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(deleted, evalId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalDeleteResponse{deleted=$deleted, evalId=$evalId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalLabelModelGrader.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalLabelModelGrader.kt new file mode 100644 index 00000000..680035be --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalLabelModelGrader.kt @@ -0,0 +1,2108 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A LabelModelGrader object which uses a model to assign labels to each item in the evaluation. */ +class EvalLabelModelGrader +private constructor( + private val input: JsonField>, + private val labels: JsonField>, + private val model: JsonField, + private val name: JsonField, + private val passingLabels: JsonField>, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("input") @ExcludeMissing input: JsonField> = JsonMissing.of(), + @JsonProperty("labels") @ExcludeMissing labels: JsonField> = JsonMissing.of(), + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("passing_labels") + @ExcludeMissing + passingLabels: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(input, labels, model, name, passingLabels, type, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun input(): List = input.getRequired("input") + + /** + * The labels to assign to each item in the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun labels(): List = labels.getRequired("labels") + + /** + * The model to use for the evaluation. Must support structured outputs. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun model(): String = model.getRequired("model") + + /** + * The name of the grader. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The labels that indicate a passing result. Must be a subset of labels. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun passingLabels(): List = passingLabels.getRequired("passing_labels") + + /** + * The object type, which is always `label_model`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("label_model") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [input]. + * + * Unlike [input], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input") @ExcludeMissing fun _input(): JsonField> = input + + /** + * Returns the raw JSON value of [labels]. + * + * Unlike [labels], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("labels") @ExcludeMissing fun _labels(): JsonField> = labels + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [passingLabels]. + * + * Unlike [passingLabels], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("passing_labels") + @ExcludeMissing + fun _passingLabels(): JsonField> = passingLabels + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalLabelModelGrader]. + * + * The following fields are required: + * ```java + * .input() + * .labels() + * .model() + * .name() + * .passingLabels() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalLabelModelGrader]. */ + class Builder internal constructor() { + + private var input: JsonField>? = null + private var labels: JsonField>? = null + private var model: JsonField? = null + private var name: JsonField? = null + private var passingLabels: JsonField>? = null + private var type: JsonValue = JsonValue.from("label_model") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalLabelModelGrader: EvalLabelModelGrader) = apply { + input = evalLabelModelGrader.input.map { it.toMutableList() } + labels = evalLabelModelGrader.labels.map { it.toMutableList() } + model = evalLabelModelGrader.model + name = evalLabelModelGrader.name + passingLabels = evalLabelModelGrader.passingLabels.map { it.toMutableList() } + type = evalLabelModelGrader.type + additionalProperties = evalLabelModelGrader.additionalProperties.toMutableMap() + } + + fun input(input: List) = input(JsonField.of(input)) + + /** + * Sets [Builder.input] to an arbitrary JSON value. + * + * You should usually call [Builder.input] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun input(input: JsonField>) = apply { + this.input = input.map { it.toMutableList() } + } + + /** + * Adds a single [Input] to [Builder.input]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInput(input: Input) = apply { + this.input = + (this.input ?: JsonField.of(mutableListOf())).also { + checkKnown("input", it).add(input) + } + } + + /** Alias for calling [addInput] with `Input.ofMessage(message)`. */ + fun addInput(message: Input.InputMessage) = addInput(Input.ofMessage(message)) + + /** Alias for calling [addInput] with `Input.ofAssistant(assistant)`. */ + fun addInput(assistant: Input.Assistant) = addInput(Input.ofAssistant(assistant)) + + /** The labels to assign to each item in the evaluation. */ + fun labels(labels: List) = labels(JsonField.of(labels)) + + /** + * Sets [Builder.labels] to an arbitrary JSON value. + * + * You should usually call [Builder.labels] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun labels(labels: JsonField>) = apply { + this.labels = labels.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [labels]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addLabel(label: String) = apply { + labels = + (labels ?: JsonField.of(mutableListOf())).also { + checkKnown("labels", it).add(label) + } + } + + /** The model to use for the evaluation. Must support structured outputs. */ + fun model(model: String) = model(JsonField.of(model)) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** The name of the grader. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** The labels that indicate a passing result. Must be a subset of labels. */ + fun passingLabels(passingLabels: List) = passingLabels(JsonField.of(passingLabels)) + + /** + * Sets [Builder.passingLabels] to an arbitrary JSON value. + * + * You should usually call [Builder.passingLabels] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun passingLabels(passingLabels: JsonField>) = apply { + this.passingLabels = passingLabels.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [passingLabels]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPassingLabel(passingLabel: String) = apply { + passingLabels = + (passingLabels ?: JsonField.of(mutableListOf())).also { + checkKnown("passingLabels", it).add(passingLabel) + } + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("label_model") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalLabelModelGrader]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .input() + * .labels() + * .model() + * .name() + * .passingLabels() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalLabelModelGrader = + EvalLabelModelGrader( + checkRequired("input", input).map { it.toImmutable() }, + checkRequired("labels", labels).map { it.toImmutable() }, + checkRequired("model", model), + checkRequired("name", name), + checkRequired("passingLabels", passingLabels).map { it.toImmutable() }, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalLabelModelGrader = apply { + if (validated) { + return@apply + } + + input().forEach { it.validate() } + labels() + model() + name() + passingLabels() + _type().let { + if (it != JsonValue.from("label_model")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (input.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (labels.asKnown().getOrNull()?.size ?: 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (passingLabels.asKnown().getOrNull()?.size ?: 0) + + type.let { if (it == JsonValue.from("label_model")) 1 else 0 } + + /** An item can either be an input message or an output message. */ + @JsonDeserialize(using = Input.Deserializer::class) + @JsonSerialize(using = Input.Serializer::class) + class Input + private constructor( + private val message: InputMessage? = null, + private val assistant: Assistant? = null, + private val _json: JsonValue? = null, + ) { + + fun message(): Optional = Optional.ofNullable(message) + + fun assistant(): Optional = Optional.ofNullable(assistant) + + fun isMessage(): Boolean = message != null + + fun isAssistant(): Boolean = assistant != null + + fun asMessage(): InputMessage = message.getOrThrow("message") + + fun asAssistant(): Assistant = assistant.getOrThrow("assistant") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + message != null -> visitor.visitMessage(message) + assistant != null -> visitor.visitAssistant(assistant) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Input = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitMessage(message: InputMessage) { + message.validate() + } + + override fun visitAssistant(assistant: Assistant) { + assistant.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitMessage(message: InputMessage) = message.validity() + + override fun visitAssistant(assistant: Assistant) = assistant.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Input && message == other.message && assistant == other.assistant /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(message, assistant) /* spotless:on */ + + override fun toString(): String = + when { + message != null -> "Input{message=$message}" + assistant != null -> "Input{assistant=$assistant}" + _json != null -> "Input{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Input") + } + + companion object { + + @JvmStatic fun ofMessage(message: InputMessage) = Input(message = message) + + @JvmStatic fun ofAssistant(assistant: Assistant) = Input(assistant = assistant) + } + + /** An interface that defines how to map each variant of [Input] to a value of type [T]. */ + interface Visitor { + + fun visitMessage(message: InputMessage): T + + fun visitAssistant(assistant: Assistant): T + + /** + * Maps an unknown variant of [Input] to a value of type [T]. + * + * An instance of [Input] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Input: $json") + } + } + + internal class Deserializer : BaseDeserializer(Input::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Input { + val json = JsonValue.fromJsonNode(node) + val role = json.asObject().getOrNull()?.get("role")?.asString()?.getOrNull() + + if (role == "assistant") { + return tryDeserialize(node, jacksonTypeRef())?.let { + Input(assistant = it, _json = json) + } ?: Input(_json = json) + } + + return tryDeserialize(node, jacksonTypeRef())?.let { + Input(message = it, _json = json) + } ?: Input(_json = json) + } + } + + internal class Serializer : BaseSerializer(Input::class) { + + override fun serialize( + value: Input, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.message != null -> generator.writeObject(value.message) + value.assistant != null -> generator.writeObject(value.assistant) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Input") + } + } + } + + class InputMessage + private constructor( + private val content: JsonField, + private val role: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(content, role, type, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun content(): Content = content.getRequired("content") + + /** + * The role of the message. One of `user`, `system`, or `developer`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun role(): Role = role.getRequired("role") + + /** + * The type of item, which is always `message`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [role]. + * + * Unlike [role], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("role") @ExcludeMissing fun _role(): JsonField = role + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [InputMessage]. + * + * The following fields are required: + * ```java + * .content() + * .role() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputMessage]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var role: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputMessage: InputMessage) = apply { + content = inputMessage.content + role = inputMessage.role + type = inputMessage.type + additionalProperties = inputMessage.additionalProperties.toMutableMap() + } + + fun content(content: Content) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [Content] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** The role of the message. One of `user`, `system`, or `developer`. */ + fun role(role: Role) = role(JsonField.of(role)) + + /** + * Sets [Builder.role] to an arbitrary JSON value. + * + * You should usually call [Builder.role] with a well-typed [Role] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun role(role: JsonField) = apply { this.role = role } + + /** The type of item, which is always `message`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputMessage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .role() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InputMessage = + InputMessage( + checkRequired("content", content), + checkRequired("role", role), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InputMessage = apply { + if (validated) { + return@apply + } + + content().validate() + role().validate() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (content.asKnown().getOrNull()?.validity() ?: 0) + + (role.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Content + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") + @ExcludeMissing + text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * The text content. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun text(): String = text.getRequired("text") + + /** + * The type of content, which is always `input_text`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Content]. + * + * The following fields are required: + * ```java + * .text() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Content]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(content: Content) = apply { + text = content.text + type = content.type + additionalProperties = content.additionalProperties.toMutableMap() + } + + /** The text content. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** The type of content, which is always `input_text`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Content]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .text() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Content = + Content( + checkRequired("text", text), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Content = apply { + if (validated) { + return@apply + } + + text() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (text.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** The type of content, which is always `input_text`. */ + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val INPUT_TEXT = of("input_text") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + INPUT_TEXT + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + INPUT_TEXT, + /** + * An enum member indicating that [Type] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + INPUT_TEXT -> Value.INPUT_TEXT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known + * and don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + INPUT_TEXT -> Known.INPUT_TEXT + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Content && text == other.text && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Content{text=$text, type=$type, additionalProperties=$additionalProperties}" + } + + /** The role of the message. One of `user`, `system`, or `developer`. */ + class Role @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USER = of("user") + + @JvmField val SYSTEM = of("system") + + @JvmField val DEVELOPER = of("developer") + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + /** An enum containing [Role]'s known values. */ + enum class Known { + USER, + SYSTEM, + DEVELOPER, + } + + /** + * An enum containing [Role]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Role] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + USER, + SYSTEM, + DEVELOPER, + /** + * An enum member indicating that [Role] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + USER -> Value.USER + SYSTEM -> Value.SYSTEM + DEVELOPER -> Value.DEVELOPER + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + USER -> Known.USER + SYSTEM -> Known.SYSTEM + DEVELOPER -> Known.DEVELOPER + else -> throw OpenAIInvalidDataException("Unknown Role: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Role = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The type of item, which is always `message`. */ + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MESSAGE = of("message") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MESSAGE + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MESSAGE, + /** + * An enum member indicating that [Type] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MESSAGE -> Value.MESSAGE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + MESSAGE -> Known.MESSAGE + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is InputMessage && content == other.content && role == other.role && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(content, role, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InputMessage{content=$content, role=$role, type=$type, additionalProperties=$additionalProperties}" + } + + class Assistant + private constructor( + private val content: JsonField, + private val role: JsonValue, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") + @ExcludeMissing + content: JsonField = JsonMissing.of(), + @JsonProperty("role") @ExcludeMissing role: JsonValue = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(content, role, type, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun content(): Content = content.getRequired("content") + + /** + * The role of the message. Must be `assistant` for output. + * + * Expected to always return the following: + * ```java + * JsonValue.from("assistant") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). + */ + @JsonProperty("role") @ExcludeMissing fun _role(): JsonValue = role + + /** + * The type of item, which is always `message`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Assistant]. + * + * The following fields are required: + * ```java + * .content() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Assistant]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var role: JsonValue = JsonValue.from("assistant") + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + content = assistant.content + role = assistant.role + type = assistant.type + additionalProperties = assistant.additionalProperties.toMutableMap() + } + + fun content(content: Content) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [Content] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("assistant") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun role(role: JsonValue) = apply { this.role = role } + + /** The type of item, which is always `message`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Assistant]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Assistant = + Assistant( + checkRequired("content", content), + role, + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Assistant = apply { + if (validated) { + return@apply + } + + content().validate() + _role().let { + if (it != JsonValue.from("assistant")) { + throw OpenAIInvalidDataException("'role' is invalid, received $it") + } + } + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (content.asKnown().getOrNull()?.validity() ?: 0) + + role.let { if (it == JsonValue.from("assistant")) 1 else 0 } + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Content + private constructor( + private val text: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") + @ExcludeMissing + text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * The text content. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun text(): String = text.getRequired("text") + + /** + * The type of content, which is always `output_text`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): Type = type.getRequired("type") + + /** + * Returns the raw JSON value of [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Content]. + * + * The following fields are required: + * ```java + * .text() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Content]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(content: Content) = apply { + text = content.text + type = content.type + additionalProperties = content.additionalProperties.toMutableMap() + } + + /** The text content. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** The type of content, which is always `output_text`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Content]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .text() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Content = + Content( + checkRequired("text", text), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Content = apply { + if (validated) { + return@apply + } + + text() + type().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (text.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** The type of content, which is always `output_text`. */ + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val OUTPUT_TEXT = of("output_text") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + OUTPUT_TEXT + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For + * example, if the SDK is on an older version than the API, then the API may + * respond with new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + OUTPUT_TEXT, + /** + * An enum member indicating that [Type] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or + * if you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + OUTPUT_TEXT -> Value.OUTPUT_TEXT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known + * and don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + OUTPUT_TEXT -> Known.OUTPUT_TEXT + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not + * have the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Content && text == other.text && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Content{text=$text, type=$type, additionalProperties=$additionalProperties}" + } + + /** The type of item, which is always `message`. */ + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MESSAGE = of("message") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MESSAGE + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MESSAGE, + /** + * An enum member indicating that [Type] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MESSAGE -> Value.MESSAGE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + MESSAGE -> Known.MESSAGE + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenAIInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Assistant && content == other.content && role == other.role && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(content, role, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Assistant{content=$content, role=$role, type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalLabelModelGrader && input == other.input && labels == other.labels && model == other.model && name == other.name && passingLabels == other.passingLabels && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(input, labels, model, name, passingLabels, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalLabelModelGrader{input=$input, labels=$labels, model=$model, name=$name, passingLabels=$passingLabels, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPage.kt new file mode 100644 index 00000000..01acf382 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPage.kt @@ -0,0 +1,199 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.errors.OpenAIInvalidDataException +import com.openai.services.blocking.EvalService +import java.util.Collections +import java.util.Objects +import java.util.Optional +import java.util.stream.Stream +import java.util.stream.StreamSupport +import kotlin.jvm.optionals.getOrNull + +/** List evaluations for a project. */ +class EvalListPage +private constructor( + private val evalsService: EvalService, + private val params: EvalListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + fun hasMore(): Optional = response().hasMore() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalListPage && evalsService == other.evalsService && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(evalsService, params, response) /* spotless:on */ + + override fun toString() = + "EvalListPage{evalsService=$evalsService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of(params.toBuilder().after(data().last().id()).build()) + } + + fun getNextPage(): Optional { + return getNextPageParams().map { evalsService.list(it) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of(evalsService: EvalService, params: EvalListParams, response: Response) = + EvalListPage(evalsService, params, response) + } + + class Response( + private val data: JsonField>, + private val hasMore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("data") data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), + ) : this(data, hasMore, mutableMapOf()) + + fun data(): List = data.getOptional("data").getOrNull() ?: listOf() + + fun hasMore(): Optional = hasMore.getOptional("has_more") + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonProperty("has_more") + fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + private var validated: Boolean = false + + fun validate(): Response = apply { + if (validated) { + return@apply + } + + data().map { it.validate() } + hasMore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + + override fun toString() = + "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + + companion object { + + /** Returns a mutable builder for constructing an instance of [EvalListPage]. */ + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var hasMore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.hasMore = page.hasMore + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + /** + * Returns an immutable instance of [Response]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) + } + } + + class AutoPager(private val firstPage: EvalListPage) : Iterable { + + override fun iterator(): Iterator = iterator { + var page = firstPage + var index = 0 + while (true) { + while (index < page.data().size) { + yield(page.data()[index++]) + } + page = page.getNextPage().getOrNull() ?: break + index = 0 + } + } + + fun stream(): Stream { + return StreamSupport.stream(spliterator(), false) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageAsync.kt new file mode 100644 index 00000000..8a38784d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageAsync.kt @@ -0,0 +1,212 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.errors.OpenAIInvalidDataException +import com.openai.services.async.EvalServiceAsync +import java.util.Collections +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.function.Predicate +import kotlin.jvm.optionals.getOrNull + +/** List evaluations for a project. */ +class EvalListPageAsync +private constructor( + private val evalsService: EvalServiceAsync, + private val params: EvalListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + fun hasMore(): Optional = response().hasMore() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalListPageAsync && evalsService == other.evalsService && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(evalsService, params, response) /* spotless:on */ + + override fun toString() = + "EvalListPageAsync{evalsService=$evalsService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of(params.toBuilder().after(data().last().id()).build()) + } + + fun getNextPage(): CompletableFuture> { + return getNextPageParams() + .map { evalsService.list(it).thenApply { Optional.of(it) } } + .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of(evalsService: EvalServiceAsync, params: EvalListParams, response: Response) = + EvalListPageAsync(evalsService, params, response) + } + + class Response( + private val data: JsonField>, + private val hasMore: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("data") data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), + ) : this(data, hasMore, mutableMapOf()) + + fun data(): List = data.getOptional("data").getOrNull() ?: listOf() + + fun hasMore(): Optional = hasMore.getOptional("has_more") + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonProperty("has_more") + fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + private var validated: Boolean = false + + fun validate(): Response = apply { + if (validated) { + return@apply + } + + data().map { it.validate() } + hasMore() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + fun toBuilder() = Builder().from(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + + override fun toString() = + "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + + companion object { + + /** Returns a mutable builder for constructing an instance of [EvalListPageAsync]. */ + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var hasMore: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.hasMore = page.hasMore + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + /** + * Returns an immutable instance of [Response]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) + } + } + + class AutoPager(private val firstPage: EvalListPageAsync) { + + fun forEach( + action: Predicate, + executor: Executor, + ): CompletableFuture { + fun CompletableFuture>.forEach( + action: (EvalListResponse) -> Boolean, + executor: Executor, + ): CompletableFuture = + thenComposeAsync( + { page -> + page + .filter { it.data().all(action) } + .map { it.getNextPage().forEach(action, executor) } + .orElseGet { CompletableFuture.completedFuture(null) } + }, + executor, + ) + return CompletableFuture.completedFuture(Optional.of(firstPage)) + .forEach(action::test, executor) + } + + fun toList(executor: Executor): CompletableFuture> { + val values = mutableListOf() + return forEach(values::add, executor).thenApply { values } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListParams.kt new file mode 100644 index 00000000..5bba0da0 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListParams.kt @@ -0,0 +1,513 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.Params +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** List evaluations for a project. */ +class EvalListParams +private constructor( + private val after: String?, + private val limit: Long?, + private val order: Order?, + private val orderBy: OrderBy?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Identifier for the last eval from the previous pagination request. */ + fun after(): Optional = Optional.ofNullable(after) + + /** Number of evals to retrieve. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order for evals by timestamp. Use `asc` for ascending order or `desc` for descending + * order. + */ + fun order(): Optional = Optional.ofNullable(order) + + /** + * Evals can be ordered by creation time or last updated time. Use `created_at` for creation + * time or `updated_at` for last updated time. + */ + fun orderBy(): Optional = Optional.ofNullable(orderBy) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): EvalListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [EvalListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalListParams]. */ + class Builder internal constructor() { + + private var after: String? = null + private var limit: Long? = null + private var order: Order? = null + private var orderBy: OrderBy? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(evalListParams: EvalListParams) = apply { + after = evalListParams.after + limit = evalListParams.limit + order = evalListParams.order + orderBy = evalListParams.orderBy + additionalHeaders = evalListParams.additionalHeaders.toBuilder() + additionalQueryParams = evalListParams.additionalQueryParams.toBuilder() + } + + /** Identifier for the last eval from the previous pagination request. */ + fun after(after: String?) = apply { this.after = after } + + /** Alias for calling [Builder.after] with `after.orElse(null)`. */ + fun after(after: Optional) = after(after.getOrNull()) + + /** Number of evals to retrieve. */ + fun limit(limit: Long?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** + * Sort order for evals by timestamp. Use `asc` for ascending order or `desc` for descending + * order. + */ + fun order(order: Order?) = apply { this.order = order } + + /** Alias for calling [Builder.order] with `order.orElse(null)`. */ + fun order(order: Optional) = order(order.getOrNull()) + + /** + * Evals can be ordered by creation time or last updated time. Use `created_at` for creation + * time or `updated_at` for last updated time. + */ + fun orderBy(orderBy: OrderBy?) = apply { this.orderBy = orderBy } + + /** Alias for calling [Builder.orderBy] with `orderBy.orElse(null)`. */ + fun orderBy(orderBy: Optional) = orderBy(orderBy.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [EvalListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): EvalListParams = + EvalListParams( + after, + limit, + order, + orderBy, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + after?.let { put("after", it) } + limit?.let { put("limit", it.toString()) } + order?.let { put("order", it.toString()) } + orderBy?.let { put("order_by", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** + * Sort order for evals by timestamp. Use `asc` for ascending order or `desc` for descending + * order. + */ + class Order @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + /** An enum containing [Order]'s known values. */ + enum class Known { + ASC, + DESC, + } + + /** + * An enum containing [Order]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Order] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ASC, + DESC, + /** An enum member indicating that [Order] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + fun validate(): Order = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Order && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Evals can be ordered by creation time or last updated time. Use `created_at` for creation + * time or `updated_at` for last updated time. + */ + class OrderBy @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val CREATED_AT = of("created_at") + + @JvmField val UPDATED_AT = of("updated_at") + + @JvmStatic fun of(value: String) = OrderBy(JsonField.of(value)) + } + + /** An enum containing [OrderBy]'s known values. */ + enum class Known { + CREATED_AT, + UPDATED_AT, + } + + /** + * An enum containing [OrderBy]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [OrderBy] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + CREATED_AT, + UPDATED_AT, + /** An enum member indicating that [OrderBy] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + CREATED_AT -> Value.CREATED_AT + UPDATED_AT -> Value.UPDATED_AT + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + CREATED_AT -> Known.CREATED_AT + UPDATED_AT -> Known.UPDATED_AT + else -> throw OpenAIInvalidDataException("Unknown OrderBy: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + fun validate(): OrderBy = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OrderBy && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalListParams && after == other.after && limit == other.limit && order == other.order && orderBy == other.orderBy && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(after, limit, order, orderBy, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "EvalListParams{after=$after, limit=$limit, order=$order, orderBy=$orderBy, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListResponse.kt new file mode 100644 index 00000000..0a4a952e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListResponse.kt @@ -0,0 +1,1145 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * An Eval object with a data source config and testing criteria. An Eval represents a task to be + * done for your LLM integration. Like: + * - Improve the quality of my chatbot + * - See how well my chatbot handles customer support + * - Check if o3-mini is better at my usecase than gpt-4o + */ +class EvalListResponse +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val dataSourceConfig: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val object_: JsonValue, + private val shareWithOpenAI: JsonField, + private val testingCriteria: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("data_source_config") + @ExcludeMissing + dataSourceConfig: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("share_with_openai") + @ExcludeMissing + shareWithOpenAI: JsonField = JsonMissing.of(), + @JsonProperty("testing_criteria") + @ExcludeMissing + testingCriteria: JsonField> = JsonMissing.of(), + ) : this( + id, + createdAt, + dataSourceConfig, + metadata, + name, + object_, + shareWithOpenAI, + testingCriteria, + mutableMapOf(), + ) + + /** + * Unique identifier for the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * The Unix timestamp (in seconds) for when the eval was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Long = createdAt.getRequired("created_at") + + /** + * Configuration of data sources used in runs of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dataSourceConfig(): DataSourceConfig = dataSourceConfig.getRequired("data_source_config") + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * The name of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The object type. + * + * Expected to always return the following: + * ```java + * JsonValue.from("eval") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Indicates whether the evaluation is shared with OpenAI. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun shareWithOpenAI(): Boolean = shareWithOpenAI.getRequired("share_with_openai") + + /** + * A list of testing criteria. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun testingCriteria(): List = testingCriteria.getRequired("testing_criteria") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [dataSourceConfig]. + * + * Unlike [dataSourceConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("data_source_config") + @ExcludeMissing + fun _dataSourceConfig(): JsonField = dataSourceConfig + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [shareWithOpenAI]. + * + * Unlike [shareWithOpenAI], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("share_with_openai") + @ExcludeMissing + fun _shareWithOpenAI(): JsonField = shareWithOpenAI + + /** + * Returns the raw JSON value of [testingCriteria]. + * + * Unlike [testingCriteria], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("testing_criteria") + @ExcludeMissing + fun _testingCriteria(): JsonField> = testingCriteria + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalListResponse]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .dataSourceConfig() + * .metadata() + * .name() + * .shareWithOpenAI() + * .testingCriteria() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalListResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var dataSourceConfig: JsonField? = null + private var metadata: JsonField? = null + private var name: JsonField? = null + private var object_: JsonValue = JsonValue.from("eval") + private var shareWithOpenAI: JsonField? = null + private var testingCriteria: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalListResponse: EvalListResponse) = apply { + id = evalListResponse.id + createdAt = evalListResponse.createdAt + dataSourceConfig = evalListResponse.dataSourceConfig + metadata = evalListResponse.metadata + name = evalListResponse.name + object_ = evalListResponse.object_ + shareWithOpenAI = evalListResponse.shareWithOpenAI + testingCriteria = evalListResponse.testingCriteria.map { it.toMutableList() } + additionalProperties = evalListResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier for the evaluation. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** The Unix timestamp (in seconds) for when the eval was created. */ + fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Configuration of data sources used in runs of the evaluation. */ + fun dataSourceConfig(dataSourceConfig: DataSourceConfig) = + dataSourceConfig(JsonField.of(dataSourceConfig)) + + /** + * Sets [Builder.dataSourceConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.dataSourceConfig] with a well-typed [DataSourceConfig] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dataSourceConfig(dataSourceConfig: JsonField) = apply { + this.dataSourceConfig = dataSourceConfig + } + + /** Alias for calling [dataSourceConfig] with `DataSourceConfig.ofCustom(custom)`. */ + fun dataSourceConfig(custom: EvalCustomDataSourceConfig) = + dataSourceConfig(DataSourceConfig.ofCustom(custom)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * EvalCustomDataSourceConfig.builder() + * .schema(schema) + * .build() + * ``` + */ + fun customDataSourceConfig(schema: EvalCustomDataSourceConfig.Schema) = + dataSourceConfig(EvalCustomDataSourceConfig.builder().schema(schema).build()) + + /** + * Alias for calling [dataSourceConfig] with + * `DataSourceConfig.ofStoredCompletions(storedCompletions)`. + */ + fun dataSourceConfig(storedCompletions: EvalStoredCompletionsDataSourceConfig) = + dataSourceConfig(DataSourceConfig.ofStoredCompletions(storedCompletions)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * EvalStoredCompletionsDataSourceConfig.builder() + * .schema(schema) + * .build() + * ``` + */ + fun storedCompletionsDataSourceConfig( + schema: EvalStoredCompletionsDataSourceConfig.Schema + ) = dataSourceConfig(EvalStoredCompletionsDataSourceConfig.builder().schema(schema).build()) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** The name of the evaluation. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("eval") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Indicates whether the evaluation is shared with OpenAI. */ + fun shareWithOpenAI(shareWithOpenAI: Boolean) = + shareWithOpenAI(JsonField.of(shareWithOpenAI)) + + /** + * Sets [Builder.shareWithOpenAI] to an arbitrary JSON value. + * + * You should usually call [Builder.shareWithOpenAI] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun shareWithOpenAI(shareWithOpenAI: JsonField) = apply { + this.shareWithOpenAI = shareWithOpenAI + } + + /** A list of testing criteria. */ + fun testingCriteria(testingCriteria: List) = + testingCriteria(JsonField.of(testingCriteria)) + + /** + * Sets [Builder.testingCriteria] to an arbitrary JSON value. + * + * You should usually call [Builder.testingCriteria] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun testingCriteria(testingCriteria: JsonField>) = apply { + this.testingCriteria = testingCriteria.map { it.toMutableList() } + } + + /** + * Adds a single [TestingCriterion] to [testingCriteria]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTestingCriterion(testingCriterion: TestingCriterion) = apply { + testingCriteria = + (testingCriteria ?: JsonField.of(mutableListOf())).also { + checkKnown("testingCriteria", it).add(testingCriterion) + } + } + + /** + * Alias for calling [addTestingCriterion] with `TestingCriterion.ofLabelModel(labelModel)`. + */ + fun addTestingCriterion(labelModel: EvalLabelModelGrader) = + addTestingCriterion(TestingCriterion.ofLabelModel(labelModel)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofStringCheck(stringCheck)`. + */ + fun addTestingCriterion(stringCheck: EvalStringCheckGrader) = + addTestingCriterion(TestingCriterion.ofStringCheck(stringCheck)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofTextSimilarity(textSimilarity)`. + */ + fun addTestingCriterion(textSimilarity: EvalTextSimilarityGrader) = + addTestingCriterion(TestingCriterion.ofTextSimilarity(textSimilarity)) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .dataSourceConfig() + * .metadata() + * .name() + * .shareWithOpenAI() + * .testingCriteria() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalListResponse = + EvalListResponse( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("dataSourceConfig", dataSourceConfig), + checkRequired("metadata", metadata), + checkRequired("name", name), + object_, + checkRequired("shareWithOpenAI", shareWithOpenAI), + checkRequired("testingCriteria", testingCriteria).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalListResponse = apply { + if (validated) { + return@apply + } + + id() + createdAt() + dataSourceConfig().validate() + metadata().ifPresent { it.validate() } + name() + _object_().let { + if (it != JsonValue.from("eval")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + shareWithOpenAI() + testingCriteria().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (dataSourceConfig.asKnown().getOrNull()?.validity() ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("eval")) 1 else 0 } + + (if (shareWithOpenAI.asKnown().isPresent) 1 else 0) + + (testingCriteria.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration of data sources used in runs of the evaluation. */ + @JsonDeserialize(using = DataSourceConfig.Deserializer::class) + @JsonSerialize(using = DataSourceConfig.Serializer::class) + class DataSourceConfig + private constructor( + private val custom: EvalCustomDataSourceConfig? = null, + private val storedCompletions: EvalStoredCompletionsDataSourceConfig? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun custom(): Optional = Optional.ofNullable(custom) + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both defined + * when using this data source config. + */ + fun storedCompletions(): Optional = + Optional.ofNullable(storedCompletions) + + fun isCustom(): Boolean = custom != null + + fun isStoredCompletions(): Boolean = storedCompletions != null + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun asCustom(): EvalCustomDataSourceConfig = custom.getOrThrow("custom") + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both defined + * when using this data source config. + */ + fun asStoredCompletions(): EvalStoredCompletionsDataSourceConfig = + storedCompletions.getOrThrow("storedCompletions") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + custom != null -> visitor.visitCustom(custom) + storedCompletions != null -> visitor.visitStoredCompletions(storedCompletions) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): DataSourceConfig = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustom(custom: EvalCustomDataSourceConfig) { + custom.validate() + } + + override fun visitStoredCompletions( + storedCompletions: EvalStoredCompletionsDataSourceConfig + ) { + storedCompletions.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCustom(custom: EvalCustomDataSourceConfig) = custom.validity() + + override fun visitStoredCompletions( + storedCompletions: EvalStoredCompletionsDataSourceConfig + ) = storedCompletions.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DataSourceConfig && custom == other.custom && storedCompletions == other.storedCompletions /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(custom, storedCompletions) /* spotless:on */ + + override fun toString(): String = + when { + custom != null -> "DataSourceConfig{custom=$custom}" + storedCompletions != null -> + "DataSourceConfig{storedCompletions=$storedCompletions}" + _json != null -> "DataSourceConfig{_unknown=$_json}" + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + + companion object { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + @JvmStatic + fun ofCustom(custom: EvalCustomDataSourceConfig) = DataSourceConfig(custom = custom) + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your + * stored completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both + * defined when using this data source config. + */ + @JvmStatic + fun ofStoredCompletions(storedCompletions: EvalStoredCompletionsDataSourceConfig) = + DataSourceConfig(storedCompletions = storedCompletions) + } + + /** + * An interface that defines how to map each variant of [DataSourceConfig] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun visitCustom(custom: EvalCustomDataSourceConfig): T + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your + * stored completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both + * defined when using this data source config. + */ + fun visitStoredCompletions(storedCompletions: EvalStoredCompletionsDataSourceConfig): T + + /** + * Maps an unknown variant of [DataSourceConfig] to a value of type [T]. + * + * An instance of [DataSourceConfig] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown DataSourceConfig: $json") + } + } + + internal class Deserializer : BaseDeserializer(DataSourceConfig::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): DataSourceConfig { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "custom" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { DataSourceConfig(custom = it, _json = json) } + ?: DataSourceConfig(_json = json) + } + "stored_completions" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { DataSourceConfig(storedCompletions = it, _json = json) } + ?: DataSourceConfig(_json = json) + } + } + + return DataSourceConfig(_json = json) + } + } + + internal class Serializer : BaseSerializer(DataSourceConfig::class) { + + override fun serialize( + value: DataSourceConfig, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.custom != null -> generator.writeObject(value.custom) + value.storedCompletions != null -> + generator.writeObject(value.storedCompletions) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + } + } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the evaluation. + */ + @JsonDeserialize(using = TestingCriterion.Deserializer::class) + @JsonSerialize(using = TestingCriterion.Serializer::class) + class TestingCriterion + private constructor( + private val labelModel: EvalLabelModelGrader? = null, + private val stringCheck: EvalStringCheckGrader? = null, + private val textSimilarity: EvalTextSimilarityGrader? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun labelModel(): Optional = Optional.ofNullable(labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun stringCheck(): Optional = Optional.ofNullable(stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun textSimilarity(): Optional = + Optional.ofNullable(textSimilarity) + + fun isLabelModel(): Boolean = labelModel != null + + fun isStringCheck(): Boolean = stringCheck != null + + fun isTextSimilarity(): Boolean = textSimilarity != null + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun asLabelModel(): EvalLabelModelGrader = labelModel.getOrThrow("labelModel") + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun asStringCheck(): EvalStringCheckGrader = stringCheck.getOrThrow("stringCheck") + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun asTextSimilarity(): EvalTextSimilarityGrader = + textSimilarity.getOrThrow("textSimilarity") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + labelModel != null -> visitor.visitLabelModel(labelModel) + stringCheck != null -> visitor.visitStringCheck(stringCheck) + textSimilarity != null -> visitor.visitTextSimilarity(textSimilarity) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): TestingCriterion = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitLabelModel(labelModel: EvalLabelModelGrader) { + labelModel.validate() + } + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) { + stringCheck.validate() + } + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) { + textSimilarity.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitLabelModel(labelModel: EvalLabelModelGrader) = + labelModel.validity() + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) = + stringCheck.validity() + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + textSimilarity.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TestingCriterion && labelModel == other.labelModel && stringCheck == other.stringCheck && textSimilarity == other.textSimilarity /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(labelModel, stringCheck, textSimilarity) /* spotless:on */ + + override fun toString(): String = + when { + labelModel != null -> "TestingCriterion{labelModel=$labelModel}" + stringCheck != null -> "TestingCriterion{stringCheck=$stringCheck}" + textSimilarity != null -> "TestingCriterion{textSimilarity=$textSimilarity}" + _json != null -> "TestingCriterion{_unknown=$_json}" + else -> throw IllegalStateException("Invalid TestingCriterion") + } + + companion object { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + @JvmStatic + fun ofLabelModel(labelModel: EvalLabelModelGrader) = + TestingCriterion(labelModel = labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + @JvmStatic + fun ofStringCheck(stringCheck: EvalStringCheckGrader) = + TestingCriterion(stringCheck = stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + @JvmStatic + fun ofTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + TestingCriterion(textSimilarity = textSimilarity) + } + + /** + * An interface that defines how to map each variant of [TestingCriterion] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun visitLabelModel(labelModel: EvalLabelModelGrader): T + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + fun visitStringCheck(stringCheck: EvalStringCheckGrader): T + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader): T + + /** + * Maps an unknown variant of [TestingCriterion] to a value of type [T]. + * + * An instance of [TestingCriterion] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown TestingCriterion: $json") + } + } + + internal class Deserializer : BaseDeserializer(TestingCriterion::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): TestingCriterion { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "label_model" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(labelModel = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "string_check" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(stringCheck = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "text_similarity" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { TestingCriterion(textSimilarity = it, _json = json) } + ?: TestingCriterion(_json = json) + } + } + + return TestingCriterion(_json = json) + } + } + + internal class Serializer : BaseSerializer(TestingCriterion::class) { + + override fun serialize( + value: TestingCriterion, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.labelModel != null -> generator.writeObject(value.labelModel) + value.stringCheck != null -> generator.writeObject(value.stringCheck) + value.textSimilarity != null -> generator.writeObject(value.textSimilarity) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid TestingCriterion") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalListResponse && id == other.id && createdAt == other.createdAt && dataSourceConfig == other.dataSourceConfig && metadata == other.metadata && name == other.name && object_ == other.object_ && shareWithOpenAI == other.shareWithOpenAI && testingCriteria == other.testingCriteria && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, createdAt, dataSourceConfig, metadata, name, object_, shareWithOpenAI, testingCriteria, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalListResponse{id=$id, createdAt=$createdAt, dataSourceConfig=$dataSourceConfig, metadata=$metadata, name=$name, object_=$object_, shareWithOpenAI=$shareWithOpenAI, testingCriteria=$testingCriteria, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveParams.kt new file mode 100644 index 00000000..63111243 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveParams.kt @@ -0,0 +1,196 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +/** Get an evaluation by ID. */ +class EvalRetrieveParams +private constructor( + private val evalId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun evalId(): String = evalId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalRetrieveParams]. + * + * The following fields are required: + * ```java + * .evalId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalRetrieveParams]. */ + class Builder internal constructor() { + + private var evalId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(evalRetrieveParams: EvalRetrieveParams) = apply { + evalId = evalRetrieveParams.evalId + additionalHeaders = evalRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = evalRetrieveParams.additionalQueryParams.toBuilder() + } + + fun evalId(evalId: String) = apply { this.evalId = evalId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [EvalRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .evalId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalRetrieveParams = + EvalRetrieveParams( + checkRequired("evalId", evalId), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> evalId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalRetrieveParams && evalId == other.evalId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(evalId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "EvalRetrieveParams{evalId=$evalId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveResponse.kt new file mode 100644 index 00000000..6de6ef8d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveResponse.kt @@ -0,0 +1,1145 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * An Eval object with a data source config and testing criteria. An Eval represents a task to be + * done for your LLM integration. Like: + * - Improve the quality of my chatbot + * - See how well my chatbot handles customer support + * - Check if o3-mini is better at my usecase than gpt-4o + */ +class EvalRetrieveResponse +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val dataSourceConfig: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val object_: JsonValue, + private val shareWithOpenAI: JsonField, + private val testingCriteria: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("data_source_config") + @ExcludeMissing + dataSourceConfig: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("share_with_openai") + @ExcludeMissing + shareWithOpenAI: JsonField = JsonMissing.of(), + @JsonProperty("testing_criteria") + @ExcludeMissing + testingCriteria: JsonField> = JsonMissing.of(), + ) : this( + id, + createdAt, + dataSourceConfig, + metadata, + name, + object_, + shareWithOpenAI, + testingCriteria, + mutableMapOf(), + ) + + /** + * Unique identifier for the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * The Unix timestamp (in seconds) for when the eval was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Long = createdAt.getRequired("created_at") + + /** + * Configuration of data sources used in runs of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dataSourceConfig(): DataSourceConfig = dataSourceConfig.getRequired("data_source_config") + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * The name of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The object type. + * + * Expected to always return the following: + * ```java + * JsonValue.from("eval") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Indicates whether the evaluation is shared with OpenAI. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun shareWithOpenAI(): Boolean = shareWithOpenAI.getRequired("share_with_openai") + + /** + * A list of testing criteria. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun testingCriteria(): List = testingCriteria.getRequired("testing_criteria") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [dataSourceConfig]. + * + * Unlike [dataSourceConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("data_source_config") + @ExcludeMissing + fun _dataSourceConfig(): JsonField = dataSourceConfig + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [shareWithOpenAI]. + * + * Unlike [shareWithOpenAI], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("share_with_openai") + @ExcludeMissing + fun _shareWithOpenAI(): JsonField = shareWithOpenAI + + /** + * Returns the raw JSON value of [testingCriteria]. + * + * Unlike [testingCriteria], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("testing_criteria") + @ExcludeMissing + fun _testingCriteria(): JsonField> = testingCriteria + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalRetrieveResponse]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .dataSourceConfig() + * .metadata() + * .name() + * .shareWithOpenAI() + * .testingCriteria() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var dataSourceConfig: JsonField? = null + private var metadata: JsonField? = null + private var name: JsonField? = null + private var object_: JsonValue = JsonValue.from("eval") + private var shareWithOpenAI: JsonField? = null + private var testingCriteria: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalRetrieveResponse: EvalRetrieveResponse) = apply { + id = evalRetrieveResponse.id + createdAt = evalRetrieveResponse.createdAt + dataSourceConfig = evalRetrieveResponse.dataSourceConfig + metadata = evalRetrieveResponse.metadata + name = evalRetrieveResponse.name + object_ = evalRetrieveResponse.object_ + shareWithOpenAI = evalRetrieveResponse.shareWithOpenAI + testingCriteria = evalRetrieveResponse.testingCriteria.map { it.toMutableList() } + additionalProperties = evalRetrieveResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier for the evaluation. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** The Unix timestamp (in seconds) for when the eval was created. */ + fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Configuration of data sources used in runs of the evaluation. */ + fun dataSourceConfig(dataSourceConfig: DataSourceConfig) = + dataSourceConfig(JsonField.of(dataSourceConfig)) + + /** + * Sets [Builder.dataSourceConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.dataSourceConfig] with a well-typed [DataSourceConfig] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dataSourceConfig(dataSourceConfig: JsonField) = apply { + this.dataSourceConfig = dataSourceConfig + } + + /** Alias for calling [dataSourceConfig] with `DataSourceConfig.ofCustom(custom)`. */ + fun dataSourceConfig(custom: EvalCustomDataSourceConfig) = + dataSourceConfig(DataSourceConfig.ofCustom(custom)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * EvalCustomDataSourceConfig.builder() + * .schema(schema) + * .build() + * ``` + */ + fun customDataSourceConfig(schema: EvalCustomDataSourceConfig.Schema) = + dataSourceConfig(EvalCustomDataSourceConfig.builder().schema(schema).build()) + + /** + * Alias for calling [dataSourceConfig] with + * `DataSourceConfig.ofStoredCompletions(storedCompletions)`. + */ + fun dataSourceConfig(storedCompletions: EvalStoredCompletionsDataSourceConfig) = + dataSourceConfig(DataSourceConfig.ofStoredCompletions(storedCompletions)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * EvalStoredCompletionsDataSourceConfig.builder() + * .schema(schema) + * .build() + * ``` + */ + fun storedCompletionsDataSourceConfig( + schema: EvalStoredCompletionsDataSourceConfig.Schema + ) = dataSourceConfig(EvalStoredCompletionsDataSourceConfig.builder().schema(schema).build()) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** The name of the evaluation. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("eval") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Indicates whether the evaluation is shared with OpenAI. */ + fun shareWithOpenAI(shareWithOpenAI: Boolean) = + shareWithOpenAI(JsonField.of(shareWithOpenAI)) + + /** + * Sets [Builder.shareWithOpenAI] to an arbitrary JSON value. + * + * You should usually call [Builder.shareWithOpenAI] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun shareWithOpenAI(shareWithOpenAI: JsonField) = apply { + this.shareWithOpenAI = shareWithOpenAI + } + + /** A list of testing criteria. */ + fun testingCriteria(testingCriteria: List) = + testingCriteria(JsonField.of(testingCriteria)) + + /** + * Sets [Builder.testingCriteria] to an arbitrary JSON value. + * + * You should usually call [Builder.testingCriteria] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun testingCriteria(testingCriteria: JsonField>) = apply { + this.testingCriteria = testingCriteria.map { it.toMutableList() } + } + + /** + * Adds a single [TestingCriterion] to [testingCriteria]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTestingCriterion(testingCriterion: TestingCriterion) = apply { + testingCriteria = + (testingCriteria ?: JsonField.of(mutableListOf())).also { + checkKnown("testingCriteria", it).add(testingCriterion) + } + } + + /** + * Alias for calling [addTestingCriterion] with `TestingCriterion.ofLabelModel(labelModel)`. + */ + fun addTestingCriterion(labelModel: EvalLabelModelGrader) = + addTestingCriterion(TestingCriterion.ofLabelModel(labelModel)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofStringCheck(stringCheck)`. + */ + fun addTestingCriterion(stringCheck: EvalStringCheckGrader) = + addTestingCriterion(TestingCriterion.ofStringCheck(stringCheck)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofTextSimilarity(textSimilarity)`. + */ + fun addTestingCriterion(textSimilarity: EvalTextSimilarityGrader) = + addTestingCriterion(TestingCriterion.ofTextSimilarity(textSimilarity)) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .dataSourceConfig() + * .metadata() + * .name() + * .shareWithOpenAI() + * .testingCriteria() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalRetrieveResponse = + EvalRetrieveResponse( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("dataSourceConfig", dataSourceConfig), + checkRequired("metadata", metadata), + checkRequired("name", name), + object_, + checkRequired("shareWithOpenAI", shareWithOpenAI), + checkRequired("testingCriteria", testingCriteria).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + createdAt() + dataSourceConfig().validate() + metadata().ifPresent { it.validate() } + name() + _object_().let { + if (it != JsonValue.from("eval")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + shareWithOpenAI() + testingCriteria().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (dataSourceConfig.asKnown().getOrNull()?.validity() ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("eval")) 1 else 0 } + + (if (shareWithOpenAI.asKnown().isPresent) 1 else 0) + + (testingCriteria.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration of data sources used in runs of the evaluation. */ + @JsonDeserialize(using = DataSourceConfig.Deserializer::class) + @JsonSerialize(using = DataSourceConfig.Serializer::class) + class DataSourceConfig + private constructor( + private val custom: EvalCustomDataSourceConfig? = null, + private val storedCompletions: EvalStoredCompletionsDataSourceConfig? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun custom(): Optional = Optional.ofNullable(custom) + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both defined + * when using this data source config. + */ + fun storedCompletions(): Optional = + Optional.ofNullable(storedCompletions) + + fun isCustom(): Boolean = custom != null + + fun isStoredCompletions(): Boolean = storedCompletions != null + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun asCustom(): EvalCustomDataSourceConfig = custom.getOrThrow("custom") + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both defined + * when using this data source config. + */ + fun asStoredCompletions(): EvalStoredCompletionsDataSourceConfig = + storedCompletions.getOrThrow("storedCompletions") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + custom != null -> visitor.visitCustom(custom) + storedCompletions != null -> visitor.visitStoredCompletions(storedCompletions) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): DataSourceConfig = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustom(custom: EvalCustomDataSourceConfig) { + custom.validate() + } + + override fun visitStoredCompletions( + storedCompletions: EvalStoredCompletionsDataSourceConfig + ) { + storedCompletions.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCustom(custom: EvalCustomDataSourceConfig) = custom.validity() + + override fun visitStoredCompletions( + storedCompletions: EvalStoredCompletionsDataSourceConfig + ) = storedCompletions.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DataSourceConfig && custom == other.custom && storedCompletions == other.storedCompletions /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(custom, storedCompletions) /* spotless:on */ + + override fun toString(): String = + when { + custom != null -> "DataSourceConfig{custom=$custom}" + storedCompletions != null -> + "DataSourceConfig{storedCompletions=$storedCompletions}" + _json != null -> "DataSourceConfig{_unknown=$_json}" + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + + companion object { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + @JvmStatic + fun ofCustom(custom: EvalCustomDataSourceConfig) = DataSourceConfig(custom = custom) + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your + * stored completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both + * defined when using this data source config. + */ + @JvmStatic + fun ofStoredCompletions(storedCompletions: EvalStoredCompletionsDataSourceConfig) = + DataSourceConfig(storedCompletions = storedCompletions) + } + + /** + * An interface that defines how to map each variant of [DataSourceConfig] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun visitCustom(custom: EvalCustomDataSourceConfig): T + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your + * stored completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both + * defined when using this data source config. + */ + fun visitStoredCompletions(storedCompletions: EvalStoredCompletionsDataSourceConfig): T + + /** + * Maps an unknown variant of [DataSourceConfig] to a value of type [T]. + * + * An instance of [DataSourceConfig] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown DataSourceConfig: $json") + } + } + + internal class Deserializer : BaseDeserializer(DataSourceConfig::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): DataSourceConfig { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "custom" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { DataSourceConfig(custom = it, _json = json) } + ?: DataSourceConfig(_json = json) + } + "stored_completions" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { DataSourceConfig(storedCompletions = it, _json = json) } + ?: DataSourceConfig(_json = json) + } + } + + return DataSourceConfig(_json = json) + } + } + + internal class Serializer : BaseSerializer(DataSourceConfig::class) { + + override fun serialize( + value: DataSourceConfig, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.custom != null -> generator.writeObject(value.custom) + value.storedCompletions != null -> + generator.writeObject(value.storedCompletions) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + } + } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the evaluation. + */ + @JsonDeserialize(using = TestingCriterion.Deserializer::class) + @JsonSerialize(using = TestingCriterion.Serializer::class) + class TestingCriterion + private constructor( + private val labelModel: EvalLabelModelGrader? = null, + private val stringCheck: EvalStringCheckGrader? = null, + private val textSimilarity: EvalTextSimilarityGrader? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun labelModel(): Optional = Optional.ofNullable(labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun stringCheck(): Optional = Optional.ofNullable(stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun textSimilarity(): Optional = + Optional.ofNullable(textSimilarity) + + fun isLabelModel(): Boolean = labelModel != null + + fun isStringCheck(): Boolean = stringCheck != null + + fun isTextSimilarity(): Boolean = textSimilarity != null + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun asLabelModel(): EvalLabelModelGrader = labelModel.getOrThrow("labelModel") + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun asStringCheck(): EvalStringCheckGrader = stringCheck.getOrThrow("stringCheck") + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun asTextSimilarity(): EvalTextSimilarityGrader = + textSimilarity.getOrThrow("textSimilarity") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + labelModel != null -> visitor.visitLabelModel(labelModel) + stringCheck != null -> visitor.visitStringCheck(stringCheck) + textSimilarity != null -> visitor.visitTextSimilarity(textSimilarity) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): TestingCriterion = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitLabelModel(labelModel: EvalLabelModelGrader) { + labelModel.validate() + } + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) { + stringCheck.validate() + } + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) { + textSimilarity.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitLabelModel(labelModel: EvalLabelModelGrader) = + labelModel.validity() + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) = + stringCheck.validity() + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + textSimilarity.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TestingCriterion && labelModel == other.labelModel && stringCheck == other.stringCheck && textSimilarity == other.textSimilarity /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(labelModel, stringCheck, textSimilarity) /* spotless:on */ + + override fun toString(): String = + when { + labelModel != null -> "TestingCriterion{labelModel=$labelModel}" + stringCheck != null -> "TestingCriterion{stringCheck=$stringCheck}" + textSimilarity != null -> "TestingCriterion{textSimilarity=$textSimilarity}" + _json != null -> "TestingCriterion{_unknown=$_json}" + else -> throw IllegalStateException("Invalid TestingCriterion") + } + + companion object { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + @JvmStatic + fun ofLabelModel(labelModel: EvalLabelModelGrader) = + TestingCriterion(labelModel = labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + @JvmStatic + fun ofStringCheck(stringCheck: EvalStringCheckGrader) = + TestingCriterion(stringCheck = stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + @JvmStatic + fun ofTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + TestingCriterion(textSimilarity = textSimilarity) + } + + /** + * An interface that defines how to map each variant of [TestingCriterion] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun visitLabelModel(labelModel: EvalLabelModelGrader): T + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + fun visitStringCheck(stringCheck: EvalStringCheckGrader): T + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader): T + + /** + * Maps an unknown variant of [TestingCriterion] to a value of type [T]. + * + * An instance of [TestingCriterion] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown TestingCriterion: $json") + } + } + + internal class Deserializer : BaseDeserializer(TestingCriterion::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): TestingCriterion { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "label_model" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(labelModel = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "string_check" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(stringCheck = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "text_similarity" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { TestingCriterion(textSimilarity = it, _json = json) } + ?: TestingCriterion(_json = json) + } + } + + return TestingCriterion(_json = json) + } + } + + internal class Serializer : BaseSerializer(TestingCriterion::class) { + + override fun serialize( + value: TestingCriterion, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.labelModel != null -> generator.writeObject(value.labelModel) + value.stringCheck != null -> generator.writeObject(value.stringCheck) + value.textSimilarity != null -> generator.writeObject(value.textSimilarity) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid TestingCriterion") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalRetrieveResponse && id == other.id && createdAt == other.createdAt && dataSourceConfig == other.dataSourceConfig && metadata == other.metadata && name == other.name && object_ == other.object_ && shareWithOpenAI == other.shareWithOpenAI && testingCriteria == other.testingCriteria && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, createdAt, dataSourceConfig, metadata, name, object_, shareWithOpenAI, testingCriteria, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalRetrieveResponse{id=$id, createdAt=$createdAt, dataSourceConfig=$dataSourceConfig, metadata=$metadata, name=$name, object_=$object_, shareWithOpenAI=$shareWithOpenAI, testingCriteria=$testingCriteria, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalStoredCompletionsDataSourceConfig.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalStoredCompletionsDataSourceConfig.kt new file mode 100644 index 00000000..d7d5d289 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalStoredCompletionsDataSourceConfig.kt @@ -0,0 +1,492 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. + * The schema returned by this data source config is used to defined what variables are available in + * your evals. `item` and `sample` are both defined when using this data source config. + */ +class EvalStoredCompletionsDataSourceConfig +private constructor( + private val schema: JsonField, + private val type: JsonValue, + private val metadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("schema") @ExcludeMissing schema: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + ) : this(schema, type, metadata, mutableMapOf()) + + /** + * The json schema for the run data source items. Learn how to build JSON schemas + * [here](https://json-schema.org/). + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun schema(): Schema = schema.getRequired("schema") + + /** + * The type of data source. Always `stored_completions`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("stored_completions") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Returns the raw JSON value of [schema]. + * + * Unlike [schema], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("schema") @ExcludeMissing fun _schema(): JsonField = schema + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [EvalStoredCompletionsDataSourceConfig]. + * + * The following fields are required: + * ```java + * .schema() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalStoredCompletionsDataSourceConfig]. */ + class Builder internal constructor() { + + private var schema: JsonField? = null + private var type: JsonValue = JsonValue.from("stored_completions") + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + evalStoredCompletionsDataSourceConfig: EvalStoredCompletionsDataSourceConfig + ) = apply { + schema = evalStoredCompletionsDataSourceConfig.schema + type = evalStoredCompletionsDataSourceConfig.type + metadata = evalStoredCompletionsDataSourceConfig.metadata + additionalProperties = + evalStoredCompletionsDataSourceConfig.additionalProperties.toMutableMap() + } + + /** + * The json schema for the run data source items. Learn how to build JSON schemas + * [here](https://json-schema.org/). + */ + fun schema(schema: Schema) = schema(JsonField.of(schema)) + + /** + * Sets [Builder.schema] to an arbitrary JSON value. + * + * You should usually call [Builder.schema] with a well-typed [Schema] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun schema(schema: JsonField) = apply { this.schema = schema } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("stored_completions") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalStoredCompletionsDataSourceConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .schema() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalStoredCompletionsDataSourceConfig = + EvalStoredCompletionsDataSourceConfig( + checkRequired("schema", schema), + type, + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalStoredCompletionsDataSourceConfig = apply { + if (validated) { + return@apply + } + + schema().validate() + _type().let { + if (it != JsonValue.from("stored_completions")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + metadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (schema.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("stored_completions")) 1 else 0 } + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + /** + * The json schema for the run data source items. Learn how to build JSON schemas + * [here](https://json-schema.org/). + */ + class Schema + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Schema]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Schema]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(schema: Schema) = apply { + additionalProperties = schema.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Schema]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Schema = Schema(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Schema = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Schema && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Schema{additionalProperties=$additionalProperties}" + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalStoredCompletionsDataSourceConfig && schema == other.schema && type == other.type && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(schema, type, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalStoredCompletionsDataSourceConfig{schema=$schema, type=$type, metadata=$metadata, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalStringCheckGrader.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalStringCheckGrader.kt new file mode 100644 index 00000000..e1279a14 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalStringCheckGrader.kt @@ -0,0 +1,467 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** + * A StringCheckGrader object that performs a string comparison between input and reference using a + * specified operation. + */ +class EvalStringCheckGrader +private constructor( + private val input: JsonField, + private val name: JsonField, + private val operation: JsonField, + private val reference: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("input") @ExcludeMissing input: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("operation") + @ExcludeMissing + operation: JsonField = JsonMissing.of(), + @JsonProperty("reference") @ExcludeMissing reference: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(input, name, operation, reference, type, mutableMapOf()) + + /** + * The input text. This may include template strings. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun input(): String = input.getRequired("input") + + /** + * The name of the grader. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun operation(): Operation = operation.getRequired("operation") + + /** + * The reference text. This may include template strings. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun reference(): String = reference.getRequired("reference") + + /** + * The object type, which is always `string_check`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("string_check") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [input]. + * + * Unlike [input], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input") @ExcludeMissing fun _input(): JsonField = input + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [operation]. + * + * Unlike [operation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operation") @ExcludeMissing fun _operation(): JsonField = operation + + /** + * Returns the raw JSON value of [reference]. + * + * Unlike [reference], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reference") @ExcludeMissing fun _reference(): JsonField = reference + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalStringCheckGrader]. + * + * The following fields are required: + * ```java + * .input() + * .name() + * .operation() + * .reference() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalStringCheckGrader]. */ + class Builder internal constructor() { + + private var input: JsonField? = null + private var name: JsonField? = null + private var operation: JsonField? = null + private var reference: JsonField? = null + private var type: JsonValue = JsonValue.from("string_check") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalStringCheckGrader: EvalStringCheckGrader) = apply { + input = evalStringCheckGrader.input + name = evalStringCheckGrader.name + operation = evalStringCheckGrader.operation + reference = evalStringCheckGrader.reference + type = evalStringCheckGrader.type + additionalProperties = evalStringCheckGrader.additionalProperties.toMutableMap() + } + + /** The input text. This may include template strings. */ + fun input(input: String) = input(JsonField.of(input)) + + /** + * Sets [Builder.input] to an arbitrary JSON value. + * + * You should usually call [Builder.input] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun input(input: JsonField) = apply { this.input = input } + + /** The name of the grader. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`. */ + fun operation(operation: Operation) = operation(JsonField.of(operation)) + + /** + * Sets [Builder.operation] to an arbitrary JSON value. + * + * You should usually call [Builder.operation] with a well-typed [Operation] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun operation(operation: JsonField) = apply { this.operation = operation } + + /** The reference text. This may include template strings. */ + fun reference(reference: String) = reference(JsonField.of(reference)) + + /** + * Sets [Builder.reference] to an arbitrary JSON value. + * + * You should usually call [Builder.reference] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun reference(reference: JsonField) = apply { this.reference = reference } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("string_check") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalStringCheckGrader]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .input() + * .name() + * .operation() + * .reference() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalStringCheckGrader = + EvalStringCheckGrader( + checkRequired("input", input), + checkRequired("name", name), + checkRequired("operation", operation), + checkRequired("reference", reference), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalStringCheckGrader = apply { + if (validated) { + return@apply + } + + input() + name() + operation().validate() + reference() + _type().let { + if (it != JsonValue.from("string_check")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (input.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (operation.asKnown().getOrNull()?.validity() ?: 0) + + (if (reference.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("string_check")) 1 else 0 } + + /** The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`. */ + class Operation @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val EQ = of("eq") + + @JvmField val NE = of("ne") + + @JvmField val LIKE = of("like") + + @JvmField val ILIKE = of("ilike") + + @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) + } + + /** An enum containing [Operation]'s known values. */ + enum class Known { + EQ, + NE, + LIKE, + ILIKE, + } + + /** + * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operation] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + EQ, + NE, + LIKE, + ILIKE, + /** + * An enum member indicating that [Operation] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + EQ -> Value.EQ + NE -> Value.NE + LIKE -> Value.LIKE + ILIKE -> Value.ILIKE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + EQ -> Known.EQ + NE -> Known.NE + LIKE -> Known.LIKE + ILIKE -> Known.ILIKE + else -> throw OpenAIInvalidDataException("Unknown Operation: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + fun validate(): Operation = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalStringCheckGrader && input == other.input && name == other.name && operation == other.operation && reference == other.reference && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(input, name, operation, reference, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalStringCheckGrader{input=$input, name=$name, operation=$operation, reference=$reference, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalTextSimilarityGrader.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalTextSimilarityGrader.kt new file mode 100644 index 00000000..fd9de81b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalTextSimilarityGrader.kt @@ -0,0 +1,562 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkRequired +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A TextSimilarityGrader object which grades text based on similarity metrics. */ +class EvalTextSimilarityGrader +private constructor( + private val evaluationMetric: JsonField, + private val input: JsonField, + private val passThreshold: JsonField, + private val reference: JsonField, + private val type: JsonValue, + private val name: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("evaluation_metric") + @ExcludeMissing + evaluationMetric: JsonField = JsonMissing.of(), + @JsonProperty("input") @ExcludeMissing input: JsonField = JsonMissing.of(), + @JsonProperty("pass_threshold") + @ExcludeMissing + passThreshold: JsonField = JsonMissing.of(), + @JsonProperty("reference") @ExcludeMissing reference: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(evaluationMetric, input, passThreshold, reference, type, name, mutableMapOf()) + + /** + * The evaluation metric to use. One of `cosine`, `fuzzy_match`, `bleu`, `gleu`, `meteor`, + * `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun evaluationMetric(): EvaluationMetric = evaluationMetric.getRequired("evaluation_metric") + + /** + * The text being graded. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun input(): String = input.getRequired("input") + + /** + * A float score where a value greater than or equal indicates a passing grade. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun passThreshold(): Double = passThreshold.getRequired("pass_threshold") + + /** + * The text being graded against. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun reference(): String = reference.getRequired("reference") + + /** + * The type of grader. + * + * Expected to always return the following: + * ```java + * JsonValue.from("text_similarity") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * The name of the grader. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Returns the raw JSON value of [evaluationMetric]. + * + * Unlike [evaluationMetric], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("evaluation_metric") + @ExcludeMissing + fun _evaluationMetric(): JsonField = evaluationMetric + + /** + * Returns the raw JSON value of [input]. + * + * Unlike [input], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input") @ExcludeMissing fun _input(): JsonField = input + + /** + * Returns the raw JSON value of [passThreshold]. + * + * Unlike [passThreshold], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("pass_threshold") + @ExcludeMissing + fun _passThreshold(): JsonField = passThreshold + + /** + * Returns the raw JSON value of [reference]. + * + * Unlike [reference], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("reference") @ExcludeMissing fun _reference(): JsonField = reference + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalTextSimilarityGrader]. + * + * The following fields are required: + * ```java + * .evaluationMetric() + * .input() + * .passThreshold() + * .reference() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalTextSimilarityGrader]. */ + class Builder internal constructor() { + + private var evaluationMetric: JsonField? = null + private var input: JsonField? = null + private var passThreshold: JsonField? = null + private var reference: JsonField? = null + private var type: JsonValue = JsonValue.from("text_similarity") + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalTextSimilarityGrader: EvalTextSimilarityGrader) = apply { + evaluationMetric = evalTextSimilarityGrader.evaluationMetric + input = evalTextSimilarityGrader.input + passThreshold = evalTextSimilarityGrader.passThreshold + reference = evalTextSimilarityGrader.reference + type = evalTextSimilarityGrader.type + name = evalTextSimilarityGrader.name + additionalProperties = evalTextSimilarityGrader.additionalProperties.toMutableMap() + } + + /** + * The evaluation metric to use. One of `cosine`, `fuzzy_match`, `bleu`, `gleu`, `meteor`, + * `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`. + */ + fun evaluationMetric(evaluationMetric: EvaluationMetric) = + evaluationMetric(JsonField.of(evaluationMetric)) + + /** + * Sets [Builder.evaluationMetric] to an arbitrary JSON value. + * + * You should usually call [Builder.evaluationMetric] with a well-typed [EvaluationMetric] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun evaluationMetric(evaluationMetric: JsonField) = apply { + this.evaluationMetric = evaluationMetric + } + + /** The text being graded. */ + fun input(input: String) = input(JsonField.of(input)) + + /** + * Sets [Builder.input] to an arbitrary JSON value. + * + * You should usually call [Builder.input] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun input(input: JsonField) = apply { this.input = input } + + /** A float score where a value greater than or equal indicates a passing grade. */ + fun passThreshold(passThreshold: Double) = passThreshold(JsonField.of(passThreshold)) + + /** + * Sets [Builder.passThreshold] to an arbitrary JSON value. + * + * You should usually call [Builder.passThreshold] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun passThreshold(passThreshold: JsonField) = apply { + this.passThreshold = passThreshold + } + + /** The text being graded against. */ + fun reference(reference: String) = reference(JsonField.of(reference)) + + /** + * Sets [Builder.reference] to an arbitrary JSON value. + * + * You should usually call [Builder.reference] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun reference(reference: JsonField) = apply { this.reference = reference } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("text_similarity") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** The name of the grader. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalTextSimilarityGrader]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .evaluationMetric() + * .input() + * .passThreshold() + * .reference() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalTextSimilarityGrader = + EvalTextSimilarityGrader( + checkRequired("evaluationMetric", evaluationMetric), + checkRequired("input", input), + checkRequired("passThreshold", passThreshold), + checkRequired("reference", reference), + type, + name, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalTextSimilarityGrader = apply { + if (validated) { + return@apply + } + + evaluationMetric().validate() + input() + passThreshold() + reference() + _type().let { + if (it != JsonValue.from("text_similarity")) { + throw OpenAIInvalidDataException("'type' is invalid, received $it") + } + } + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (evaluationMetric.asKnown().getOrNull()?.validity() ?: 0) + + (if (input.asKnown().isPresent) 1 else 0) + + (if (passThreshold.asKnown().isPresent) 1 else 0) + + (if (reference.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("text_similarity")) 1 else 0 } + + (if (name.asKnown().isPresent) 1 else 0) + + /** + * The evaluation metric to use. One of `cosine`, `fuzzy_match`, `bleu`, `gleu`, `meteor`, + * `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`. + */ + class EvaluationMetric @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val FUZZY_MATCH = of("fuzzy_match") + + @JvmField val BLEU = of("bleu") + + @JvmField val GLEU = of("gleu") + + @JvmField val METEOR = of("meteor") + + @JvmField val ROUGE_1 = of("rouge_1") + + @JvmField val ROUGE_2 = of("rouge_2") + + @JvmField val ROUGE_3 = of("rouge_3") + + @JvmField val ROUGE_4 = of("rouge_4") + + @JvmField val ROUGE_5 = of("rouge_5") + + @JvmField val ROUGE_L = of("rouge_l") + + @JvmField val COSINE = of("cosine") + + @JvmStatic fun of(value: String) = EvaluationMetric(JsonField.of(value)) + } + + /** An enum containing [EvaluationMetric]'s known values. */ + enum class Known { + FUZZY_MATCH, + BLEU, + GLEU, + METEOR, + ROUGE_1, + ROUGE_2, + ROUGE_3, + ROUGE_4, + ROUGE_5, + ROUGE_L, + COSINE, + } + + /** + * An enum containing [EvaluationMetric]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EvaluationMetric] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + FUZZY_MATCH, + BLEU, + GLEU, + METEOR, + ROUGE_1, + ROUGE_2, + ROUGE_3, + ROUGE_4, + ROUGE_5, + ROUGE_L, + COSINE, + /** + * An enum member indicating that [EvaluationMetric] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + FUZZY_MATCH -> Value.FUZZY_MATCH + BLEU -> Value.BLEU + GLEU -> Value.GLEU + METEOR -> Value.METEOR + ROUGE_1 -> Value.ROUGE_1 + ROUGE_2 -> Value.ROUGE_2 + ROUGE_3 -> Value.ROUGE_3 + ROUGE_4 -> Value.ROUGE_4 + ROUGE_5 -> Value.ROUGE_5 + ROUGE_L -> Value.ROUGE_L + COSINE -> Value.COSINE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenAIInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FUZZY_MATCH -> Known.FUZZY_MATCH + BLEU -> Known.BLEU + GLEU -> Known.GLEU + METEOR -> Known.METEOR + ROUGE_1 -> Known.ROUGE_1 + ROUGE_2 -> Known.ROUGE_2 + ROUGE_3 -> Known.ROUGE_3 + ROUGE_4 -> Known.ROUGE_4 + ROUGE_5 -> Known.ROUGE_5 + ROUGE_L -> Known.ROUGE_L + COSINE -> Known.COSINE + else -> throw OpenAIInvalidDataException("Unknown EvaluationMetric: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenAIInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + fun validate(): EvaluationMetric = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvaluationMetric && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalTextSimilarityGrader && evaluationMetric == other.evaluationMetric && input == other.input && passThreshold == other.passThreshold && reference == other.reference && type == other.type && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(evaluationMetric, input, passThreshold, reference, type, name, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalTextSimilarityGrader{evaluationMetric=$evaluationMetric, input=$input, passThreshold=$passThreshold, reference=$reference, type=$type, name=$name, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateParams.kt new file mode 100644 index 00000000..c5ea3694 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateParams.kt @@ -0,0 +1,615 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.Params +import com.openai.core.checkRequired +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Update certain properties of an evaluation. */ +class EvalUpdateParams +private constructor( + private val evalId: String, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun evalId(): String = evalId + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = body.metadata() + + /** + * Rename the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = body.name() + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _metadata(): JsonField = body._metadata() + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _name(): JsonField = body._name() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalUpdateParams]. + * + * The following fields are required: + * ```java + * .evalId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalUpdateParams]. */ + class Builder internal constructor() { + + private var evalId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(evalUpdateParams: EvalUpdateParams) = apply { + evalId = evalUpdateParams.evalId + body = evalUpdateParams.body.toBuilder() + additionalHeaders = evalUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = evalUpdateParams.additionalQueryParams.toBuilder() + } + + fun evalId(evalId: String) = apply { this.evalId = evalId } + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [metadata] + * - [name] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) } + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + + /** Rename the evaluation. */ + fun name(name: String) = apply { body.name(name) } + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { body.name(name) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [EvalUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .evalId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalUpdateParams = + EvalUpdateParams( + checkRequired("evalId", evalId), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + fun _pathParam(index: Int): String = + when (index) { + 0 -> evalId + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + private constructor( + private val metadata: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(metadata, name, mutableMapOf()) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Rename the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Body]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var metadata: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + metadata = body.metadata + name = body.name + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying + * for objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** Rename the evaluation. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Body = Body(metadata, name, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + metadata().ifPresent { it.validate() } + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Body && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, name, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{metadata=$metadata, name=$name, additionalProperties=$additionalProperties}" + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalUpdateParams && evalId == other.evalId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(evalId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "EvalUpdateParams{evalId=$evalId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateResponse.kt new file mode 100644 index 00000000..929f696d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateResponse.kt @@ -0,0 +1,1145 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * An Eval object with a data source config and testing criteria. An Eval represents a task to be + * done for your LLM integration. Like: + * - Improve the quality of my chatbot + * - See how well my chatbot handles customer support + * - Check if o3-mini is better at my usecase than gpt-4o + */ +class EvalUpdateResponse +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val dataSourceConfig: JsonField, + private val metadata: JsonField, + private val name: JsonField, + private val object_: JsonValue, + private val shareWithOpenAI: JsonField, + private val testingCriteria: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("data_source_config") + @ExcludeMissing + dataSourceConfig: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("share_with_openai") + @ExcludeMissing + shareWithOpenAI: JsonField = JsonMissing.of(), + @JsonProperty("testing_criteria") + @ExcludeMissing + testingCriteria: JsonField> = JsonMissing.of(), + ) : this( + id, + createdAt, + dataSourceConfig, + metadata, + name, + object_, + shareWithOpenAI, + testingCriteria, + mutableMapOf(), + ) + + /** + * Unique identifier for the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun id(): String = id.getRequired("id") + + /** + * The Unix timestamp (in seconds) for when the eval was created. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun createdAt(): Long = createdAt.getRequired("created_at") + + /** + * Configuration of data sources used in runs of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun dataSourceConfig(): DataSourceConfig = dataSourceConfig.getRequired("data_source_config") + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * The name of the evaluation. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun name(): String = name.getRequired("name") + + /** + * The object type. + * + * Expected to always return the following: + * ```java + * JsonValue.from("eval") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Indicates whether the evaluation is shared with OpenAI. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun shareWithOpenAI(): Boolean = shareWithOpenAI.getRequired("share_with_openai") + + /** + * A list of testing criteria. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun testingCriteria(): List = testingCriteria.getRequired("testing_criteria") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [dataSourceConfig]. + * + * Unlike [dataSourceConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("data_source_config") + @ExcludeMissing + fun _dataSourceConfig(): JsonField = dataSourceConfig + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [shareWithOpenAI]. + * + * Unlike [shareWithOpenAI], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("share_with_openai") + @ExcludeMissing + fun _shareWithOpenAI(): JsonField = shareWithOpenAI + + /** + * Returns the raw JSON value of [testingCriteria]. + * + * Unlike [testingCriteria], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("testing_criteria") + @ExcludeMissing + fun _testingCriteria(): JsonField> = testingCriteria + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [EvalUpdateResponse]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .dataSourceConfig() + * .metadata() + * .name() + * .shareWithOpenAI() + * .testingCriteria() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalUpdateResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var dataSourceConfig: JsonField? = null + private var metadata: JsonField? = null + private var name: JsonField? = null + private var object_: JsonValue = JsonValue.from("eval") + private var shareWithOpenAI: JsonField? = null + private var testingCriteria: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalUpdateResponse: EvalUpdateResponse) = apply { + id = evalUpdateResponse.id + createdAt = evalUpdateResponse.createdAt + dataSourceConfig = evalUpdateResponse.dataSourceConfig + metadata = evalUpdateResponse.metadata + name = evalUpdateResponse.name + object_ = evalUpdateResponse.object_ + shareWithOpenAI = evalUpdateResponse.shareWithOpenAI + testingCriteria = evalUpdateResponse.testingCriteria.map { it.toMutableList() } + additionalProperties = evalUpdateResponse.additionalProperties.toMutableMap() + } + + /** Unique identifier for the evaluation. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** The Unix timestamp (in seconds) for when the eval was created. */ + fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Configuration of data sources used in runs of the evaluation. */ + fun dataSourceConfig(dataSourceConfig: DataSourceConfig) = + dataSourceConfig(JsonField.of(dataSourceConfig)) + + /** + * Sets [Builder.dataSourceConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.dataSourceConfig] with a well-typed [DataSourceConfig] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun dataSourceConfig(dataSourceConfig: JsonField) = apply { + this.dataSourceConfig = dataSourceConfig + } + + /** Alias for calling [dataSourceConfig] with `DataSourceConfig.ofCustom(custom)`. */ + fun dataSourceConfig(custom: EvalCustomDataSourceConfig) = + dataSourceConfig(DataSourceConfig.ofCustom(custom)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * EvalCustomDataSourceConfig.builder() + * .schema(schema) + * .build() + * ``` + */ + fun customDataSourceConfig(schema: EvalCustomDataSourceConfig.Schema) = + dataSourceConfig(EvalCustomDataSourceConfig.builder().schema(schema).build()) + + /** + * Alias for calling [dataSourceConfig] with + * `DataSourceConfig.ofStoredCompletions(storedCompletions)`. + */ + fun dataSourceConfig(storedCompletions: EvalStoredCompletionsDataSourceConfig) = + dataSourceConfig(DataSourceConfig.ofStoredCompletions(storedCompletions)) + + /** + * Alias for calling [dataSourceConfig] with the following: + * ```java + * EvalStoredCompletionsDataSourceConfig.builder() + * .schema(schema) + * .build() + * ``` + */ + fun storedCompletionsDataSourceConfig( + schema: EvalStoredCompletionsDataSourceConfig.Schema + ) = dataSourceConfig(EvalStoredCompletionsDataSourceConfig.builder().schema(schema).build()) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format, and querying for + * objects via API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a + * maximum length of 512 characters. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** The name of the evaluation. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("eval") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + /** Indicates whether the evaluation is shared with OpenAI. */ + fun shareWithOpenAI(shareWithOpenAI: Boolean) = + shareWithOpenAI(JsonField.of(shareWithOpenAI)) + + /** + * Sets [Builder.shareWithOpenAI] to an arbitrary JSON value. + * + * You should usually call [Builder.shareWithOpenAI] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun shareWithOpenAI(shareWithOpenAI: JsonField) = apply { + this.shareWithOpenAI = shareWithOpenAI + } + + /** A list of testing criteria. */ + fun testingCriteria(testingCriteria: List) = + testingCriteria(JsonField.of(testingCriteria)) + + /** + * Sets [Builder.testingCriteria] to an arbitrary JSON value. + * + * You should usually call [Builder.testingCriteria] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun testingCriteria(testingCriteria: JsonField>) = apply { + this.testingCriteria = testingCriteria.map { it.toMutableList() } + } + + /** + * Adds a single [TestingCriterion] to [testingCriteria]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTestingCriterion(testingCriterion: TestingCriterion) = apply { + testingCriteria = + (testingCriteria ?: JsonField.of(mutableListOf())).also { + checkKnown("testingCriteria", it).add(testingCriterion) + } + } + + /** + * Alias for calling [addTestingCriterion] with `TestingCriterion.ofLabelModel(labelModel)`. + */ + fun addTestingCriterion(labelModel: EvalLabelModelGrader) = + addTestingCriterion(TestingCriterion.ofLabelModel(labelModel)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofStringCheck(stringCheck)`. + */ + fun addTestingCriterion(stringCheck: EvalStringCheckGrader) = + addTestingCriterion(TestingCriterion.ofStringCheck(stringCheck)) + + /** + * Alias for calling [addTestingCriterion] with + * `TestingCriterion.ofTextSimilarity(textSimilarity)`. + */ + fun addTestingCriterion(textSimilarity: EvalTextSimilarityGrader) = + addTestingCriterion(TestingCriterion.ofTextSimilarity(textSimilarity)) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [EvalUpdateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .dataSourceConfig() + * .metadata() + * .name() + * .shareWithOpenAI() + * .testingCriteria() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalUpdateResponse = + EvalUpdateResponse( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("dataSourceConfig", dataSourceConfig), + checkRequired("metadata", metadata), + checkRequired("name", name), + object_, + checkRequired("shareWithOpenAI", shareWithOpenAI), + checkRequired("testingCriteria", testingCriteria).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalUpdateResponse = apply { + if (validated) { + return@apply + } + + id() + createdAt() + dataSourceConfig().validate() + metadata().ifPresent { it.validate() } + name() + _object_().let { + if (it != JsonValue.from("eval")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + shareWithOpenAI() + testingCriteria().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (dataSourceConfig.asKnown().getOrNull()?.validity() ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("eval")) 1 else 0 } + + (if (shareWithOpenAI.asKnown().isPresent) 1 else 0) + + (testingCriteria.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** Configuration of data sources used in runs of the evaluation. */ + @JsonDeserialize(using = DataSourceConfig.Deserializer::class) + @JsonSerialize(using = DataSourceConfig.Serializer::class) + class DataSourceConfig + private constructor( + private val custom: EvalCustomDataSourceConfig? = null, + private val storedCompletions: EvalStoredCompletionsDataSourceConfig? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun custom(): Optional = Optional.ofNullable(custom) + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both defined + * when using this data source config. + */ + fun storedCompletions(): Optional = + Optional.ofNullable(storedCompletions) + + fun isCustom(): Boolean = custom != null + + fun isStoredCompletions(): Boolean = storedCompletions != null + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun asCustom(): EvalCustomDataSourceConfig = custom.getOrThrow("custom") + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your stored + * completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both defined + * when using this data source config. + */ + fun asStoredCompletions(): EvalStoredCompletionsDataSourceConfig = + storedCompletions.getOrThrow("storedCompletions") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + custom != null -> visitor.visitCustom(custom) + storedCompletions != null -> visitor.visitStoredCompletions(storedCompletions) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): DataSourceConfig = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitCustom(custom: EvalCustomDataSourceConfig) { + custom.validate() + } + + override fun visitStoredCompletions( + storedCompletions: EvalStoredCompletionsDataSourceConfig + ) { + storedCompletions.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitCustom(custom: EvalCustomDataSourceConfig) = custom.validity() + + override fun visitStoredCompletions( + storedCompletions: EvalStoredCompletionsDataSourceConfig + ) = storedCompletions.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DataSourceConfig && custom == other.custom && storedCompletions == other.storedCompletions /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(custom, storedCompletions) /* spotless:on */ + + override fun toString(): String = + when { + custom != null -> "DataSourceConfig{custom=$custom}" + storedCompletions != null -> + "DataSourceConfig{storedCompletions=$storedCompletions}" + _json != null -> "DataSourceConfig{_unknown=$_json}" + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + + companion object { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + @JvmStatic + fun ofCustom(custom: EvalCustomDataSourceConfig) = DataSourceConfig(custom = custom) + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your + * stored completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both + * defined when using this data source config. + */ + @JvmStatic + fun ofStoredCompletions(storedCompletions: EvalStoredCompletionsDataSourceConfig) = + DataSourceConfig(storedCompletions = storedCompletions) + } + + /** + * An interface that defines how to map each variant of [DataSourceConfig] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A CustomDataSourceConfig which specifies the schema of your `item` and optionally + * `sample` namespaces. The response schema defines the shape of the data that will be: + * - Used to define your testing criteria and + * - What data is required when creating a run + */ + fun visitCustom(custom: EvalCustomDataSourceConfig): T + + /** + * A StoredCompletionsDataSourceConfig which specifies the metadata property of your + * stored completions query. This is usually metadata like `usecase=chatbot` or + * `prompt-version=v2`, etc. The schema returned by this data source config is used to + * defined what variables are available in your evals. `item` and `sample` are both + * defined when using this data source config. + */ + fun visitStoredCompletions(storedCompletions: EvalStoredCompletionsDataSourceConfig): T + + /** + * Maps an unknown variant of [DataSourceConfig] to a value of type [T]. + * + * An instance of [DataSourceConfig] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown DataSourceConfig: $json") + } + } + + internal class Deserializer : BaseDeserializer(DataSourceConfig::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): DataSourceConfig { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "custom" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { DataSourceConfig(custom = it, _json = json) } + ?: DataSourceConfig(_json = json) + } + "stored_completions" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { DataSourceConfig(storedCompletions = it, _json = json) } + ?: DataSourceConfig(_json = json) + } + } + + return DataSourceConfig(_json = json) + } + } + + internal class Serializer : BaseSerializer(DataSourceConfig::class) { + + override fun serialize( + value: DataSourceConfig, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.custom != null -> generator.writeObject(value.custom) + value.storedCompletions != null -> + generator.writeObject(value.storedCompletions) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid DataSourceConfig") + } + } + } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format, and querying for objects via + * API or the dashboard. + * + * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum + * length of 512 characters. + */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the evaluation. + */ + @JsonDeserialize(using = TestingCriterion.Deserializer::class) + @JsonSerialize(using = TestingCriterion.Serializer::class) + class TestingCriterion + private constructor( + private val labelModel: EvalLabelModelGrader? = null, + private val stringCheck: EvalStringCheckGrader? = null, + private val textSimilarity: EvalTextSimilarityGrader? = null, + private val _json: JsonValue? = null, + ) { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun labelModel(): Optional = Optional.ofNullable(labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun stringCheck(): Optional = Optional.ofNullable(stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun textSimilarity(): Optional = + Optional.ofNullable(textSimilarity) + + fun isLabelModel(): Boolean = labelModel != null + + fun isStringCheck(): Boolean = stringCheck != null + + fun isTextSimilarity(): Boolean = textSimilarity != null + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun asLabelModel(): EvalLabelModelGrader = labelModel.getOrThrow("labelModel") + + /** + * A StringCheckGrader object that performs a string comparison between input and reference + * using a specified operation. + */ + fun asStringCheck(): EvalStringCheckGrader = stringCheck.getOrThrow("stringCheck") + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun asTextSimilarity(): EvalTextSimilarityGrader = + textSimilarity.getOrThrow("textSimilarity") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + labelModel != null -> visitor.visitLabelModel(labelModel) + stringCheck != null -> visitor.visitStringCheck(stringCheck) + textSimilarity != null -> visitor.visitTextSimilarity(textSimilarity) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): TestingCriterion = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitLabelModel(labelModel: EvalLabelModelGrader) { + labelModel.validate() + } + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) { + stringCheck.validate() + } + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) { + textSimilarity.validate() + } + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitLabelModel(labelModel: EvalLabelModelGrader) = + labelModel.validity() + + override fun visitStringCheck(stringCheck: EvalStringCheckGrader) = + stringCheck.validity() + + override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + textSimilarity.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TestingCriterion && labelModel == other.labelModel && stringCheck == other.stringCheck && textSimilarity == other.textSimilarity /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(labelModel, stringCheck, textSimilarity) /* spotless:on */ + + override fun toString(): String = + when { + labelModel != null -> "TestingCriterion{labelModel=$labelModel}" + stringCheck != null -> "TestingCriterion{stringCheck=$stringCheck}" + textSimilarity != null -> "TestingCriterion{textSimilarity=$textSimilarity}" + _json != null -> "TestingCriterion{_unknown=$_json}" + else -> throw IllegalStateException("Invalid TestingCriterion") + } + + companion object { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + @JvmStatic + fun ofLabelModel(labelModel: EvalLabelModelGrader) = + TestingCriterion(labelModel = labelModel) + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + @JvmStatic + fun ofStringCheck(stringCheck: EvalStringCheckGrader) = + TestingCriterion(stringCheck = stringCheck) + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + @JvmStatic + fun ofTextSimilarity(textSimilarity: EvalTextSimilarityGrader) = + TestingCriterion(textSimilarity = textSimilarity) + } + + /** + * An interface that defines how to map each variant of [TestingCriterion] to a value of + * type [T]. + */ + interface Visitor { + + /** + * A LabelModelGrader object which uses a model to assign labels to each item in the + * evaluation. + */ + fun visitLabelModel(labelModel: EvalLabelModelGrader): T + + /** + * A StringCheckGrader object that performs a string comparison between input and + * reference using a specified operation. + */ + fun visitStringCheck(stringCheck: EvalStringCheckGrader): T + + /** A TextSimilarityGrader object which grades text based on similarity metrics. */ + fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader): T + + /** + * Maps an unknown variant of [TestingCriterion] to a value of type [T]. + * + * An instance of [TestingCriterion] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if the SDK + * is on an older version than the API, then the API may respond with new variants that + * the SDK is unaware of. + * + * @throws OpenAIInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown TestingCriterion: $json") + } + } + + internal class Deserializer : BaseDeserializer(TestingCriterion::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): TestingCriterion { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "label_model" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(labelModel = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "string_check" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + TestingCriterion(stringCheck = it, _json = json) + } ?: TestingCriterion(_json = json) + } + "text_similarity" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { TestingCriterion(textSimilarity = it, _json = json) } + ?: TestingCriterion(_json = json) + } + } + + return TestingCriterion(_json = json) + } + } + + internal class Serializer : BaseSerializer(TestingCriterion::class) { + + override fun serialize( + value: TestingCriterion, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.labelModel != null -> generator.writeObject(value.labelModel) + value.stringCheck != null -> generator.writeObject(value.stringCheck) + value.textSimilarity != null -> generator.writeObject(value.textSimilarity) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid TestingCriterion") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalUpdateResponse && id == other.id && createdAt == other.createdAt && dataSourceConfig == other.dataSourceConfig && metadata == other.metadata && name == other.name && object_ == other.object_ && shareWithOpenAI == other.shareWithOpenAI && testingCriteria == other.testingCriteria && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, createdAt, dataSourceConfig, metadata, name, object_, shareWithOpenAI, testingCriteria, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalUpdateResponse{id=$id, createdAt=$createdAt, dataSourceConfig=$dataSourceConfig, metadata=$metadata, name=$name, object_=$object_, shareWithOpenAI=$shareWithOpenAI, testingCriteria=$testingCriteria, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSource.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSource.kt new file mode 100644 index 00000000..d2fe6e43 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSource.kt @@ -0,0 +1,5102 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals.runs + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.allMaxBy +import com.openai.core.checkKnown +import com.openai.core.checkRequired +import com.openai.core.getOrThrow +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A CompletionsRunDataSource object describing a model sampling configuration. */ +class CreateEvalCompletionsRunDataSource +private constructor( + private val inputMessages: JsonField, + private val model: JsonField, + private val source: JsonField, + private val type: JsonField, + private val samplingParams: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("input_messages") + @ExcludeMissing + inputMessages: JsonField = JsonMissing.of(), + @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("sampling_params") + @ExcludeMissing + samplingParams: JsonField = JsonMissing.of(), + ) : this(inputMessages, model, source, type, samplingParams, mutableMapOf()) + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun inputMessages(): InputMessages = inputMessages.getRequired("input_messages") + + /** + * The name of the model to use for generating completions (e.g. "o3-mini"). + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun model(): String = model.getRequired("model") + + /** + * A StoredCompletionsRunDataSource configuration describing a set of filters + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun source(): Source = source.getRequired("source") + + /** + * The type of run data source. Always `completions`. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun type(): Type = type.getRequired("type") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun samplingParams(): Optional = samplingParams.getOptional("sampling_params") + + /** + * Returns the raw JSON value of [inputMessages]. + * + * Unlike [inputMessages], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_messages") + @ExcludeMissing + fun _inputMessages(): JsonField = inputMessages + + /** + * Returns the raw JSON value of [model]. + * + * Unlike [model], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [samplingParams]. + * + * Unlike [samplingParams], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sampling_params") + @ExcludeMissing + fun _samplingParams(): JsonField = samplingParams + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CreateEvalCompletionsRunDataSource]. + * + * The following fields are required: + * ```java + * .inputMessages() + * .model() + * .source() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreateEvalCompletionsRunDataSource]. */ + class Builder internal constructor() { + + private var inputMessages: JsonField? = null + private var model: JsonField? = null + private var source: JsonField? = null + private var type: JsonField? = null + private var samplingParams: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(createEvalCompletionsRunDataSource: CreateEvalCompletionsRunDataSource) = + apply { + inputMessages = createEvalCompletionsRunDataSource.inputMessages + model = createEvalCompletionsRunDataSource.model + source = createEvalCompletionsRunDataSource.source + type = createEvalCompletionsRunDataSource.type + samplingParams = createEvalCompletionsRunDataSource.samplingParams + additionalProperties = + createEvalCompletionsRunDataSource.additionalProperties.toMutableMap() + } + + fun inputMessages(inputMessages: InputMessages) = inputMessages(JsonField.of(inputMessages)) + + /** + * Sets [Builder.inputMessages] to an arbitrary JSON value. + * + * You should usually call [Builder.inputMessages] with a well-typed [InputMessages] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun inputMessages(inputMessages: JsonField) = apply { + this.inputMessages = inputMessages + } + + /** Alias for calling [inputMessages] with `InputMessages.ofTemplate(template)`. */ + fun inputMessages(template: InputMessages.Template) = + inputMessages(InputMessages.ofTemplate(template)) + + /** + * Alias for calling [inputMessages] with the following: + * ```java + * InputMessages.Template.builder() + * .template(template) + * .build() + * ``` + */ + fun templateInputMessages(template: List) = + inputMessages(InputMessages.Template.builder().template(template).build()) + + /** + * Alias for calling [inputMessages] with `InputMessages.ofItemReference(itemReference)`. + */ + fun inputMessages(itemReference: InputMessages.ItemReference) = + inputMessages(InputMessages.ofItemReference(itemReference)) + + /** + * Alias for calling [inputMessages] with the following: + * ```java + * InputMessages.ItemReference.builder() + * .itemReference(itemReference) + * .build() + * ``` + */ + fun itemReferenceInputMessages(itemReference: String) = + inputMessages( + InputMessages.ItemReference.builder().itemReference(itemReference).build() + ) + + /** The name of the model to use for generating completions (e.g. "o3-mini"). */ + fun model(model: String) = model(JsonField.of(model)) + + /** + * Sets [Builder.model] to an arbitrary JSON value. + * + * You should usually call [Builder.model] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** A StoredCompletionsRunDataSource configuration describing a set of filters */ + fun source(source: Source) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [Source] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** Alias for calling [source] with `Source.ofFileContent(fileContent)`. */ + fun source(fileContent: Source.FileContent) = source(Source.ofFileContent(fileContent)) + + /** + * Alias for calling [source] with the following: + * ```java + * Source.FileContent.builder() + * .content(content) + * .build() + * ``` + */ + fun fileContentSource(content: List) = + source(Source.FileContent.builder().content(content).build()) + + /** Alias for calling [source] with `Source.ofFileId(fileId)`. */ + fun source(fileId: Source.FileId) = source(Source.ofFileId(fileId)) + + /** + * Alias for calling [source] with the following: + * ```java + * Source.FileId.builder() + * .id(id) + * .build() + * ``` + */ + fun fileIdSource(id: String) = source(Source.FileId.builder().id(id).build()) + + /** Alias for calling [source] with `Source.ofStoredCompletions(storedCompletions)`. */ + fun source(storedCompletions: Source.StoredCompletions) = + source(Source.ofStoredCompletions(storedCompletions)) + + /** The type of run data source. Always `completions`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun samplingParams(samplingParams: SamplingParams) = + samplingParams(JsonField.of(samplingParams)) + + /** + * Sets [Builder.samplingParams] to an arbitrary JSON value. + * + * You should usually call [Builder.samplingParams] with a well-typed [SamplingParams] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun samplingParams(samplingParams: JsonField) = apply { + this.samplingParams = samplingParams + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [CreateEvalCompletionsRunDataSource]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .inputMessages() + * .model() + * .source() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreateEvalCompletionsRunDataSource = + CreateEvalCompletionsRunDataSource( + checkRequired("inputMessages", inputMessages), + checkRequired("model", model), + checkRequired("source", source), + checkRequired("type", type), + samplingParams, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CreateEvalCompletionsRunDataSource = apply { + if (validated) { + return@apply + } + + inputMessages().validate() + model() + source().validate() + type().validate() + samplingParams().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (inputMessages.asKnown().getOrNull()?.validity() ?: 0) + + (if (model.asKnown().isPresent) 1 else 0) + + (source.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (samplingParams.asKnown().getOrNull()?.validity() ?: 0) + + @JsonDeserialize(using = InputMessages.Deserializer::class) + @JsonSerialize(using = InputMessages.Serializer::class) + class InputMessages + private constructor( + private val template: Template? = null, + private val itemReference: ItemReference? = null, + private val _json: JsonValue? = null, + ) { + + fun template(): Optional