From 44a353a63c423f8db555831fae2b0bc2ab672a63 Mon Sep 17 00:00:00 2001 From: Andres Cruz Date: Mon, 25 Nov 2024 17:49:30 +0100 Subject: [PATCH] NO-JIRA: Upgrade Fern to latest versions (#719) --- .../documentation/rest_api/opik.yaml | 104 +++- sdks/python/.pre-commit-config.yaml | 1 + .../code_generation/fern/fern.config.json | 2 +- .../code_generation/fern/generators.yml | 4 +- .../code_generation/fern/openapi/openapi.yaml | 104 +++- sdks/python/src/opik/rest_api/__init__.py | 8 +- sdks/python/src/opik/rest_api/client.py | 121 ++-- .../python/src/opik/rest_api/core/__init__.py | 25 +- .../src/opik/rest_api/core/client_wrapper.py | 21 +- sdks/python/src/opik/rest_api/core/file.py | 49 +- .../src/opik/rest_api/core/http_client.py | 92 ++- .../opik/rest_api/core/jsonable_encoder.py | 68 ++- .../opik/rest_api/core/pydantic_utilities.py | 303 +++++++++- .../src/opik/rest_api/core/query_encoder.py | 55 +- .../src/opik/rest_api/core/request_options.py | 3 + .../src/opik/rest_api/core/serialization.py | 276 +++++++++ .../src/opik/rest_api/datasets/client.py | 327 +++++++---- .../opik/rest_api/errors/bad_request_error.py | 5 +- .../opik/rest_api/errors/conflict_error.py | 5 +- .../opik/rest_api/errors/not_found_error.py | 5 +- .../rest_api/errors/not_implemented_error.py | 5 +- .../errors/unprocessable_entity_error.py | 5 +- .../src/opik/rest_api/experiments/client.py | 367 +++++++++--- .../rest_api/feedback_definitions/client.py | 161 ++++-- .../opik/rest_api/feedback_scores/__init__.py | 1 - .../opik/rest_api/feedback_scores/client.py | 123 ---- .../src/opik/rest_api/projects/client.py | 388 ++++++++++--- .../src/opik/rest_api/prompts/client.py | 535 ++++++++++++++---- .../src/opik/rest_api/spans/__init__.py | 4 +- sdks/python/src/opik/rest_api/spans/client.py | 332 +++++++++-- .../src/opik/rest_api/spans/types/__init__.py | 3 +- ...ind_feedback_score_names_1_request_type.py | 7 + .../src/opik/rest_api/system_usage/client.py | 98 +++- .../rest_api/tests/utils/test_http_client.py | 59 -- .../tests/utils/test_query_encoding.py | 19 - .../python/src/opik/rest_api/traces/client.py | 273 +++++++-- .../src/opik/rest_api/types/bi_information.py | 47 +- .../rest_api/types/bi_information_response.py | 47 +- .../types/categorical_feedback_definition.py | 48 +- .../categorical_feedback_definition_create.py | 47 +- .../categorical_feedback_definition_public.py | 48 +- .../categorical_feedback_definition_update.py | 47 +- .../types/categorical_feedback_detail.py | 47 +- .../categorical_feedback_detail_create.py | 47 +- .../categorical_feedback_detail_public.py | 47 +- .../categorical_feedback_detail_update.py | 47 +- .../types/chunked_output_json_node.py | 47 +- .../types/chunked_output_json_node_type.py | 63 +-- .../src/opik/rest_api/types/column_compare.py | 47 +- .../src/opik/rest_api/types/column_public.py | 47 +- .../opik/rest_api/types/data_point_public.py | 48 +- .../python/src/opik/rest_api/types/dataset.py | 48 +- .../src/opik/rest_api/types/dataset_item.py | 50 +- .../opik/rest_api/types/dataset_item_batch.py | 51 +- .../rest_api/types/dataset_item_compare.py | 52 +- .../types/dataset_item_page_compare.py | 49 +- .../types/dataset_item_page_public.py | 49 +- .../rest_api/types/dataset_item_public.py | 52 +- .../opik/rest_api/types/dataset_item_write.py | 49 +- .../rest_api/types/dataset_page_public.py | 47 +- .../src/opik/rest_api/types/dataset_public.py | 48 +- .../rest_api/types/delete_feedback_score.py | 47 +- .../src/opik/rest_api/types/error_message.py | 47 +- .../rest_api/types/error_message_detail.py | 47 +- .../rest_api/types/error_message_public.py | 47 +- .../src/opik/rest_api/types/experiment.py | 50 +- .../opik/rest_api/types/experiment_item.py | 50 +- .../rest_api/types/experiment_item_compare.py | 50 +- .../rest_api/types/experiment_item_public.py | 48 +- .../rest_api/types/experiment_page_public.py | 47 +- .../opik/rest_api/types/experiment_public.py | 50 +- .../src/opik/rest_api/types/feedback.py | 169 ++---- .../opik/rest_api/types/feedback_create.py | 136 ++--- .../types/feedback_definition_page_public.py | 47 +- .../rest_api/types/feedback_object_public.py | 169 ++---- .../opik/rest_api/types/feedback_public.py | 169 ++---- .../src/opik/rest_api/types/feedback_score.py | 48 +- .../rest_api/types/feedback_score_average.py | 47 +- .../types/feedback_score_average_public.py | 47 +- .../rest_api/types/feedback_score_batch.py | 47 +- .../types/feedback_score_batch_item.py | 49 +- .../rest_api/types/feedback_score_compare.py | 48 +- .../rest_api/types/feedback_score_public.py | 48 +- .../opik/rest_api/types/feedback_update.py | 136 ++--- .../src/opik/rest_api/types/json_node.py | 2 +- .../opik/rest_api/types/json_node_compare.py | 2 +- .../opik/rest_api/types/json_node_public.py | 2 +- .../opik/rest_api/types/json_node_write.py | 2 +- .../types/numerical_feedback_definition.py | 48 +- .../numerical_feedback_definition_create.py | 47 +- .../numerical_feedback_definition_public.py | 48 +- .../numerical_feedback_definition_update.py | 47 +- .../types/numerical_feedback_detail.py | 47 +- .../types/numerical_feedback_detail_create.py | 47 +- .../types/numerical_feedback_detail_public.py | 47 +- .../types/numerical_feedback_detail_update.py | 47 +- .../python/src/opik/rest_api/types/project.py | 48 +- .../types/project_metric_response_public.py | 49 +- .../rest_api/types/project_page_public.py | 61 +- .../src/opik/rest_api/types/project_public.py | 48 +- sdks/python/src/opik/rest_api/types/prompt.py | 48 +- .../src/opik/rest_api/types/prompt_detail.py | 48 +- .../opik/rest_api/types/prompt_page_public.py | 47 +- .../src/opik/rest_api/types/prompt_public.py | 48 +- .../src/opik/rest_api/types/prompt_version.py | 52 +- .../rest_api/types/prompt_version_detail.py | 52 +- .../rest_api/types/prompt_version_link.py | 47 +- .../types/prompt_version_link_public.py | 47 +- .../types/prompt_version_link_write.py | 47 +- .../types/prompt_version_page_public.py | 47 +- .../rest_api/types/prompt_version_public.py | 52 +- .../src/opik/rest_api/types/results_public.py | 47 +- sdks/python/src/opik/rest_api/types/span.py | 54 +- .../src/opik/rest_api/types/span_batch.py | 47 +- .../opik/rest_api/types/span_page_public.py | 47 +- .../src/opik/rest_api/types/span_public.py | 52 +- .../src/opik/rest_api/types/span_write.py | 52 +- sdks/python/src/opik/rest_api/types/trace.py | 52 +- .../src/opik/rest_api/types/trace_batch.py | 47 +- .../rest_api/types/trace_count_response.py | 47 +- .../opik/rest_api/types/trace_page_public.py | 47 +- .../src/opik/rest_api/types/trace_public.py | 50 +- .../src/opik/rest_api/types/trace_write.py | 50 +- .../rest_api/types/workspace_trace_count.py | 47 +- 124 files changed, 4289 insertions(+), 4297 deletions(-) create mode 100644 sdks/python/src/opik/rest_api/core/serialization.py delete mode 100644 sdks/python/src/opik/rest_api/feedback_scores/__init__.py delete mode 100644 sdks/python/src/opik/rest_api/feedback_scores/client.py create mode 100644 sdks/python/src/opik/rest_api/spans/types/find_feedback_score_names_1_request_type.py delete mode 100644 sdks/python/src/opik/rest_api/tests/utils/test_http_client.py delete mode 100644 sdks/python/src/opik/rest_api/tests/utils/test_query_encoding.py diff --git a/apps/opik-documentation/documentation/rest_api/opik.yaml b/apps/opik-documentation/documentation/rest_api/opik.yaml index 09630a9b4c..062d36802b 100644 --- a/apps/opik-documentation/documentation/rest_api/opik.yaml +++ b/apps/opik-documentation/documentation/rest_api/opik.yaml @@ -43,8 +43,6 @@ tags: description: Experiment resources - name: Feedback-definitions description: Feedback definitions related resources - - name: Feedback-scores - description: Feedback scores related resources - name: Projects description: Project related resources - name: Prompts @@ -541,6 +539,30 @@ paths: responses: "204": description: No content + /v1/private/experiments/feedback-scores/names: + get: + tags: + - Experiments + summary: Find Feedback Score names + description: Find Feedback Score names + operationId: findFeedbackScoreNames + parameters: + - name: experiment_ids + in: query + schema: + type: array + items: + type: string + format: uuid + responses: + "200": + description: Feedback Scores resource + content: + application/json: + schema: + type: array + items: + type: string /v1/private/experiments/{id}: get: tags: @@ -739,32 +761,6 @@ paths: responses: "204": description: No Content - /v1/private/feedback-scores/names: - get: - tags: - - Feedback-scores - summary: Find Feedback Score names - description: Find Feedback Score names - operationId: findFeedbackScoreNames - parameters: - - name: project_id - in: query - schema: - type: string - format: uuid - - name: with_experiments_only - in: query - schema: - type: boolean - responses: - "200": - description: Feedback Scores resource - content: - application/json: - schema: - type: array - items: - type: string /v1/private/projects: get: tags: @@ -1490,6 +1486,36 @@ paths: responses: "204": description: No Content + /v1/private/spans/feedback-scores/names: + get: + tags: + - Spans + summary: Find Feedback Score names + description: Find Feedback Score names + operationId: findFeedbackScoreNames_1 + parameters: + - name: project_id + in: query + schema: + type: string + format: uuid + - name: type + in: query + schema: + type: string + enum: + - general + - tool + - llm + responses: + "200": + description: Feedback Scores resource + content: + application/json: + schema: + type: array + items: + type: string /v1/private/spans/feedback-scores: put: tags: @@ -1704,6 +1730,28 @@ paths: responses: "204": description: No Content + /v1/private/traces/feedback-scores/names: + get: + tags: + - Traces + summary: Find Feedback Score names + description: Find Feedback Score names + operationId: findFeedbackScoreNames_2 + parameters: + - name: project_id + in: query + schema: + type: string + format: uuid + responses: + "200": + description: Feedback Scores resource + content: + application/json: + schema: + type: array + items: + type: string /v1/private/traces/feedback-scores: put: tags: diff --git a/sdks/python/.pre-commit-config.yaml b/sdks/python/.pre-commit-config.yaml index 7ba6c3b791..33d931f88e 100644 --- a/sdks/python/.pre-commit-config.yaml +++ b/sdks/python/.pre-commit-config.yaml @@ -13,6 +13,7 @@ repos: - id: ruff args: [ --fix ] files: ^sdks/python + exclude: '(sdks/python/src/opik/rest_api/)' - id: ruff-format files: ^sdks/python diff --git a/sdks/python/code_generation/fern/fern.config.json b/sdks/python/code_generation/fern/fern.config.json index 531075f1e3..c559e54c94 100644 --- a/sdks/python/code_generation/fern/fern.config.json +++ b/sdks/python/code_generation/fern/fern.config.json @@ -1,4 +1,4 @@ { "organization": "Opik", - "version": "0.31.9" + "version": "0.45.0" } diff --git a/sdks/python/code_generation/fern/generators.yml b/sdks/python/code_generation/fern/generators.yml index 971a5b61df..2dc7bcb50b 100644 --- a/sdks/python/code_generation/fern/generators.yml +++ b/sdks/python/code_generation/fern/generators.yml @@ -1,9 +1,11 @@ +api: + path: openapi/openapi.yaml default-group: local groups: local: generators: - name: fernapi/fern-python-sdk - version: 2.14.1 + version: 4.3.8 output: location: local-file-system path: ../../src/opik/rest_api diff --git a/sdks/python/code_generation/fern/openapi/openapi.yaml b/sdks/python/code_generation/fern/openapi/openapi.yaml index 9dad4a237a..df4e9834c0 100644 --- a/sdks/python/code_generation/fern/openapi/openapi.yaml +++ b/sdks/python/code_generation/fern/openapi/openapi.yaml @@ -43,8 +43,6 @@ tags: description: Experiment resources - name: Feedback-definitions description: Feedback definitions related resources -- name: Feedback-scores - description: Feedback scores related resources - name: Projects description: Project related resources - name: Prompts @@ -541,6 +539,30 @@ paths: responses: "204": description: No content + /v1/private/experiments/feedback-scores/names: + get: + tags: + - Experiments + summary: Find Feedback Score names + description: Find Feedback Score names + operationId: findFeedbackScoreNames + parameters: + - name: experiment_ids + in: query + schema: + type: array + items: + type: string + format: uuid + responses: + "200": + description: Feedback Scores resource + content: + application/json: + schema: + type: array + items: + type: string /v1/private/experiments/{id}: get: tags: @@ -739,32 +761,6 @@ paths: responses: "204": description: No Content - /v1/private/feedback-scores/names: - get: - tags: - - Feedback-scores - summary: Find Feedback Score names - description: Find Feedback Score names - operationId: findFeedbackScoreNames - parameters: - - name: project_id - in: query - schema: - type: string - format: uuid - - name: with_experiments_only - in: query - schema: - type: boolean - responses: - "200": - description: Feedback Scores resource - content: - application/json: - schema: - type: array - items: - type: string /v1/private/projects: get: tags: @@ -1490,6 +1486,36 @@ paths: responses: "204": description: No Content + /v1/private/spans/feedback-scores/names: + get: + tags: + - Spans + summary: Find Feedback Score names + description: Find Feedback Score names + operationId: findFeedbackScoreNames_1 + parameters: + - name: project_id + in: query + schema: + type: string + format: uuid + - name: type + in: query + schema: + type: string + enum: + - general + - tool + - llm + responses: + "200": + description: Feedback Scores resource + content: + application/json: + schema: + type: array + items: + type: string /v1/private/spans/feedback-scores: put: tags: @@ -1704,6 +1730,28 @@ paths: responses: "204": description: No Content + /v1/private/traces/feedback-scores/names: + get: + tags: + - Traces + summary: Find Feedback Score names + description: Find Feedback Score names + operationId: findFeedbackScoreNames_2 + parameters: + - name: project_id + in: query + schema: + type: string + format: uuid + responses: + "200": + description: Feedback Scores resource + content: + application/json: + schema: + type: array + items: + type: string /v1/private/traces/feedback-scores: put: tags: diff --git a/sdks/python/src/opik/rest_api/__init__.py b/sdks/python/src/opik/rest_api/__init__.py index f80f0b5f6c..d038330153 100644 --- a/sdks/python/src/opik/rest_api/__init__.py +++ b/sdks/python/src/opik/rest_api/__init__.py @@ -126,22 +126,23 @@ datasets, experiments, feedback_definitions, - feedback_scores, projects, prompts, spans, system_usage, traces, ) +from .client import AsyncOpikApi, OpikApi from .environment import OpikApiEnvironment from .feedback_definitions import FindFeedbackDefinitionsRequestType from .projects import ( ProjectMetricRequestPublicInterval, ProjectMetricRequestPublicMetricType, ) -from .spans import GetSpansByProjectRequestType +from .spans import FindFeedbackScoreNames1RequestType, GetSpansByProjectRequestType __all__ = [ + "AsyncOpikApi", "BadRequestError", "BiInformation", "BiInformationResponse", @@ -213,6 +214,7 @@ "Feedback_Categorical", "Feedback_Numerical", "FindFeedbackDefinitionsRequestType", + "FindFeedbackScoreNames1RequestType", "GetSpansByProjectRequestType", "JsonNode", "JsonNodeCompare", @@ -228,6 +230,7 @@ "NumericalFeedbackDetailCreate", "NumericalFeedbackDetailPublic", "NumericalFeedbackDetailUpdate", + "OpikApi", "OpikApiEnvironment", "Project", "ProjectMetricRequestPublicInterval", @@ -268,7 +271,6 @@ "datasets", "experiments", "feedback_definitions", - "feedback_scores", "projects", "prompts", "spans", diff --git a/sdks/python/src/opik/rest_api/client.py b/sdks/python/src/opik/rest_api/client.py index 9599bc37ef..8fac0c48ae 100644 --- a/sdks/python/src/opik/rest_api/client.py +++ b/sdks/python/src/opik/rest_api/client.py @@ -1,27 +1,30 @@ # This file was auto-generated by Fern from our API Definition. import typing -from json.decoder import JSONDecodeError - +from .environment import OpikApiEnvironment import httpx - -from .core.api_error import ApiError -from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from .core.pydantic_utilities import pydantic_v1 +from .core.client_wrapper import SyncClientWrapper +from .system_usage.client import SystemUsageClient +from .datasets.client import DatasetsClient +from .experiments.client import ExperimentsClient +from .feedback_definitions.client import FeedbackDefinitionsClient +from .projects.client import ProjectsClient +from .prompts.client import PromptsClient +from .spans.client import SpansClient +from .traces.client import TracesClient from .core.request_options import RequestOptions -from .datasets.client import AsyncDatasetsClient, DatasetsClient -from .environment import OpikApiEnvironment -from .experiments.client import AsyncExperimentsClient, ExperimentsClient -from .feedback_definitions.client import ( - AsyncFeedbackDefinitionsClient, - FeedbackDefinitionsClient, -) -from .feedback_scores.client import AsyncFeedbackScoresClient, FeedbackScoresClient -from .projects.client import AsyncProjectsClient, ProjectsClient -from .prompts.client import AsyncPromptsClient, PromptsClient -from .spans.client import AsyncSpansClient, SpansClient -from .system_usage.client import AsyncSystemUsageClient, SystemUsageClient -from .traces.client import AsyncTracesClient, TracesClient +from .core.pydantic_utilities import parse_obj_as +from json.decoder import JSONDecodeError +from .core.api_error import ApiError +from .core.client_wrapper import AsyncClientWrapper +from .system_usage.client import AsyncSystemUsageClient +from .datasets.client import AsyncDatasetsClient +from .experiments.client import AsyncExperimentsClient +from .feedback_definitions.client import AsyncFeedbackDefinitionsClient +from .projects.client import AsyncProjectsClient +from .prompts.client import AsyncPromptsClient +from .spans.client import AsyncSpansClient +from .traces.client import AsyncTracesClient class OpikApi: @@ -53,7 +56,7 @@ class OpikApi: Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() """ @@ -87,7 +90,6 @@ def __init__( self.feedback_definitions = FeedbackDefinitionsClient( client_wrapper=self._client_wrapper ) - self.feedback_scores = FeedbackScoresClient(client_wrapper=self._client_wrapper) self.projects = ProjectsClient(client_wrapper=self._client_wrapper) self.prompts = PromptsClient(client_wrapper=self._client_wrapper) self.spans = SpansClient(client_wrapper=self._client_wrapper) @@ -95,7 +97,7 @@ def __init__( def is_alive( self, *, request_options: typing.Optional[RequestOptions] = None - ) -> typing.Any: + ) -> typing.Optional[typing.Any]: """ Parameters ---------- @@ -104,22 +106,30 @@ def is_alive( Returns ------- - typing.Any + typing.Optional[typing.Any] default response Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.is_alive() """ _response = self._client_wrapper.httpx_client.request( - "is-alive/ping", method="GET", request_options=request_options + "is-alive/ping", + method="GET", + request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore + return typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -127,7 +137,7 @@ def is_alive( def version( self, *, request_options: typing.Optional[RequestOptions] = None - ) -> typing.Any: + ) -> typing.Optional[typing.Any]: """ Parameters ---------- @@ -136,22 +146,30 @@ def version( Returns ------- - typing.Any + typing.Optional[typing.Any] default response Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.version() """ _response = self._client_wrapper.httpx_client.request( - "is-alive/ver", method="GET", request_options=request_options + "is-alive/ver", + method="GET", + request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore + return typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -187,7 +205,7 @@ class AsyncOpikApi: Examples -------- - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() """ @@ -221,9 +239,6 @@ def __init__( self.feedback_definitions = AsyncFeedbackDefinitionsClient( client_wrapper=self._client_wrapper ) - self.feedback_scores = AsyncFeedbackScoresClient( - client_wrapper=self._client_wrapper - ) self.projects = AsyncProjectsClient(client_wrapper=self._client_wrapper) self.prompts = AsyncPromptsClient(client_wrapper=self._client_wrapper) self.spans = AsyncSpansClient(client_wrapper=self._client_wrapper) @@ -231,7 +246,7 @@ def __init__( async def is_alive( self, *, request_options: typing.Optional[RequestOptions] = None - ) -> typing.Any: + ) -> typing.Optional[typing.Any]: """ Parameters ---------- @@ -240,14 +255,14 @@ async def is_alive( Returns ------- - typing.Any + typing.Optional[typing.Any] default response Examples -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -259,11 +274,19 @@ async def main() -> None: asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( - "is-alive/ping", method="GET", request_options=request_options + "is-alive/ping", + method="GET", + request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore + return typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -271,7 +294,7 @@ async def main() -> None: async def version( self, *, request_options: typing.Optional[RequestOptions] = None - ) -> typing.Any: + ) -> typing.Optional[typing.Any]: """ Parameters ---------- @@ -280,14 +303,14 @@ async def version( Returns ------- - typing.Any + typing.Optional[typing.Any] default response Examples -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -299,11 +322,19 @@ async def main() -> None: asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( - "is-alive/ver", method="GET", request_options=request_options + "is-alive/ver", + method="GET", + request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.Any, _response.json()) # type: ignore + return typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/sdks/python/src/opik/rest_api/core/__init__.py b/sdks/python/src/opik/rest_api/core/__init__.py index 58ad52ad2e..f03aecbfe1 100644 --- a/sdks/python/src/opik/rest_api/core/__init__.py +++ b/sdks/python/src/opik/rest_api/core/__init__.py @@ -3,28 +3,45 @@ from .api_error import ApiError from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper from .datetime_utils import serialize_datetime -from .file import File, convert_file_dict_to_httpx_tuples +from .file import File, convert_file_dict_to_httpx_tuples, with_content_type from .http_client import AsyncHttpClient, HttpClient from .jsonable_encoder import jsonable_encoder -from .pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .pydantic_utilities import ( + IS_PYDANTIC_V2, + UniversalBaseModel, + UniversalRootModel, + parse_obj_as, + universal_field_validator, + universal_root_validator, + update_forward_refs, +) from .query_encoder import encode_query from .remove_none_from_dict import remove_none_from_dict from .request_options import RequestOptions +from .serialization import FieldMetadata, convert_and_respect_annotation_metadata __all__ = [ "ApiError", "AsyncClientWrapper", "AsyncHttpClient", "BaseClientWrapper", + "FieldMetadata", "File", "HttpClient", + "IS_PYDANTIC_V2", "RequestOptions", "SyncClientWrapper", + "UniversalBaseModel", + "UniversalRootModel", + "convert_and_respect_annotation_metadata", "convert_file_dict_to_httpx_tuples", - "deep_union_pydantic_dicts", "encode_query", "jsonable_encoder", - "pydantic_v1", + "parse_obj_as", "remove_none_from_dict", "serialize_datetime", + "universal_field_validator", + "universal_root_validator", + "update_forward_refs", + "with_content_type", ] diff --git a/sdks/python/src/opik/rest_api/core/client_wrapper.py b/sdks/python/src/opik/rest_api/core/client_wrapper.py index 3b8b2bd60a..7d4639ba0a 100644 --- a/sdks/python/src/opik/rest_api/core/client_wrapper.py +++ b/sdks/python/src/opik/rest_api/core/client_wrapper.py @@ -1,10 +1,9 @@ # This file was auto-generated by Fern from our API Definition. import typing - import httpx - -from .http_client import AsyncHttpClient, HttpClient +from .http_client import HttpClient +from .http_client import AsyncHttpClient class BaseClientWrapper: @@ -13,7 +12,9 @@ def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None): self._timeout = timeout def get_headers(self) -> typing.Dict[str, str]: - headers: typing.Dict[str, str] = {"X-Fern-Language": "Python"} + headers: typing.Dict[str, str] = { + "X-Fern-Language": "Python", + } return headers def get_base_url(self) -> str: @@ -34,9 +35,9 @@ def __init__( super().__init__(base_url=base_url, timeout=timeout) self.httpx_client = HttpClient( httpx_client=httpx_client, - base_headers=self.get_headers(), - base_timeout=self.get_timeout(), - base_url=self.get_base_url(), + base_headers=self.get_headers, + base_timeout=self.get_timeout, + base_url=self.get_base_url, ) @@ -51,7 +52,7 @@ def __init__( super().__init__(base_url=base_url, timeout=timeout) self.httpx_client = AsyncHttpClient( httpx_client=httpx_client, - base_headers=self.get_headers(), - base_timeout=self.get_timeout(), - base_url=self.get_base_url(), + base_headers=self.get_headers, + base_timeout=self.get_timeout, + base_url=self.get_base_url, ) diff --git a/sdks/python/src/opik/rest_api/core/file.py b/sdks/python/src/opik/rest_api/core/file.py index 6e0f92bfcb..3467175cb7 100644 --- a/sdks/python/src/opik/rest_api/core/file.py +++ b/sdks/python/src/opik/rest_api/core/file.py @@ -1,30 +1,30 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from typing import IO, Dict, List, Mapping, Optional, Tuple, Union, cast # File typing inspired by the flexibility of types within the httpx library # https://github.com/encode/httpx/blob/master/httpx/_types.py -FileContent = typing.Union[typing.IO[bytes], bytes, str] -File = typing.Union[ +FileContent = Union[IO[bytes], bytes, str] +File = Union[ # file (or bytes) FileContent, # (filename, file (or bytes)) - typing.Tuple[typing.Optional[str], FileContent], + Tuple[Optional[str], FileContent], # (filename, file (or bytes), content_type) - typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str]], + Tuple[Optional[str], FileContent, Optional[str]], # (filename, file (or bytes), content_type, headers) - typing.Tuple[ - typing.Optional[str], + Tuple[ + Optional[str], FileContent, - typing.Optional[str], - typing.Mapping[str, str], + Optional[str], + Mapping[str, str], ], ] def convert_file_dict_to_httpx_tuples( - d: typing.Dict[str, typing.Union[File, typing.List[File]]], -) -> typing.List[typing.Tuple[str, File]]: + d: Dict[str, Union[File, List[File]]], +) -> List[Tuple[str, File]]: """ The format we use is a list of tuples, where the first element is the name of the file and the second is the file object. Typically HTTPX wants @@ -41,3 +41,30 @@ def convert_file_dict_to_httpx_tuples( else: httpx_tuples.append((key, file_like)) return httpx_tuples + + +def with_content_type(*, file: File, default_content_type: str) -> File: + """ + This function resolves to the file's content type, if provided, and defaults + to the default_content_type value if not. + """ + if isinstance(file, tuple): + if len(file) == 2: + filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore + return (filename, content, default_content_type) + elif len(file) == 3: + filename, content, file_content_type = cast( + Tuple[Optional[str], FileContent, Optional[str]], file + ) # type: ignore + out_content_type = file_content_type or default_content_type + return (filename, content, out_content_type) + elif len(file) == 4: + filename, content, file_content_type, headers = cast( # type: ignore + Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], + file, + ) + out_content_type = file_content_type or default_content_type + return (filename, content, out_content_type, headers) + else: + raise ValueError(f"Unexpected tuple length: {len(file)}") + return (None, file, default_content_type) diff --git a/sdks/python/src/opik/rest_api/core/http_client.py b/sdks/python/src/opik/rest_api/core/http_client.py index dce2021917..c9f1d7a59b 100644 --- a/sdks/python/src/opik/rest_api/core/http_client.py +++ b/sdks/python/src/opik/rest_api/core/http_client.py @@ -2,6 +2,7 @@ import asyncio import email.utils +import json import re import time import typing @@ -111,6 +112,7 @@ def maybe_filter_request_body( if data is None: return ( jsonable_encoder(request_options.get("additional_body_parameters", {})) + or {} if request_options is not None else None ) @@ -121,6 +123,7 @@ def maybe_filter_request_body( **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore **( jsonable_encoder(request_options.get("additional_body_parameters", {})) + or {} if request_options is not None else {} ), @@ -144,7 +147,10 @@ def get_request_body( # If both data and json are None, we send json data in the event extra properties are specified json_body = maybe_filter_request_body(json, request_options, omit) - return json_body, data_body + # If you have an empty JSON body, you should just send None + return ( + json_body if json_body != {} else None + ), data_body if data_body != {} else None class HttpClient: @@ -152,9 +158,9 @@ def __init__( self, *, httpx_client: httpx.Client, - base_timeout: typing.Optional[float], - base_headers: typing.Dict[str, str], - base_url: typing.Optional[str] = None, + base_timeout: typing.Callable[[], typing.Optional[float]], + base_headers: typing.Callable[[], typing.Dict[str, str]], + base_url: typing.Optional[typing.Callable[[], str]] = None, ): self.base_url = base_url self.base_timeout = base_timeout @@ -162,7 +168,10 @@ def __init__( self.httpx_client = httpx_client def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: - base_url = self.base_url if maybe_base_url is None else maybe_base_url + base_url = maybe_base_url + if self.base_url is not None and base_url is None: + base_url = self.base_url() + if base_url is None: raise ValueError( "A base_url is required to make this request, please provide one and try again." @@ -194,7 +203,7 @@ def request( request_options.get("timeout_in_seconds") if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self.base_timeout + else self.base_timeout() ) json_body, data_body = get_request_body( @@ -207,10 +216,10 @@ def request( headers=jsonable_encoder( remove_none_from_dict( { - **self.base_headers, + **self.base_headers(), **(headers if headers is not None else {}), **( - request_options.get("additional_headers", {}) + request_options.get("additional_headers", {}) or {} if request_options is not None else {} ), @@ -227,6 +236,7 @@ def request( request_options.get( "additional_query_parameters", {} ) + or {} if request_options is not None else {} ), @@ -239,9 +249,13 @@ def request( json=json_body, data=data_body, content=content, - files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) - if files is not None - else None, + files=( + convert_file_dict_to_httpx_tuples( + remove_omit_from_dict(remove_none_from_dict(files), omit) + ) + if (files is not None and files is not omit) + else None + ), timeout=timeout, ) @@ -293,7 +307,7 @@ def stream( request_options.get("timeout_in_seconds") if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self.base_timeout + else self.base_timeout() ) json_body, data_body = get_request_body( @@ -306,7 +320,7 @@ def stream( headers=jsonable_encoder( remove_none_from_dict( { - **self.base_headers, + **self.base_headers(), **(headers if headers is not None else {}), **( request_options.get("additional_headers", {}) @@ -338,9 +352,13 @@ def stream( json=json_body, data=data_body, content=content, - files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) - if files is not None - else None, + files=( + convert_file_dict_to_httpx_tuples( + remove_omit_from_dict(remove_none_from_dict(files), omit) + ) + if (files is not None and files is not omit) + else None + ), timeout=timeout, ) as stream: yield stream @@ -351,9 +369,9 @@ def __init__( self, *, httpx_client: httpx.AsyncClient, - base_timeout: typing.Optional[float], - base_headers: typing.Dict[str, str], - base_url: typing.Optional[str] = None, + base_timeout: typing.Callable[[], typing.Optional[float]], + base_headers: typing.Callable[[], typing.Dict[str, str]], + base_url: typing.Optional[typing.Callable[[], str]] = None, ): self.base_url = base_url self.base_timeout = base_timeout @@ -361,7 +379,10 @@ def __init__( self.httpx_client = httpx_client def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: - base_url = self.base_url if maybe_base_url is None else maybe_base_url + base_url = maybe_base_url + if self.base_url is not None and base_url is None: + base_url = self.base_url() + if base_url is None: raise ValueError( "A base_url is required to make this request, please provide one and try again." @@ -393,7 +414,7 @@ async def request( request_options.get("timeout_in_seconds") if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self.base_timeout + else self.base_timeout() ) json_body, data_body = get_request_body( @@ -407,10 +428,10 @@ async def request( headers=jsonable_encoder( remove_none_from_dict( { - **self.base_headers, + **self.base_headers(), **(headers if headers is not None else {}), **( - request_options.get("additional_headers", {}) + request_options.get("additional_headers", {}) or {} if request_options is not None else {} ), @@ -427,6 +448,7 @@ async def request( request_options.get( "additional_query_parameters", {} ) + or {} if request_options is not None else {} ), @@ -439,9 +461,13 @@ async def request( json=json_body, data=data_body, content=content, - files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) - if files is not None - else None, + files=( + convert_file_dict_to_httpx_tuples( + remove_omit_from_dict(remove_none_from_dict(files), omit) + ) + if files is not None + else None + ), timeout=timeout, ) @@ -492,7 +518,7 @@ async def stream( request_options.get("timeout_in_seconds") if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self.base_timeout + else self.base_timeout() ) json_body, data_body = get_request_body( @@ -505,7 +531,7 @@ async def stream( headers=jsonable_encoder( remove_none_from_dict( { - **self.base_headers, + **self.base_headers(), **(headers if headers is not None else {}), **( request_options.get("additional_headers", {}) @@ -537,9 +563,13 @@ async def stream( json=json_body, data=data_body, content=content, - files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) - if files is not None - else None, + files=( + convert_file_dict_to_httpx_tuples( + remove_omit_from_dict(remove_none_from_dict(files), omit) + ) + if files is not None + else None + ), timeout=timeout, ) as stream: yield stream diff --git a/sdks/python/src/opik/rest_api/core/jsonable_encoder.py b/sdks/python/src/opik/rest_api/core/jsonable_encoder.py index a4a3473ed1..12a8b52fc2 100644 --- a/sdks/python/src/opik/rest_api/core/jsonable_encoder.py +++ b/sdks/python/src/opik/rest_api/core/jsonable_encoder.py @@ -8,37 +8,27 @@ https://github.com/tiangolo/fastapi/blob/master/fastapi/encoders.py """ +import base64 import dataclasses import datetime as dt -from collections import defaultdict from enum import Enum from pathlib import PurePath from types import GeneratorType -from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Set, Union + +import pydantic from .datetime_utils import serialize_datetime -from .pydantic_utilities import pydantic_v1 +from .pydantic_utilities import ( + IS_PYDANTIC_V2, + encode_by_type, + to_jsonable_with_fallback, +) SetIntStr = Set[Union[int, str]] DictIntStrAny = Dict[Union[int, str], Any] -def generate_encoders_by_class_tuples( - type_encoder_map: Dict[Any, Callable[[Any], Any]], -) -> Dict[Callable[[Any], Any], Tuple[Any, ...]]: - encoders_by_class_tuples: Dict[Callable[[Any], Any], Tuple[Any, ...]] = defaultdict( - tuple - ) - for type_, encoder in type_encoder_map.items(): - encoders_by_class_tuples[encoder] += (type_,) - return encoders_by_class_tuples - - -encoders_by_class_tuples = generate_encoders_by_class_tuples( - pydantic_v1.json.ENCODERS_BY_TYPE -) - - def jsonable_encoder( obj: Any, custom_encoder: Optional[Dict[Any, Callable[[Any], Any]]] = None ) -> Any: @@ -50,17 +40,24 @@ def jsonable_encoder( for encoder_type, encoder_instance in custom_encoder.items(): if isinstance(obj, encoder_type): return encoder_instance(obj) - if isinstance(obj, pydantic_v1.BaseModel): - encoder = getattr(obj.__config__, "json_encoders", {}) + if isinstance(obj, pydantic.BaseModel): + if IS_PYDANTIC_V2: + encoder = getattr(obj.model_config, "json_encoders", {}) # type: ignore # Pydantic v2 + else: + encoder = getattr(obj.__config__, "json_encoders", {}) # type: ignore # Pydantic v1 if custom_encoder: encoder.update(custom_encoder) obj_dict = obj.dict(by_alias=True) if "__root__" in obj_dict: obj_dict = obj_dict["__root__"] + if "root" in obj_dict: + obj_dict = obj_dict["root"] return jsonable_encoder(obj_dict, custom_encoder=encoder) if dataclasses.is_dataclass(obj): - obj_dict = dataclasses.asdict(obj) + obj_dict = dataclasses.asdict(obj) # type: ignore return jsonable_encoder(obj_dict, custom_encoder=custom_encoder) + if isinstance(obj, bytes): + return base64.b64encode(obj).decode("utf-8") if isinstance(obj, Enum): return obj.value if isinstance(obj, PurePath): @@ -86,20 +83,21 @@ def jsonable_encoder( encoded_list.append(jsonable_encoder(item, custom_encoder=custom_encoder)) return encoded_list - if type(obj) in pydantic_v1.json.ENCODERS_BY_TYPE: - return pydantic_v1.json.ENCODERS_BY_TYPE[type(obj)](obj) - for encoder, classes_tuple in encoders_by_class_tuples.items(): - if isinstance(obj, classes_tuple): - return encoder(obj) + def fallback_serializer(o: Any) -> Any: + attempt_encode = encode_by_type(o) + if attempt_encode is not None: + return attempt_encode - try: - data = dict(obj) - except Exception as e: - errors: List[Exception] = [] - errors.append(e) try: - data = vars(obj) + data = dict(o) except Exception as e: + errors: List[Exception] = [] errors.append(e) - raise ValueError(errors) from e - return jsonable_encoder(data, custom_encoder=custom_encoder) + try: + data = vars(o) + except Exception as e: + errors.append(e) + raise ValueError(errors) from e + return jsonable_encoder(data, custom_encoder=custom_encoder) + + return to_jsonable_with_fallback(obj, fallback_serializer) diff --git a/sdks/python/src/opik/rest_api/core/pydantic_utilities.py b/sdks/python/src/opik/rest_api/core/pydantic_utilities.py index a72c1a52f1..dd74023c63 100644 --- a/sdks/python/src/opik/rest_api/core/pydantic_utilities.py +++ b/sdks/python/src/opik/rest_api/core/pydantic_utilities.py @@ -1,28 +1,323 @@ # This file was auto-generated by Fern from our API Definition. +# nopycln: file +import datetime as dt import typing +from collections import defaultdict + +import typing_extensions import pydantic +from .datetime_utils import serialize_datetime +from .serialization import convert_and_respect_annotation_metadata + IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.") if IS_PYDANTIC_V2: - import pydantic.v1 as pydantic_v1 # type: ignore # nopycln: import + # isort will try to reformat the comments on these imports, which breaks mypy + # isort: off + from pydantic.v1.datetime_parse import ( # type: ignore # pyright: ignore[reportMissingImports] # Pydantic v2 + parse_date as parse_date, + ) + from pydantic.v1.datetime_parse import ( # pyright: ignore[reportMissingImports] # Pydantic v2 + parse_datetime as parse_datetime, + ) + from pydantic.v1.json import ( # type: ignore # pyright: ignore[reportMissingImports] # Pydantic v2 + ENCODERS_BY_TYPE as encoders_by_type, + ) + from pydantic.v1.typing import ( # type: ignore # pyright: ignore[reportMissingImports] # Pydantic v2 + get_args as get_args, + ) + from pydantic.v1.typing import ( # pyright: ignore[reportMissingImports] # Pydantic v2 + get_origin as get_origin, + ) + from pydantic.v1.typing import ( # pyright: ignore[reportMissingImports] # Pydantic v2 + is_literal_type as is_literal_type, + ) + from pydantic.v1.typing import ( # pyright: ignore[reportMissingImports] # Pydantic v2 + is_union as is_union, + ) + from pydantic.v1.fields import ModelField as ModelField # type: ignore # pyright: ignore[reportMissingImports] # Pydantic v2 else: - import pydantic as pydantic_v1 # type: ignore # nopycln: import + from pydantic.datetime_parse import parse_date as parse_date # type: ignore # Pydantic v1 + from pydantic.datetime_parse import parse_datetime as parse_datetime # type: ignore # Pydantic v1 + from pydantic.fields import ModelField as ModelField # type: ignore # Pydantic v1 + from pydantic.json import ENCODERS_BY_TYPE as encoders_by_type # type: ignore # Pydantic v1 + from pydantic.typing import get_args as get_args # type: ignore # Pydantic v1 + from pydantic.typing import get_origin as get_origin # type: ignore # Pydantic v1 + from pydantic.typing import is_literal_type as is_literal_type # type: ignore # Pydantic v1 + from pydantic.typing import is_union as is_union # type: ignore # Pydantic v1 + + # isort: on + + +T = typing.TypeVar("T") +Model = typing.TypeVar("Model", bound=pydantic.BaseModel) + + +def parse_obj_as(type_: typing.Type[T], object_: typing.Any) -> T: + dealiased_object = convert_and_respect_annotation_metadata( + object_=object_, annotation=type_, direction="read" + ) + if IS_PYDANTIC_V2: + adapter = pydantic.TypeAdapter(type_) # type: ignore # Pydantic v2 + return adapter.validate_python(dealiased_object) + else: + return pydantic.parse_obj_as(type_, dealiased_object) + + +def to_jsonable_with_fallback( + obj: typing.Any, fallback_serializer: typing.Callable[[typing.Any], typing.Any] +) -> typing.Any: + if IS_PYDANTIC_V2: + from pydantic_core import to_jsonable_python + + return to_jsonable_python(obj, fallback=fallback_serializer) + else: + return fallback_serializer(obj) + + +class UniversalBaseModel(pydantic.BaseModel): + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + # Allow fields begining with `model_` to be used in the model + protected_namespaces=(), + ) # type: ignore # Pydantic v2 + + @pydantic.model_serializer(mode="wrap", when_used="json") # type: ignore # Pydantic v2 + def serialize_model( + self, handler: pydantic.SerializerFunctionWrapHandler + ) -> typing.Any: # type: ignore # Pydantic v2 + serialized = handler(self) + data = { + k: serialize_datetime(v) if isinstance(v, dt.datetime) else v + for k, v in serialized.items() + } + return data + + else: + + class Config: + smart_union = True + json_encoders = {dt.datetime: serialize_datetime} + + @classmethod + def model_construct( + cls: typing.Type["Model"], + _fields_set: typing.Optional[typing.Set[str]] = None, + **values: typing.Any, + ) -> "Model": + dealiased_object = convert_and_respect_annotation_metadata( + object_=values, annotation=cls, direction="read" + ) + return cls.construct(_fields_set, **dealiased_object) + + @classmethod + def construct( + cls: typing.Type["Model"], + _fields_set: typing.Optional[typing.Set[str]] = None, + **values: typing.Any, + ) -> "Model": + dealiased_object = convert_and_respect_annotation_metadata( + object_=values, annotation=cls, direction="read" + ) + if IS_PYDANTIC_V2: + return super().model_construct(_fields_set, **dealiased_object) # type: ignore # Pydantic v2 + else: + return super().construct(_fields_set, **dealiased_object) + + def json(self, **kwargs: typing.Any) -> str: + kwargs_with_defaults: typing.Any = { + "by_alias": True, + "exclude_unset": True, + **kwargs, + } + if IS_PYDANTIC_V2: + return super().model_dump_json(**kwargs_with_defaults) # type: ignore # Pydantic v2 + else: + return super().json(**kwargs_with_defaults) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + """ + Override the default dict method to `exclude_unset` by default. This function patches + `exclude_unset` to work include fields within non-None default values. + """ + # Note: the logic here is multi-plexed given the levers exposed in Pydantic V1 vs V2 + # Pydantic V1's .dict can be extremely slow, so we do not want to call it twice. + # + # We'd ideally do the same for Pydantic V2, but it shells out to a library to serialize models + # that we have less control over, and this is less intrusive than custom serializers for now. + if IS_PYDANTIC_V2: + kwargs_with_defaults_exclude_unset: typing.Any = { + **kwargs, + "by_alias": True, + "exclude_unset": True, + "exclude_none": False, + } + kwargs_with_defaults_exclude_none: typing.Any = { + **kwargs, + "by_alias": True, + "exclude_none": True, + "exclude_unset": False, + } + dict_dump = deep_union_pydantic_dicts( + super().model_dump(**kwargs_with_defaults_exclude_unset), # type: ignore # Pydantic v2 + super().model_dump(**kwargs_with_defaults_exclude_none), # type: ignore # Pydantic v2 + ) + + else: + _fields_set = self.__fields_set__.copy() + + fields = _get_model_fields(self.__class__) + for name, field in fields.items(): + if name not in _fields_set: + default = _get_field_default(field) + + # If the default values are non-null act like they've been set + # This effectively allows exclude_unset to work like exclude_none where + # the latter passes through intentionally set none values. + if default is not None or ( + "exclude_unset" in kwargs and not kwargs["exclude_unset"] + ): + _fields_set.add(name) + + if default is not None: + self.__fields_set__.add(name) + + kwargs_with_defaults_exclude_unset_include_fields: typing.Any = { + "by_alias": True, + "exclude_unset": True, + "include": _fields_set, + **kwargs, + } + + dict_dump = super().dict( + **kwargs_with_defaults_exclude_unset_include_fields + ) + + return convert_and_respect_annotation_metadata( + object_=dict_dump, annotation=self.__class__, direction="write" + ) + + +def _union_list_of_pydantic_dicts( + source: typing.List[typing.Any], destination: typing.List[typing.Any] +) -> typing.List[typing.Any]: + converted_list: typing.List[typing.Any] = [] + for i, item in enumerate(source): + destination_value = destination[i] # type: ignore + if isinstance(item, dict): + converted_list.append(deep_union_pydantic_dicts(item, destination_value)) + elif isinstance(item, list): + converted_list.append( + _union_list_of_pydantic_dicts(item, destination_value) + ) + else: + converted_list.append(item) + return converted_list def deep_union_pydantic_dicts( source: typing.Dict[str, typing.Any], destination: typing.Dict[str, typing.Any] ) -> typing.Dict[str, typing.Any]: for key, value in source.items(): + node = destination.setdefault(key, {}) if isinstance(value, dict): - node = destination.setdefault(key, {}) deep_union_pydantic_dicts(value, node) + # Note: we do not do this same processing for sets given we do not have sets of models + # and given the sets are unordered, the processing of the set and matching objects would + # be non-trivial. + elif isinstance(value, list): + destination[key] = _union_list_of_pydantic_dicts(value, node) else: destination[key] = value return destination -__all__ = ["pydantic_v1"] +if IS_PYDANTIC_V2: + + class V2RootModel(UniversalBaseModel, pydantic.RootModel): # type: ignore # Pydantic v2 + pass + + UniversalRootModel: typing_extensions.TypeAlias = V2RootModel # type: ignore +else: + UniversalRootModel: typing_extensions.TypeAlias = UniversalBaseModel # type: ignore + + +def encode_by_type(o: typing.Any) -> typing.Any: + encoders_by_class_tuples: typing.Dict[ + typing.Callable[[typing.Any], typing.Any], typing.Tuple[typing.Any, ...] + ] = defaultdict(tuple) + for type_, encoder in encoders_by_type.items(): + encoders_by_class_tuples[encoder] += (type_,) + + if type(o) in encoders_by_type: + return encoders_by_type[type(o)](o) + for encoder, classes_tuple in encoders_by_class_tuples.items(): + if isinstance(o, classes_tuple): + return encoder(o) + + +def update_forward_refs(model: typing.Type["Model"], **localns: typing.Any) -> None: + if IS_PYDANTIC_V2: + model.model_rebuild(raise_errors=False) # type: ignore # Pydantic v2 + else: + model.update_forward_refs(**localns) + + +# Mirrors Pydantic's internal typing +AnyCallable = typing.Callable[..., typing.Any] + + +def universal_root_validator( + pre: bool = False, +) -> typing.Callable[[AnyCallable], AnyCallable]: + def decorator(func: AnyCallable) -> AnyCallable: + if IS_PYDANTIC_V2: + return pydantic.model_validator(mode="before" if pre else "after")(func) # type: ignore # Pydantic v2 + else: + return pydantic.root_validator(pre=pre)(func) # type: ignore # Pydantic v1 + + return decorator + + +def universal_field_validator( + field_name: str, pre: bool = False +) -> typing.Callable[[AnyCallable], AnyCallable]: + def decorator(func: AnyCallable) -> AnyCallable: + if IS_PYDANTIC_V2: + return pydantic.field_validator( + field_name, mode="before" if pre else "after" + )(func) # type: ignore # Pydantic v2 + else: + return pydantic.validator(field_name, pre=pre)(func) # type: ignore # Pydantic v1 + + return decorator + + +PydanticField = typing.Union[ModelField, pydantic.fields.FieldInfo] + + +def _get_model_fields( + model: typing.Type["Model"], +) -> typing.Mapping[str, PydanticField]: + if IS_PYDANTIC_V2: + return model.model_fields # type: ignore # Pydantic v2 + else: + return model.__fields__ # type: ignore # Pydantic v1 + + +def _get_field_default(field: PydanticField) -> typing.Any: + try: + value = field.get_default() # type: ignore # Pydantic < v1.10.15 + except: + value = field.default + if IS_PYDANTIC_V2: + from pydantic_core import PydanticUndefined + + if value == PydanticUndefined: + return None + return value + return value diff --git a/sdks/python/src/opik/rest_api/core/query_encoder.py b/sdks/python/src/opik/rest_api/core/query_encoder.py index 069633086a..03fbf59bd1 100644 --- a/sdks/python/src/opik/rest_api/core/query_encoder.py +++ b/sdks/python/src/opik/rest_api/core/query_encoder.py @@ -1,39 +1,60 @@ # This file was auto-generated by Fern from our API Definition. -from collections import ChainMap -from typing import Any, Dict, Optional +from typing import Any, Dict, List, Optional, Tuple -from .pydantic_utilities import pydantic_v1 +import pydantic # Flattens dicts to be of the form {"key[subkey][subkey2]": value} where value is not a dict def traverse_query_dict( dict_flat: Dict[str, Any], key_prefix: Optional[str] = None -) -> Dict[str, Any]: - result = {} +) -> List[Tuple[str, Any]]: + result = [] for k, v in dict_flat.items(): key = f"{key_prefix}[{k}]" if key_prefix is not None else k if isinstance(v, dict): - result.update(traverse_query_dict(v, key)) + result.extend(traverse_query_dict(v, key)) + elif isinstance(v, list): + for arr_v in v: + if isinstance(arr_v, dict): + result.extend(traverse_query_dict(arr_v, key)) + else: + result.append((key, arr_v)) else: - result[key] = v + result.append((key, v)) return result -def single_query_encoder(query_key: str, query_value: Any) -> Dict[str, Any]: - if isinstance(query_value, pydantic_v1.BaseModel) or isinstance(query_value, dict): - if isinstance(query_value, pydantic_v1.BaseModel): +def single_query_encoder(query_key: str, query_value: Any) -> List[Tuple[str, Any]]: + if isinstance(query_value, pydantic.BaseModel) or isinstance(query_value, dict): + if isinstance(query_value, pydantic.BaseModel): obj_dict = query_value.dict(by_alias=True) else: obj_dict = query_value return traverse_query_dict(obj_dict, query_key) + elif isinstance(query_value, list): + encoded_values: List[Tuple[str, Any]] = [] + for value in query_value: + if isinstance(value, pydantic.BaseModel) or isinstance(value, dict): + if isinstance(value, pydantic.BaseModel): + obj_dict = value.dict(by_alias=True) + elif isinstance(value, dict): + obj_dict = value - return {query_key: query_value} + encoded_values.extend(single_query_encoder(query_key, obj_dict)) + else: + encoded_values.append((query_key, value)) + return encoded_values -def encode_query(query: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]: - return ( - dict(ChainMap(*[single_query_encoder(k, v) for k, v in query.items()])) - if query is not None - else None - ) + return [(query_key, query_value)] + + +def encode_query(query: Optional[Dict[str, Any]]) -> Optional[List[Tuple[str, Any]]]: + if query is None: + return None + + encoded_query = [] + for k, v in query.items(): + encoded_query.extend(single_query_encoder(k, v)) + return encoded_query diff --git a/sdks/python/src/opik/rest_api/core/request_options.py b/sdks/python/src/opik/rest_api/core/request_options.py index d0bf0dbcec..1b38804432 100644 --- a/sdks/python/src/opik/rest_api/core/request_options.py +++ b/sdks/python/src/opik/rest_api/core/request_options.py @@ -23,6 +23,8 @@ class RequestOptions(typing.TypedDict, total=False): - additional_query_parameters: typing.Dict[str, typing.Any]. A dictionary containing additional parameters to spread into the request's query parameters dict - additional_body_parameters: typing.Dict[str, typing.Any]. A dictionary containing additional parameters to spread into the request's body parameters dict + + - chunk_size: int. The size, in bytes, to process each chunk of data being streamed back within the response. This equates to leveraging `chunk_size` within `requests` or `httpx`, and is only leveraged for file downloads. """ timeout_in_seconds: NotRequired[int] @@ -30,3 +32,4 @@ class RequestOptions(typing.TypedDict, total=False): additional_headers: NotRequired[typing.Dict[str, typing.Any]] additional_query_parameters: NotRequired[typing.Dict[str, typing.Any]] additional_body_parameters: NotRequired[typing.Dict[str, typing.Any]] + chunk_size: NotRequired[int] diff --git a/sdks/python/src/opik/rest_api/core/serialization.py b/sdks/python/src/opik/rest_api/core/serialization.py new file mode 100644 index 0000000000..5679deb8a5 --- /dev/null +++ b/sdks/python/src/opik/rest_api/core/serialization.py @@ -0,0 +1,276 @@ +# This file was auto-generated by Fern from our API Definition. + +import collections +import inspect +import typing + +import typing_extensions + +import pydantic + + +class FieldMetadata: + """ + Metadata class used to annotate fields to provide additional information. + + Example: + class MyDict(TypedDict): + field: typing.Annotated[str, FieldMetadata(alias="field_name")] + + Will serialize: `{"field": "value"}` + To: `{"field_name": "value"}` + """ + + alias: str + + def __init__(self, *, alias: str) -> None: + self.alias = alias + + +def convert_and_respect_annotation_metadata( + *, + object_: typing.Any, + annotation: typing.Any, + inner_type: typing.Optional[typing.Any] = None, + direction: typing.Literal["read", "write"], +) -> typing.Any: + """ + Respect the metadata annotations on a field, such as aliasing. This function effectively + manipulates the dict-form of an object to respect the metadata annotations. This is primarily used for + TypedDicts, which cannot support aliasing out of the box, and can be extended for additional + utilities, such as defaults. + + Parameters + ---------- + object_ : typing.Any + + annotation : type + The type we're looking to apply typing annotations from + + inner_type : typing.Optional[type] + + Returns + ------- + typing.Any + """ + + if object_ is None: + return None + if inner_type is None: + inner_type = annotation + + clean_type = _remove_annotations(inner_type) + # Pydantic models + if ( + inspect.isclass(clean_type) + and issubclass(clean_type, pydantic.BaseModel) + and isinstance(object_, typing.Mapping) + ): + return _convert_mapping(object_, clean_type, direction) + # TypedDicts + if typing_extensions.is_typeddict(clean_type) and isinstance( + object_, typing.Mapping + ): + return _convert_mapping(object_, clean_type, direction) + + if ( + typing_extensions.get_origin(clean_type) == typing.Dict + or typing_extensions.get_origin(clean_type) == dict + or clean_type == typing.Dict + ) and isinstance(object_, typing.Dict): + key_type = typing_extensions.get_args(clean_type)[0] + value_type = typing_extensions.get_args(clean_type)[1] + + return { + key: convert_and_respect_annotation_metadata( + object_=value, + annotation=annotation, + inner_type=value_type, + direction=direction, + ) + for key, value in object_.items() + } + + # If you're iterating on a string, do not bother to coerce it to a sequence. + if not isinstance(object_, str): + if ( + typing_extensions.get_origin(clean_type) == typing.Set + or typing_extensions.get_origin(clean_type) == set + or clean_type == typing.Set + ) and isinstance(object_, typing.Set): + inner_type = typing_extensions.get_args(clean_type)[0] + return { + convert_and_respect_annotation_metadata( + object_=item, + annotation=annotation, + inner_type=inner_type, + direction=direction, + ) + for item in object_ + } + elif ( + ( + typing_extensions.get_origin(clean_type) == typing.List + or typing_extensions.get_origin(clean_type) == list + or clean_type == typing.List + ) + and isinstance(object_, typing.List) + ) or ( + ( + typing_extensions.get_origin(clean_type) == typing.Sequence + or typing_extensions.get_origin(clean_type) == collections.abc.Sequence + or clean_type == typing.Sequence + ) + and isinstance(object_, typing.Sequence) + ): + inner_type = typing_extensions.get_args(clean_type)[0] + return [ + convert_and_respect_annotation_metadata( + object_=item, + annotation=annotation, + inner_type=inner_type, + direction=direction, + ) + for item in object_ + ] + + if typing_extensions.get_origin(clean_type) == typing.Union: + # We should be able to ~relatively~ safely try to convert keys against all + # member types in the union, the edge case here is if one member aliases a field + # of the same name to a different name from another member + # Or if another member aliases a field of the same name that another member does not. + for member in typing_extensions.get_args(clean_type): + object_ = convert_and_respect_annotation_metadata( + object_=object_, + annotation=annotation, + inner_type=member, + direction=direction, + ) + return object_ + + annotated_type = _get_annotation(annotation) + if annotated_type is None: + return object_ + + # If the object is not a TypedDict, a Union, or other container (list, set, sequence, etc.) + # Then we can safely call it on the recursive conversion. + return object_ + + +def _convert_mapping( + object_: typing.Mapping[str, object], + expected_type: typing.Any, + direction: typing.Literal["read", "write"], +) -> typing.Mapping[str, object]: + converted_object: typing.Dict[str, object] = {} + annotations = typing_extensions.get_type_hints(expected_type, include_extras=True) + aliases_to_field_names = _get_alias_to_field_name(annotations) + for key, value in object_.items(): + if direction == "read" and key in aliases_to_field_names: + dealiased_key = aliases_to_field_names.get(key) + if dealiased_key is not None: + type_ = annotations.get(dealiased_key) + else: + type_ = annotations.get(key) + # Note you can't get the annotation by the field name if you're in read mode, so you must check the aliases map + # + # So this is effectively saying if we're in write mode, and we don't have a type, or if we're in read mode and we don't have an alias + # then we can just pass the value through as is + if type_ is None: + converted_object[key] = value + elif direction == "read" and key not in aliases_to_field_names: + converted_object[key] = convert_and_respect_annotation_metadata( + object_=value, annotation=type_, direction=direction + ) + else: + converted_object[ + _alias_key(key, type_, direction, aliases_to_field_names) + ] = convert_and_respect_annotation_metadata( + object_=value, annotation=type_, direction=direction + ) + return converted_object + + +def _get_annotation(type_: typing.Any) -> typing.Optional[typing.Any]: + maybe_annotated_type = typing_extensions.get_origin(type_) + if maybe_annotated_type is None: + return None + + if maybe_annotated_type == typing_extensions.NotRequired: + type_ = typing_extensions.get_args(type_)[0] + maybe_annotated_type = typing_extensions.get_origin(type_) + + if maybe_annotated_type == typing_extensions.Annotated: + return type_ + + return None + + +def _remove_annotations(type_: typing.Any) -> typing.Any: + maybe_annotated_type = typing_extensions.get_origin(type_) + if maybe_annotated_type is None: + return type_ + + if maybe_annotated_type == typing_extensions.NotRequired: + return _remove_annotations(typing_extensions.get_args(type_)[0]) + + if maybe_annotated_type == typing_extensions.Annotated: + return _remove_annotations(typing_extensions.get_args(type_)[0]) + + return type_ + + +def get_alias_to_field_mapping(type_: typing.Any) -> typing.Dict[str, str]: + annotations = typing_extensions.get_type_hints(type_, include_extras=True) + return _get_alias_to_field_name(annotations) + + +def get_field_to_alias_mapping(type_: typing.Any) -> typing.Dict[str, str]: + annotations = typing_extensions.get_type_hints(type_, include_extras=True) + return _get_field_to_alias_name(annotations) + + +def _get_alias_to_field_name( + field_to_hint: typing.Dict[str, typing.Any], +) -> typing.Dict[str, str]: + aliases = {} + for field, hint in field_to_hint.items(): + maybe_alias = _get_alias_from_type(hint) + if maybe_alias is not None: + aliases[maybe_alias] = field + return aliases + + +def _get_field_to_alias_name( + field_to_hint: typing.Dict[str, typing.Any], +) -> typing.Dict[str, str]: + aliases = {} + for field, hint in field_to_hint.items(): + maybe_alias = _get_alias_from_type(hint) + if maybe_alias is not None: + aliases[field] = maybe_alias + return aliases + + +def _get_alias_from_type(type_: typing.Any) -> typing.Optional[str]: + maybe_annotated_type = _get_annotation(type_) + + if maybe_annotated_type is not None: + # The actual annotations are 1 onward, the first is the annotated type + annotations = typing_extensions.get_args(maybe_annotated_type)[1:] + + for annotation in annotations: + if isinstance(annotation, FieldMetadata) and annotation.alias is not None: + return annotation.alias + return None + + +def _alias_key( + key: str, + type_: typing.Any, + direction: typing.Literal["read", "write"], + aliases_to_field_names: typing.Dict[str, str], +) -> str: + if direction == "read": + return aliases_to_field_names.get(key, key) + return _get_alias_from_type(type_=type_) or key diff --git a/sdks/python/src/opik/rest_api/datasets/client.py b/sdks/python/src/opik/rest_api/datasets/client.py index ef8be8d954..6ac8949a9d 100644 --- a/sdks/python/src/opik/rest_api/datasets/client.py +++ b/sdks/python/src/opik/rest_api/datasets/client.py @@ -1,19 +1,20 @@ # This file was auto-generated by Fern from our API Definition. import typing +from ..core.client_wrapper import SyncClientWrapper +from ..core.request_options import RequestOptions +from ..types.dataset_page_public import DatasetPagePublic +from ..core.pydantic_utilities import parse_obj_as from json.decoder import JSONDecodeError - from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper +from ..types.dataset_item_write import DatasetItemWrite +from ..core.serialization import convert_and_respect_annotation_metadata +from ..types.dataset_public import DatasetPublic from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions from ..types.dataset_item_page_compare import DatasetItemPageCompare -from ..types.dataset_item_page_public import DatasetItemPagePublic from ..types.dataset_item_public import DatasetItemPublic -from ..types.dataset_item_write import DatasetItemWrite -from ..types.dataset_page_public import DatasetPagePublic -from ..types.dataset_public import DatasetPublic +from ..types.dataset_item_page_public import DatasetItemPagePublic +from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -58,7 +59,7 @@ def find_datasets( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.find_datasets() @@ -77,7 +78,13 @@ def find_datasets( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetPagePublic, _response.json()) # type: ignore + return typing.cast( + DatasetPagePublic, + parse_obj_as( + type_=DatasetPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -111,7 +118,7 @@ def create_dataset( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.create_dataset( @@ -121,7 +128,14 @@ def create_dataset( _response = self._client_wrapper.httpx_client.request( "v1/private/datasets", method="POST", - json={"id": id, "name": name, "description": description}, + json={ + "id": id, + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -163,8 +177,7 @@ def create_or_update_dataset_items( Examples -------- - from Opik import DatasetItemWrite - from Opik.client import OpikApi + from Opik import DatasetItemWrite, OpikApi client = OpikApi() client.datasets.create_or_update_dataset_items( @@ -181,7 +194,14 @@ def create_or_update_dataset_items( json={ "dataset_name": dataset_name, "dataset_id": dataset_id, - "items": items, + "items": convert_and_respect_annotation_metadata( + object_=items, + annotation=typing.Sequence[DatasetItemWrite], + direction="write", + ), + }, + headers={ + "content-type": "application/json", }, request_options=request_options, omit=OMIT, @@ -214,7 +234,7 @@ def get_dataset_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.get_dataset_by_id( @@ -228,7 +248,13 @@ def get_dataset_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetPublic, _response.json()) # type: ignore + return typing.cast( + DatasetPublic, + parse_obj_as( + type_=DatasetPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -262,7 +288,7 @@ def update_dataset( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.update_dataset( @@ -273,7 +299,13 @@ def update_dataset( _response = self._client_wrapper.httpx_client.request( f"v1/private/datasets/{jsonable_encoder(id)}", method="PUT", - json={"name": name, "description": description}, + json={ + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -304,7 +336,7 @@ def delete_dataset( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.delete_dataset( @@ -346,7 +378,7 @@ def delete_dataset_by_name( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.delete_dataset_by_name( @@ -356,7 +388,12 @@ def delete_dataset_by_name( _response = self._client_wrapper.httpx_client.request( "v1/private/datasets/delete", method="POST", - json={"dataset_name": dataset_name}, + json={ + "dataset_name": dataset_name, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -390,7 +427,7 @@ def delete_dataset_items( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.delete_dataset_items( @@ -400,7 +437,12 @@ def delete_dataset_items( _response = self._client_wrapper.httpx_client.request( "v1/private/datasets/items/delete", method="POST", - json={"item_ids": item_ids}, + json={ + "item_ids": item_ids, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -450,7 +492,7 @@ def find_dataset_items_with_experiment_items( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.find_dataset_items_with_experiment_items( @@ -472,9 +514,13 @@ def find_dataset_items_with_experiment_items( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as( - DatasetItemPageCompare, _response.json() - ) # type: ignore + return typing.cast( + DatasetItemPageCompare, + parse_obj_as( + type_=DatasetItemPageCompare, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -503,7 +549,7 @@ def get_dataset_by_identifier( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.get_dataset_by_identifier( @@ -513,13 +559,24 @@ def get_dataset_by_identifier( _response = self._client_wrapper.httpx_client.request( "v1/private/datasets/retrieve", method="POST", - json={"dataset_name": dataset_name}, + json={ + "dataset_name": dataset_name, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetPublic, _response.json()) # type: ignore + return typing.cast( + DatasetPublic, + parse_obj_as( + type_=DatasetPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -545,7 +602,7 @@ def get_dataset_item_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.get_dataset_item_by_id( @@ -559,7 +616,13 @@ def get_dataset_item_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetItemPublic, _response.json()) # type: ignore + return typing.cast( + DatasetItemPublic, + parse_obj_as( + type_=DatasetItemPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -597,7 +660,7 @@ def get_dataset_items( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.datasets.get_dataset_items( @@ -607,12 +670,22 @@ def get_dataset_items( _response = self._client_wrapper.httpx_client.request( f"v1/private/datasets/{jsonable_encoder(id)}/items", method="GET", - params={"page": page, "size": size, "truncate": truncate}, + params={ + "page": page, + "size": size, + "truncate": truncate, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetItemPagePublic, _response.json()) # type: ignore + return typing.cast( + DatasetItemPagePublic, + parse_obj_as( + type_=DatasetItemPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -638,23 +711,12 @@ def stream_dataset_items( steam_limit : typing.Optional[int] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Yields ------ typing.Iterator[bytes] Dataset items stream or error during process - - Examples - -------- - from Opik.client import OpikApi - - client = OpikApi() - client.datasets.stream_dataset_items( - dataset_name="string", - last_retrieved_id="string", - steam_limit=1, - ) """ with self._client_wrapper.httpx_client.stream( "v1/private/datasets/items/stream", @@ -664,12 +726,20 @@ def stream_dataset_items( "last_retrieved_id": last_retrieved_id, "steam_limit": steam_limit, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) as _response: try: if 200 <= _response.status_code < 300: - for _chunk in _response.iter_bytes(): + _chunk_size = ( + request_options.get("chunk_size", None) + if request_options is not None + else None + ) + for _chunk in _response.iter_bytes(chunk_size=_chunk_size): yield _chunk return _response.read() @@ -720,7 +790,7 @@ async def find_datasets( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -745,7 +815,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetPagePublic, _response.json()) # type: ignore + return typing.cast( + DatasetPagePublic, + parse_obj_as( + type_=DatasetPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -781,7 +857,7 @@ async def create_dataset( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -797,7 +873,14 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/datasets", method="POST", - json={"id": id, "name": name, "description": description}, + json={ + "id": id, + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -841,8 +924,7 @@ async def create_or_update_dataset_items( -------- import asyncio - from Opik import DatasetItemWrite - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi, DatasetItemWrite client = AsyncOpikApi() @@ -865,7 +947,14 @@ async def main() -> None: json={ "dataset_name": dataset_name, "dataset_id": dataset_id, - "items": items, + "items": convert_and_respect_annotation_metadata( + object_=items, + annotation=typing.Sequence[DatasetItemWrite], + direction="write", + ), + }, + headers={ + "content-type": "application/json", }, request_options=request_options, omit=OMIT, @@ -900,7 +989,7 @@ async def get_dataset_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -920,7 +1009,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetPublic, _response.json()) # type: ignore + return typing.cast( + DatasetPublic, + parse_obj_as( + type_=DatasetPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -956,7 +1051,7 @@ async def update_dataset( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -973,7 +1068,13 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( f"v1/private/datasets/{jsonable_encoder(id)}", method="PUT", - json={"name": name, "description": description}, + json={ + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -1006,7 +1107,7 @@ async def delete_dataset( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1056,7 +1157,7 @@ async def delete_dataset_by_name( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1072,7 +1173,12 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/datasets/delete", method="POST", - json={"dataset_name": dataset_name}, + json={ + "dataset_name": dataset_name, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -1108,7 +1214,7 @@ async def delete_dataset_items( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1124,7 +1230,12 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/datasets/items/delete", method="POST", - json={"item_ids": item_ids}, + json={ + "item_ids": item_ids, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -1176,7 +1287,7 @@ async def find_dataset_items_with_experiment_items( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1204,9 +1315,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as( - DatasetItemPageCompare, _response.json() - ) # type: ignore + return typing.cast( + DatasetItemPageCompare, + parse_obj_as( + type_=DatasetItemPageCompare, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1237,7 +1352,7 @@ async def get_dataset_by_identifier( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1253,13 +1368,24 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/datasets/retrieve", method="POST", - json={"dataset_name": dataset_name}, + json={ + "dataset_name": dataset_name, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetPublic, _response.json()) # type: ignore + return typing.cast( + DatasetPublic, + parse_obj_as( + type_=DatasetPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1287,7 +1413,7 @@ async def get_dataset_item_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1307,7 +1433,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetItemPublic, _response.json()) # type: ignore + return typing.cast( + DatasetItemPublic, + parse_obj_as( + type_=DatasetItemPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1347,7 +1479,7 @@ async def get_dataset_items( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1363,12 +1495,22 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( f"v1/private/datasets/{jsonable_encoder(id)}/items", method="GET", - params={"page": page, "size": size, "truncate": truncate}, + params={ + "page": page, + "size": size, + "truncate": truncate, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(DatasetItemPagePublic, _response.json()) # type: ignore + return typing.cast( + DatasetItemPagePublic, + parse_obj_as( + type_=DatasetItemPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1394,31 +1536,12 @@ async def stream_dataset_items( steam_limit : typing.Optional[int] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Yields ------ typing.AsyncIterator[bytes] Dataset items stream or error during process - - Examples - -------- - import asyncio - - from Opik.client import AsyncOpikApi - - client = AsyncOpikApi() - - - async def main() -> None: - await client.datasets.stream_dataset_items( - dataset_name="string", - last_retrieved_id="string", - steam_limit=1, - ) - - - asyncio.run(main()) """ async with self._client_wrapper.httpx_client.stream( "v1/private/datasets/items/stream", @@ -1428,12 +1551,20 @@ async def main() -> None: "last_retrieved_id": last_retrieved_id, "steam_limit": steam_limit, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) as _response: try: if 200 <= _response.status_code < 300: - async for _chunk in _response.aiter_bytes(): + _chunk_size = ( + request_options.get("chunk_size", None) + if request_options is not None + else None + ) + async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size): yield _chunk return await _response.aread() diff --git a/sdks/python/src/opik/rest_api/errors/bad_request_error.py b/sdks/python/src/opik/rest_api/errors/bad_request_error.py index 44a05f49b3..9c13c61f9e 100644 --- a/sdks/python/src/opik/rest_api/errors/bad_request_error.py +++ b/sdks/python/src/opik/rest_api/errors/bad_request_error.py @@ -1,10 +1,9 @@ # This file was auto-generated by Fern from our API Definition. -import typing - from ..core.api_error import ApiError +import typing class BadRequestError(ApiError): - def __init__(self, body: typing.Any): + def __init__(self, body: typing.Optional[typing.Any]): super().__init__(status_code=400, body=body) diff --git a/sdks/python/src/opik/rest_api/errors/conflict_error.py b/sdks/python/src/opik/rest_api/errors/conflict_error.py index 416399a3db..666bd2bc0c 100644 --- a/sdks/python/src/opik/rest_api/errors/conflict_error.py +++ b/sdks/python/src/opik/rest_api/errors/conflict_error.py @@ -1,10 +1,9 @@ # This file was auto-generated by Fern from our API Definition. -import typing - from ..core.api_error import ApiError +import typing class ConflictError(ApiError): - def __init__(self, body: typing.Any): + def __init__(self, body: typing.Optional[typing.Any]): super().__init__(status_code=409, body=body) diff --git a/sdks/python/src/opik/rest_api/errors/not_found_error.py b/sdks/python/src/opik/rest_api/errors/not_found_error.py index 4405a1962d..a1235b87ff 100644 --- a/sdks/python/src/opik/rest_api/errors/not_found_error.py +++ b/sdks/python/src/opik/rest_api/errors/not_found_error.py @@ -1,10 +1,9 @@ # This file was auto-generated by Fern from our API Definition. -import typing - from ..core.api_error import ApiError +import typing class NotFoundError(ApiError): - def __init__(self, body: typing.Any): + def __init__(self, body: typing.Optional[typing.Any]): super().__init__(status_code=404, body=body) diff --git a/sdks/python/src/opik/rest_api/errors/not_implemented_error.py b/sdks/python/src/opik/rest_api/errors/not_implemented_error.py index ebd40c679a..1219b97308 100644 --- a/sdks/python/src/opik/rest_api/errors/not_implemented_error.py +++ b/sdks/python/src/opik/rest_api/errors/not_implemented_error.py @@ -1,10 +1,9 @@ # This file was auto-generated by Fern from our API Definition. -import typing - from ..core.api_error import ApiError +import typing class NotImplementedError(ApiError): - def __init__(self, body: typing.Any): + def __init__(self, body: typing.Optional[typing.Any]): super().__init__(status_code=501, body=body) diff --git a/sdks/python/src/opik/rest_api/errors/unprocessable_entity_error.py b/sdks/python/src/opik/rest_api/errors/unprocessable_entity_error.py index 64448b6bd4..5666f36274 100644 --- a/sdks/python/src/opik/rest_api/errors/unprocessable_entity_error.py +++ b/sdks/python/src/opik/rest_api/errors/unprocessable_entity_error.py @@ -1,10 +1,9 @@ # This file was auto-generated by Fern from our API Definition. -import typing - from ..core.api_error import ApiError +import typing class UnprocessableEntityError(ApiError): - def __init__(self, body: typing.Any): + def __init__(self, body: typing.Optional[typing.Any]): super().__init__(status_code=422, body=body) diff --git a/sdks/python/src/opik/rest_api/experiments/client.py b/sdks/python/src/opik/rest_api/experiments/client.py index b2b2c30b7e..90f76cf22a 100644 --- a/sdks/python/src/opik/rest_api/experiments/client.py +++ b/sdks/python/src/opik/rest_api/experiments/client.py @@ -1,20 +1,21 @@ # This file was auto-generated by Fern from our API Definition. import typing +from ..core.client_wrapper import SyncClientWrapper +from ..core.request_options import RequestOptions +from ..types.experiment_page_public import ExperimentPagePublic +from ..core.pydantic_utilities import parse_obj_as from json.decoder import JSONDecodeError - from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper +from ..types.json_node_write import JsonNodeWrite +from ..types.prompt_version_link_write import PromptVersionLinkWrite +from ..core.serialization import convert_and_respect_annotation_metadata +from ..types.experiment_item import ExperimentItem +from ..types.experiment_public import ExperimentPublic from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions from ..errors.not_found_error import NotFoundError -from ..types.experiment_item import ExperimentItem from ..types.experiment_item_public import ExperimentItemPublic -from ..types.experiment_page_public import ExperimentPagePublic -from ..types.experiment_public import ExperimentPublic -from ..types.json_node_write import JsonNodeWrite -from ..types.prompt_version_link_write import PromptVersionLinkWrite +from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -62,7 +63,7 @@ def find_experiments( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.experiments.find_experiments() @@ -82,7 +83,13 @@ def find_experiments( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ExperimentPagePublic, _response.json()) # type: ignore + return typing.cast( + ExperimentPagePublic, + parse_obj_as( + type_=ExperimentPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -122,7 +129,7 @@ def create_experiment( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.experiments.create_experiment( @@ -137,7 +144,14 @@ def create_experiment( "dataset_name": dataset_name, "name": name, "metadata": metadata, - "prompt_version": prompt_version, + "prompt_version": convert_and_respect_annotation_metadata( + object_=prompt_version, + annotation=PromptVersionLinkWrite, + direction="write", + ), + }, + headers={ + "content-type": "application/json", }, request_options=request_options, omit=OMIT, @@ -172,8 +186,7 @@ def create_experiment_items( Examples -------- - from Opik import ExperimentItem - from Opik.client import OpikApi + from Opik import ExperimentItem, OpikApi client = OpikApi() client.experiments.create_experiment_items( @@ -189,7 +202,16 @@ def create_experiment_items( _response = self._client_wrapper.httpx_client.request( "v1/private/experiments/items", method="POST", - json={"experiment_items": experiment_items}, + json={ + "experiment_items": convert_and_respect_annotation_metadata( + object_=experiment_items, + annotation=typing.Sequence[ExperimentItem], + direction="write", + ), + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -223,7 +245,7 @@ def delete_experiment_items( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.experiments.delete_experiment_items( @@ -233,7 +255,12 @@ def delete_experiment_items( _response = self._client_wrapper.httpx_client.request( "v1/private/experiments/items/delete", method="POST", - json={"ids": ids}, + json={ + "ids": ids, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -267,7 +294,7 @@ def delete_experiments_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.experiments.delete_experiments_by_id( @@ -277,7 +304,12 @@ def delete_experiments_by_id( _response = self._client_wrapper.httpx_client.request( "v1/private/experiments/delete", method="POST", - json={"ids": ids}, + json={ + "ids": ids, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -289,6 +321,56 @@ def delete_experiments_by_id( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def find_feedback_score_names( + self, + *, + experiment_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> typing.List[str]: + """ + Find Feedback Score names + + Parameters + ---------- + experiment_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]] + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + typing.List[str] + Feedback Scores resource + + Examples + -------- + from Opik import OpikApi + + client = OpikApi() + client.experiments.find_feedback_score_names() + """ + _response = self._client_wrapper.httpx_client.request( + "v1/private/experiments/feedback-scores/names", + method="GET", + params={ + "experiment_ids": experiment_ids, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + typing.List[str], + parse_obj_as( + type_=typing.List[str], # type: ignore + object_=_response.json(), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + def get_experiment_by_id( self, id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> ExperimentPublic: @@ -309,7 +391,7 @@ def get_experiment_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.experiments.get_experiment_by_id( @@ -323,11 +405,23 @@ def get_experiment_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ExperimentPublic, _response.json()) # type: ignore + return typing.cast( + ExperimentPublic, + parse_obj_as( + type_=ExperimentPublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -353,7 +447,7 @@ def get_experiment_item_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.experiments.get_experiment_item_by_id( @@ -367,11 +461,23 @@ def get_experiment_item_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ExperimentItemPublic, _response.json()) # type: ignore + return typing.cast( + ExperimentItemPublic, + parse_obj_as( + type_=ExperimentItemPublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -397,23 +503,12 @@ def stream_experiment_items( last_retrieved_id : typing.Optional[str] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Yields ------ typing.Iterator[bytes] Experiment items stream or error during process - - Examples - -------- - from Opik.client import OpikApi - - client = OpikApi() - client.experiments.stream_experiment_items( - experiment_name="string", - limit=1, - last_retrieved_id="string", - ) """ with self._client_wrapper.httpx_client.stream( "v1/private/experiments/items/stream", @@ -423,12 +518,20 @@ def stream_experiment_items( "limit": limit, "last_retrieved_id": last_retrieved_id, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) as _response: try: if 200 <= _response.status_code < 300: - for _chunk in _response.iter_bytes(): + _chunk_size = ( + request_options.get("chunk_size", None) + if request_options is not None + else None + ) + for _chunk in _response.iter_bytes(chunk_size=_chunk_size): yield _chunk return _response.read() @@ -482,7 +585,7 @@ async def find_experiments( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -508,7 +611,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ExperimentPagePublic, _response.json()) # type: ignore + return typing.cast( + ExperimentPagePublic, + parse_obj_as( + type_=ExperimentPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -550,7 +659,7 @@ async def create_experiment( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -571,7 +680,14 @@ async def main() -> None: "dataset_name": dataset_name, "name": name, "metadata": metadata, - "prompt_version": prompt_version, + "prompt_version": convert_and_respect_annotation_metadata( + object_=prompt_version, + annotation=PromptVersionLinkWrite, + direction="write", + ), + }, + headers={ + "content-type": "application/json", }, request_options=request_options, omit=OMIT, @@ -608,8 +724,7 @@ async def create_experiment_items( -------- import asyncio - from Opik import ExperimentItem - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi, ExperimentItem client = AsyncOpikApi() @@ -631,7 +746,16 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/experiments/items", method="POST", - json={"experiment_items": experiment_items}, + json={ + "experiment_items": convert_and_respect_annotation_metadata( + object_=experiment_items, + annotation=typing.Sequence[ExperimentItem], + direction="write", + ), + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -667,7 +791,7 @@ async def delete_experiment_items( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -683,7 +807,12 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/experiments/items/delete", method="POST", - json={"ids": ids}, + json={ + "ids": ids, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -719,7 +848,7 @@ async def delete_experiments_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -735,7 +864,12 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/experiments/delete", method="POST", - json={"ids": ids}, + json={ + "ids": ids, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -747,6 +881,64 @@ async def main() -> None: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + async def find_feedback_score_names( + self, + *, + experiment_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> typing.List[str]: + """ + Find Feedback Score names + + Parameters + ---------- + experiment_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]] + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + typing.List[str] + Feedback Scores resource + + Examples + -------- + import asyncio + + from Opik import AsyncOpikApi + + client = AsyncOpikApi() + + + async def main() -> None: + await client.experiments.find_feedback_score_names() + + + asyncio.run(main()) + """ + _response = await self._client_wrapper.httpx_client.request( + "v1/private/experiments/feedback-scores/names", + method="GET", + params={ + "experiment_ids": experiment_ids, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + typing.List[str], + parse_obj_as( + type_=typing.List[str], # type: ignore + object_=_response.json(), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + async def get_experiment_by_id( self, id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> ExperimentPublic: @@ -769,7 +961,7 @@ async def get_experiment_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -789,11 +981,23 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ExperimentPublic, _response.json()) # type: ignore + return typing.cast( + ExperimentPublic, + parse_obj_as( + type_=ExperimentPublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -821,7 +1025,7 @@ async def get_experiment_item_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -841,11 +1045,23 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ExperimentItemPublic, _response.json()) # type: ignore + return typing.cast( + ExperimentItemPublic, + parse_obj_as( + type_=ExperimentItemPublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -871,31 +1087,12 @@ async def stream_experiment_items( last_retrieved_id : typing.Optional[str] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Yields ------ typing.AsyncIterator[bytes] Experiment items stream or error during process - - Examples - -------- - import asyncio - - from Opik.client import AsyncOpikApi - - client = AsyncOpikApi() - - - async def main() -> None: - await client.experiments.stream_experiment_items( - experiment_name="string", - limit=1, - last_retrieved_id="string", - ) - - - asyncio.run(main()) """ async with self._client_wrapper.httpx_client.stream( "v1/private/experiments/items/stream", @@ -905,12 +1102,20 @@ async def main() -> None: "limit": limit, "last_retrieved_id": last_retrieved_id, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) as _response: try: if 200 <= _response.status_code < 300: - async for _chunk in _response.aiter_bytes(): + _chunk_size = ( + request_options.get("chunk_size", None) + if request_options is not None + else None + ) + async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size): yield _chunk return await _response.aread() diff --git a/sdks/python/src/opik/rest_api/feedback_definitions/client.py b/sdks/python/src/opik/rest_api/feedback_definitions/client.py index 9063eb4070..b175ad58de 100644 --- a/sdks/python/src/opik/rest_api/feedback_definitions/client.py +++ b/sdks/python/src/opik/rest_api/feedback_definitions/client.py @@ -1,20 +1,21 @@ # This file was auto-generated by Fern from our API Definition. import typing +from ..core.client_wrapper import SyncClientWrapper +from .types.find_feedback_definitions_request_type import ( + FindFeedbackDefinitionsRequestType, +) +from ..core.request_options import RequestOptions +from ..types.feedback_definition_page_public import FeedbackDefinitionPagePublic +from ..core.pydantic_utilities import parse_obj_as from json.decoder import JSONDecodeError - from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions from ..types.feedback_create import FeedbackCreate -from ..types.feedback_definition_page_public import FeedbackDefinitionPagePublic +from ..core.serialization import convert_and_respect_annotation_metadata from ..types.feedback_public import FeedbackPublic +from ..core.jsonable_encoder import jsonable_encoder from ..types.feedback_update import FeedbackUpdate -from .types.find_feedback_definitions_request_type import ( - FindFeedbackDefinitionsRequestType, -) +from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -56,7 +57,7 @@ def find_feedback_definitions( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.feedback_definitions.find_feedback_definitions() @@ -64,14 +65,23 @@ def find_feedback_definitions( _response = self._client_wrapper.httpx_client.request( "v1/private/feedback-definitions", method="GET", - params={"page": page, "size": size, "name": name, "type": type}, + params={ + "page": page, + "size": size, + "name": name, + "type": type, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as( - FeedbackDefinitionPagePublic, _response.json() - ) # type: ignore + return typing.cast( + FeedbackDefinitionPagePublic, + parse_obj_as( + type_=FeedbackDefinitionPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -99,23 +109,25 @@ def create_feedback_definition( Examples -------- - from Opik import FeedbackCreate_Numerical, NumericalFeedbackDetailCreate - from Opik.client import OpikApi + from Opik import ( + CategoricalFeedbackDetailCreate, + FeedbackCreate_Categorical, + OpikApi, + ) client = OpikApi() client.feedback_definitions.create_feedback_definition( - request=FeedbackCreate_Numerical( - id="string", - name="string", - details={"string": {"key": "value"}}, - details=NumericalFeedbackDetailCreate(), + request=FeedbackCreate_Categorical( + details=CategoricalFeedbackDetailCreate(), ), ) """ _response = self._client_wrapper.httpx_client.request( "v1/private/feedback-definitions", method="POST", - json=request, + json=convert_and_respect_annotation_metadata( + object_=request, annotation=FeedbackCreate, direction="write" + ), request_options=request_options, omit=OMIT, ) @@ -147,11 +159,11 @@ def get_feedback_definition_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.feedback_definitions.get_feedback_definition_by_id( - id="string", + id="id", ) """ _response = self._client_wrapper.httpx_client.request( @@ -161,7 +173,13 @@ def get_feedback_definition_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(FeedbackPublic, _response.json()) # type: ignore + return typing.cast( + FeedbackPublic, + parse_obj_as( + type_=FeedbackPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -192,24 +210,26 @@ def update_feedback_definition( Examples -------- - from Opik import FeedbackUpdate_Numerical, NumericalFeedbackDetailUpdate - from Opik.client import OpikApi + from Opik import ( + CategoricalFeedbackDetailUpdate, + FeedbackUpdate_Categorical, + OpikApi, + ) client = OpikApi() client.feedback_definitions.update_feedback_definition( - id="string", - request=FeedbackUpdate_Numerical( - id="string", - name="string", - details={"string": {"key": "value"}}, - details=NumericalFeedbackDetailUpdate(), + id="id", + request=FeedbackUpdate_Categorical( + details=CategoricalFeedbackDetailUpdate(), ), ) """ _response = self._client_wrapper.httpx_client.request( f"v1/private/feedback-definitions/{jsonable_encoder(id)}", method="PUT", - json=request, + json=convert_and_respect_annotation_metadata( + object_=request, annotation=FeedbackUpdate, direction="write" + ), request_options=request_options, omit=OMIT, ) @@ -240,7 +260,7 @@ def delete_feedback_definition_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.feedback_definitions.delete_feedback_definition_by_id( @@ -299,7 +319,7 @@ async def find_feedback_definitions( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -313,14 +333,23 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/feedback-definitions", method="GET", - params={"page": page, "size": size, "name": name, "type": type}, + params={ + "page": page, + "size": size, + "name": name, + "type": type, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as( - FeedbackDefinitionPagePublic, _response.json() - ) # type: ignore + return typing.cast( + FeedbackDefinitionPagePublic, + parse_obj_as( + type_=FeedbackDefinitionPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -350,19 +379,19 @@ async def create_feedback_definition( -------- import asyncio - from Opik import FeedbackCreate_Numerical, NumericalFeedbackDetailCreate - from Opik.client import AsyncOpikApi + from Opik import ( + AsyncOpikApi, + CategoricalFeedbackDetailCreate, + FeedbackCreate_Categorical, + ) client = AsyncOpikApi() async def main() -> None: await client.feedback_definitions.create_feedback_definition( - request=FeedbackCreate_Numerical( - id="string", - name="string", - details={"string": {"key": "value"}}, - details=NumericalFeedbackDetailCreate(), + request=FeedbackCreate_Categorical( + details=CategoricalFeedbackDetailCreate(), ), ) @@ -372,7 +401,9 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/feedback-definitions", method="POST", - json=request, + json=convert_and_respect_annotation_metadata( + object_=request, annotation=FeedbackCreate, direction="write" + ), request_options=request_options, omit=OMIT, ) @@ -406,14 +437,14 @@ async def get_feedback_definition_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() async def main() -> None: await client.feedback_definitions.get_feedback_definition_by_id( - id="string", + id="id", ) @@ -426,7 +457,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(FeedbackPublic, _response.json()) # type: ignore + return typing.cast( + FeedbackPublic, + parse_obj_as( + type_=FeedbackPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -459,20 +496,20 @@ async def update_feedback_definition( -------- import asyncio - from Opik import FeedbackUpdate_Numerical, NumericalFeedbackDetailUpdate - from Opik.client import AsyncOpikApi + from Opik import ( + AsyncOpikApi, + CategoricalFeedbackDetailUpdate, + FeedbackUpdate_Categorical, + ) client = AsyncOpikApi() async def main() -> None: await client.feedback_definitions.update_feedback_definition( - id="string", - request=FeedbackUpdate_Numerical( - id="string", - name="string", - details={"string": {"key": "value"}}, - details=NumericalFeedbackDetailUpdate(), + id="id", + request=FeedbackUpdate_Categorical( + details=CategoricalFeedbackDetailUpdate(), ), ) @@ -482,7 +519,9 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( f"v1/private/feedback-definitions/{jsonable_encoder(id)}", method="PUT", - json=request, + json=convert_and_respect_annotation_metadata( + object_=request, annotation=FeedbackUpdate, direction="write" + ), request_options=request_options, omit=OMIT, ) @@ -515,7 +554,7 @@ async def delete_feedback_definition_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() diff --git a/sdks/python/src/opik/rest_api/feedback_scores/__init__.py b/sdks/python/src/opik/rest_api/feedback_scores/__init__.py deleted file mode 100644 index 67a41b2742..0000000000 --- a/sdks/python/src/opik/rest_api/feedback_scores/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. diff --git a/sdks/python/src/opik/rest_api/feedback_scores/client.py b/sdks/python/src/opik/rest_api/feedback_scores/client.py deleted file mode 100644 index fa40e3e493..0000000000 --- a/sdks/python/src/opik/rest_api/feedback_scores/client.py +++ /dev/null @@ -1,123 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -import typing -from json.decoder import JSONDecodeError - -from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions - - -class FeedbackScoresClient: - def __init__(self, *, client_wrapper: SyncClientWrapper): - self._client_wrapper = client_wrapper - - def find_feedback_score_names( - self, - *, - project_id: typing.Optional[str] = None, - with_experiments_only: typing.Optional[bool] = None, - request_options: typing.Optional[RequestOptions] = None, - ) -> typing.List[str]: - """ - Find Feedback Score names - - Parameters - ---------- - project_id : typing.Optional[str] - - with_experiments_only : typing.Optional[bool] - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - typing.List[str] - Feedback Scores resource - - Examples - -------- - from Opik.client import OpikApi - - client = OpikApi() - client.feedback_scores.find_feedback_score_names() - """ - _response = self._client_wrapper.httpx_client.request( - "v1/private/feedback-scores/names", - method="GET", - params={ - "project_id": project_id, - "with_experiments_only": with_experiments_only, - }, - request_options=request_options, - ) - try: - if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - raise ApiError(status_code=_response.status_code, body=_response_json) - - -class AsyncFeedbackScoresClient: - def __init__(self, *, client_wrapper: AsyncClientWrapper): - self._client_wrapper = client_wrapper - - async def find_feedback_score_names( - self, - *, - project_id: typing.Optional[str] = None, - with_experiments_only: typing.Optional[bool] = None, - request_options: typing.Optional[RequestOptions] = None, - ) -> typing.List[str]: - """ - Find Feedback Score names - - Parameters - ---------- - project_id : typing.Optional[str] - - with_experiments_only : typing.Optional[bool] - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - typing.List[str] - Feedback Scores resource - - Examples - -------- - import asyncio - - from Opik.client import AsyncOpikApi - - client = AsyncOpikApi() - - - async def main() -> None: - await client.feedback_scores.find_feedback_score_names() - - - asyncio.run(main()) - """ - _response = await self._client_wrapper.httpx_client.request( - "v1/private/feedback-scores/names", - method="GET", - params={ - "project_id": project_id, - "with_experiments_only": with_experiments_only, - }, - request_options=request_options, - ) - try: - if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - raise ApiError(status_code=_response.status_code, body=_response_json) diff --git a/sdks/python/src/opik/rest_api/projects/client.py b/sdks/python/src/opik/rest_api/projects/client.py index 19649a7b2a..e050fe34c4 100644 --- a/sdks/python/src/opik/rest_api/projects/client.py +++ b/sdks/python/src/opik/rest_api/projects/client.py @@ -1,27 +1,27 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt import typing +from ..core.client_wrapper import SyncClientWrapper +from ..core.request_options import RequestOptions +from ..types.project_page_public import ProjectPagePublic +from ..core.pydantic_utilities import parse_obj_as from json.decoder import JSONDecodeError - from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions from ..errors.bad_request_error import BadRequestError -from ..errors.conflict_error import ConflictError -from ..errors.not_found_error import NotFoundError from ..errors.unprocessable_entity_error import UnprocessableEntityError -from ..types.project_metric_response_public import ProjectMetricResponsePublic -from ..types.project_page_public import ProjectPagePublic from ..types.project_public import ProjectPublic -from .types.project_metric_request_public_interval import ( - ProjectMetricRequestPublicInterval, -) +from ..core.jsonable_encoder import jsonable_encoder +from ..errors.conflict_error import ConflictError from .types.project_metric_request_public_metric_type import ( ProjectMetricRequestPublicMetricType, ) +from .types.project_metric_request_public_interval import ( + ProjectMetricRequestPublicInterval, +) +import datetime as dt +from ..types.project_metric_response_public import ProjectMetricResponsePublic +from ..errors.not_found_error import NotFoundError +from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -63,7 +63,7 @@ def find_projects( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.projects.find_projects() @@ -71,12 +71,23 @@ def find_projects( _response = self._client_wrapper.httpx_client.request( "v1/private/projects", method="GET", - params={"page": page, "size": size, "name": name, "sorting": sorting}, + params={ + "page": page, + "size": size, + "name": name, + "sorting": sorting, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ProjectPagePublic, _response.json()) # type: ignore + return typing.cast( + ProjectPagePublic, + parse_obj_as( + type_=ProjectPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -107,7 +118,7 @@ def create_project( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.projects.create_project( @@ -117,7 +128,13 @@ def create_project( _response = self._client_wrapper.httpx_client.request( "v1/private/projects", method="POST", - json={"name": name, "description": description}, + json={ + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -126,12 +143,24 @@ def create_project( return if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -157,7 +186,7 @@ def get_project_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.projects.get_project_by_id( @@ -171,7 +200,13 @@ def get_project_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ProjectPublic, _response.json()) # type: ignore + return typing.cast( + ProjectPublic, + parse_obj_as( + type_=ProjectPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -196,7 +231,7 @@ def delete_project_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.projects.delete_project_by_id( @@ -213,8 +248,14 @@ def delete_project_by_id( return if _response.status_code == 409: raise ConflictError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -248,7 +289,7 @@ def update_project( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.projects.update_project( @@ -258,7 +299,13 @@ def update_project( _response = self._client_wrapper.httpx_client.request( f"v1/private/projects/{jsonable_encoder(id)}", method="PATCH", - json={"name": name, "description": description}, + json={ + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -267,12 +314,24 @@ def update_project( return if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -313,7 +372,7 @@ def get_project_metrics( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.projects.get_project_metrics( @@ -329,22 +388,41 @@ def get_project_metrics( "interval_start": interval_start, "interval_end": interval_end, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as( - ProjectMetricResponsePublic, _response.json() - ) # type: ignore + return typing.cast( + ProjectMetricResponsePublic, + parse_obj_as( + type_=ProjectMetricResponsePublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -370,7 +448,7 @@ def retrieve_project( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.projects.retrieve_project( @@ -380,25 +458,54 @@ def retrieve_project( _response = self._client_wrapper.httpx_client.request( "v1/private/projects/retrieve", method="POST", - json={"name": name}, + json={ + "name": name, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ProjectPublic, _response.json()) # type: ignore + return typing.cast( + ProjectPublic, + parse_obj_as( + type_=ProjectPublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -443,7 +550,7 @@ async def find_projects( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -457,12 +564,23 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/projects", method="GET", - params={"page": page, "size": size, "name": name, "sorting": sorting}, + params={ + "page": page, + "size": size, + "name": name, + "sorting": sorting, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ProjectPagePublic, _response.json()) # type: ignore + return typing.cast( + ProjectPagePublic, + parse_obj_as( + type_=ProjectPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -495,7 +613,7 @@ async def create_project( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -511,7 +629,13 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/projects", method="POST", - json={"name": name, "description": description}, + json={ + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -520,12 +644,24 @@ async def main() -> None: return if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -553,7 +689,7 @@ async def get_project_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -573,7 +709,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ProjectPublic, _response.json()) # type: ignore + return typing.cast( + ProjectPublic, + parse_obj_as( + type_=ProjectPublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -600,7 +742,7 @@ async def delete_project_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -623,8 +765,14 @@ async def main() -> None: return if _response.status_code == 409: raise ConflictError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -660,7 +808,7 @@ async def update_project( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -676,7 +824,13 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( f"v1/private/projects/{jsonable_encoder(id)}", method="PATCH", - json={"name": name, "description": description}, + json={ + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -685,12 +839,24 @@ async def main() -> None: return if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -733,7 +899,7 @@ async def get_project_metrics( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -755,22 +921,41 @@ async def main() -> None: "interval_start": interval_start, "interval_end": interval_end, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as( - ProjectMetricResponsePublic, _response.json() - ) # type: ignore + return typing.cast( + ProjectMetricResponsePublic, + parse_obj_as( + type_=ProjectMetricResponsePublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -798,7 +983,7 @@ async def retrieve_project( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -814,25 +999,54 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/projects/retrieve", method="POST", - json={"name": name}, + json={ + "name": name, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(ProjectPublic, _response.json()) # type: ignore + return typing.cast( + ProjectPublic, + parse_obj_as( + type_=ProjectPublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/sdks/python/src/opik/rest_api/prompts/client.py b/sdks/python/src/opik/rest_api/prompts/client.py index b2e0a22d65..b6ebe340ac 100644 --- a/sdks/python/src/opik/rest_api/prompts/client.py +++ b/sdks/python/src/opik/rest_api/prompts/client.py @@ -1,21 +1,22 @@ # This file was auto-generated by Fern from our API Definition. import typing +from ..core.client_wrapper import SyncClientWrapper +from ..core.request_options import RequestOptions +from ..types.prompt_page_public import PromptPagePublic +from ..core.pydantic_utilities import parse_obj_as from json.decoder import JSONDecodeError - from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions from ..errors.bad_request_error import BadRequestError from ..errors.conflict_error import ConflictError -from ..errors.not_found_error import NotFoundError from ..errors.unprocessable_entity_error import UnprocessableEntityError -from ..types.prompt_detail import PromptDetail -from ..types.prompt_page_public import PromptPagePublic from ..types.prompt_version_detail import PromptVersionDetail +from ..core.serialization import convert_and_respect_annotation_metadata +from ..types.prompt_detail import PromptDetail +from ..core.jsonable_encoder import jsonable_encoder +from ..errors.not_found_error import NotFoundError from ..types.prompt_version_page_public import PromptVersionPagePublic +from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -54,7 +55,7 @@ def get_prompts( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.prompts.get_prompts() @@ -62,12 +63,22 @@ def get_prompts( _response = self._client_wrapper.httpx_client.request( "v1/private/prompts", method="GET", - params={"page": page, "size": size, "name": name}, + params={ + "page": page, + "size": size, + "name": name, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptPagePublic, _response.json()) # type: ignore + return typing.cast( + PromptPagePublic, + parse_obj_as( + type_=PromptPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -104,7 +115,7 @@ def create_prompt( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.prompts.create_prompt( @@ -120,6 +131,9 @@ def create_prompt( "description": description, "template": template, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -128,16 +142,34 @@ def create_prompt( return if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 409: raise ConflictError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -169,8 +201,7 @@ def create_prompt_version( Examples -------- - from Opik import PromptVersionDetail - from Opik.client import OpikApi + from Opik import OpikApi, PromptVersionDetail client = OpikApi() client.prompts.create_prompt_version( @@ -183,25 +214,57 @@ def create_prompt_version( _response = self._client_wrapper.httpx_client.request( "v1/private/prompts/versions", method="POST", - json={"name": name, "version": version}, + json={ + "name": name, + "version": convert_and_respect_annotation_metadata( + object_=version, annotation=PromptVersionDetail, direction="write" + ), + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptVersionDetail, _response.json()) # type: ignore + return typing.cast( + PromptVersionDetail, + parse_obj_as( + type_=PromptVersionDetail, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 409: raise ConflictError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -227,7 +290,7 @@ def get_prompt_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.prompts.get_prompt_by_id( @@ -241,11 +304,23 @@ def get_prompt_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptDetail, _response.json()) # type: ignore + return typing.cast( + PromptDetail, + parse_obj_as( + type_=PromptDetail, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -279,7 +354,7 @@ def update_prompt( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.prompts.update_prompt( @@ -290,7 +365,13 @@ def update_prompt( _response = self._client_wrapper.httpx_client.request( f"v1/private/prompts/{jsonable_encoder(id)}", method="PUT", - json={"name": name, "description": description}, + json={ + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -299,20 +380,44 @@ def update_prompt( return if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 409: raise ConflictError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -337,7 +442,7 @@ def delete_prompt( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.prompts.delete_prompt( @@ -380,7 +485,7 @@ def get_prompt_version_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.prompts.get_prompt_version_by_id( @@ -394,11 +499,23 @@ def get_prompt_version_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptVersionDetail, _response.json()) # type: ignore + return typing.cast( + PromptVersionDetail, + parse_obj_as( + type_=PromptVersionDetail, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -433,7 +550,7 @@ def get_prompt_versions( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.prompts.get_prompt_versions( @@ -443,14 +560,21 @@ def get_prompt_versions( _response = self._client_wrapper.httpx_client.request( f"v1/private/prompts/{jsonable_encoder(id)}/versions", method="GET", - params={"page": page, "size": size}, + params={ + "page": page, + "size": size, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as( - PromptVersionPagePublic, _response.json() - ) # type: ignore + return typing.cast( + PromptVersionPagePublic, + parse_obj_as( + type_=PromptVersionPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -482,7 +606,7 @@ def retrieve_prompt_version( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.prompts.retrieve_prompt_version( @@ -492,25 +616,55 @@ def retrieve_prompt_version( _response = self._client_wrapper.httpx_client.request( "v1/private/prompts/versions/retrieve", method="POST", - json={"name": name, "commit": commit}, + json={ + "name": name, + "commit": commit, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptVersionDetail, _response.json()) # type: ignore + return typing.cast( + PromptVersionDetail, + parse_obj_as( + type_=PromptVersionDetail, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -552,7 +706,7 @@ async def get_prompts( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -566,12 +720,22 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/prompts", method="GET", - params={"page": page, "size": size, "name": name}, + params={ + "page": page, + "size": size, + "name": name, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptPagePublic, _response.json()) # type: ignore + return typing.cast( + PromptPagePublic, + parse_obj_as( + type_=PromptPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -610,7 +774,7 @@ async def create_prompt( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -632,6 +796,9 @@ async def main() -> None: "description": description, "template": template, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -640,16 +807,34 @@ async def main() -> None: return if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 409: raise ConflictError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -683,8 +868,7 @@ async def create_prompt_version( -------- import asyncio - from Opik import PromptVersionDetail - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi, PromptVersionDetail client = AsyncOpikApi() @@ -703,25 +887,57 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/prompts/versions", method="POST", - json={"name": name, "version": version}, + json={ + "name": name, + "version": convert_and_respect_annotation_metadata( + object_=version, annotation=PromptVersionDetail, direction="write" + ), + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptVersionDetail, _response.json()) # type: ignore + return typing.cast( + PromptVersionDetail, + parse_obj_as( + type_=PromptVersionDetail, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 409: raise ConflictError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -749,7 +965,7 @@ async def get_prompt_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -769,11 +985,23 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptDetail, _response.json()) # type: ignore + return typing.cast( + PromptDetail, + parse_obj_as( + type_=PromptDetail, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -809,7 +1037,7 @@ async def update_prompt( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -826,7 +1054,13 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( f"v1/private/prompts/{jsonable_encoder(id)}", method="PUT", - json={"name": name, "description": description}, + json={ + "name": name, + "description": description, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -835,20 +1069,44 @@ async def main() -> None: return if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 409: raise ConflictError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -875,7 +1133,7 @@ async def delete_prompt( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -926,7 +1184,7 @@ async def get_prompt_version_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -946,11 +1204,23 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptVersionDetail, _response.json()) # type: ignore + return typing.cast( + PromptVersionDetail, + parse_obj_as( + type_=PromptVersionDetail, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -987,7 +1257,7 @@ async def get_prompt_versions( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1003,14 +1273,21 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( f"v1/private/prompts/{jsonable_encoder(id)}/versions", method="GET", - params={"page": page, "size": size}, + params={ + "page": page, + "size": size, + }, request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as( - PromptVersionPagePublic, _response.json() - ) # type: ignore + return typing.cast( + PromptVersionPagePublic, + parse_obj_as( + type_=PromptVersionPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1044,7 +1321,7 @@ async def retrieve_prompt_version( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1060,25 +1337,55 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/prompts/versions/retrieve", method="POST", - json={"name": name, "commit": commit}, + json={ + "name": name, + "commit": commit, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptVersionDetail, _response.json()) # type: ignore + return typing.cast( + PromptVersionDetail, + parse_obj_as( + type_=PromptVersionDetail, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 400: raise BadRequestError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) if _response.status_code == 422: raise UnprocessableEntityError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/sdks/python/src/opik/rest_api/spans/__init__.py b/sdks/python/src/opik/rest_api/spans/__init__.py index 4abe783760..8e7b2ddcba 100644 --- a/sdks/python/src/opik/rest_api/spans/__init__.py +++ b/sdks/python/src/opik/rest_api/spans/__init__.py @@ -1,5 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -from .types import GetSpansByProjectRequestType +from .types import FindFeedbackScoreNames1RequestType, GetSpansByProjectRequestType -__all__ = ["GetSpansByProjectRequestType"] +__all__ = ["FindFeedbackScoreNames1RequestType", "GetSpansByProjectRequestType"] diff --git a/sdks/python/src/opik/rest_api/spans/client.py b/sdks/python/src/opik/rest_api/spans/client.py index 88b11ae216..d4e4638a12 100644 --- a/sdks/python/src/opik/rest_api/spans/client.py +++ b/sdks/python/src/opik/rest_api/spans/client.py @@ -1,25 +1,29 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt import typing +from ..core.client_wrapper import SyncClientWrapper +from ..types.feedback_score_source import FeedbackScoreSource +import datetime as dt +from ..core.request_options import RequestOptions +from ..core.jsonable_encoder import jsonable_encoder from json.decoder import JSONDecodeError - from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions +from .types.get_spans_by_project_request_type import GetSpansByProjectRequestType +from ..types.span_page_public import SpanPagePublic +from ..core.pydantic_utilities import parse_obj_as +from ..types.span_write_type import SpanWriteType +from ..types.json_node_write import JsonNodeWrite +from ..types.span_write import SpanWrite +from ..core.serialization import convert_and_respect_annotation_metadata +from ..types.span_public import SpanPublic from ..errors.not_found_error import NotFoundError from ..errors.not_implemented_error import NotImplementedError -from ..types.feedback_score_batch_item import FeedbackScoreBatchItem -from ..types.feedback_score_source import FeedbackScoreSource from ..types.json_node import JsonNode -from ..types.json_node_write import JsonNodeWrite -from ..types.span_page_public import SpanPagePublic -from ..types.span_public import SpanPublic -from ..types.span_write import SpanWrite -from ..types.span_write_type import SpanWriteType -from .types.get_spans_by_project_request_type import GetSpansByProjectRequestType +from .types.find_feedback_score_names_1_request_type import ( + FindFeedbackScoreNames1RequestType, +) +from ..types.feedback_score_batch_item import FeedbackScoreBatchItem +from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -78,7 +82,7 @@ def add_span_feedback_score( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.spans.add_span_feedback_score( @@ -157,7 +161,7 @@ def get_spans_by_project( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.spans.get_spans_by_project() @@ -179,7 +183,13 @@ def get_spans_by_project( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(SpanPagePublic, _response.json()) # type: ignore + return typing.cast( + SpanPagePublic, + parse_obj_as( + type_=SpanPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -252,7 +262,7 @@ def create_span( -------- import datetime - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.spans.create_span( @@ -319,8 +329,7 @@ def create_spans( -------- import datetime - from Opik import SpanWrite - from Opik.client import OpikApi + from Opik import OpikApi, SpanWrite client = OpikApi() client.spans.create_spans( @@ -339,7 +348,16 @@ def create_spans( _response = self._client_wrapper.httpx_client.request( "v1/private/spans/batch", method="POST", - json={"spans": spans}, + json={ + "spans": convert_and_respect_annotation_metadata( + object_=spans, + annotation=typing.Sequence[SpanWrite], + direction="write", + ), + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -371,7 +389,7 @@ def get_span_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.spans.get_span_by_id( @@ -385,11 +403,23 @@ def get_span_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(SpanPublic, _response.json()) # type: ignore + return typing.cast( + SpanPublic, + parse_obj_as( + type_=SpanPublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -414,7 +444,7 @@ def delete_span_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.spans.delete_span_by_id( @@ -431,8 +461,14 @@ def delete_span_by_id( return if _response.status_code == 501: raise NotImplementedError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -498,7 +534,7 @@ def update_span( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.spans.update_span( @@ -523,6 +559,9 @@ def update_span( "tags": tags, "usage": usage, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -531,8 +570,14 @@ def update_span( return if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -563,7 +608,7 @@ def delete_span_feedback_score( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.spans.delete_span_feedback_score( @@ -574,7 +619,9 @@ def delete_span_feedback_score( _response = self._client_wrapper.httpx_client.request( f"v1/private/spans/{jsonable_encoder(id)}/feedback-scores/delete", method="POST", - json={"name": name}, + json={ + "name": name, + }, request_options=request_options, omit=OMIT, ) @@ -586,6 +633,60 @@ def delete_span_feedback_score( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def find_feedback_score_names_1( + self, + *, + project_id: typing.Optional[str] = None, + type: typing.Optional[FindFeedbackScoreNames1RequestType] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> typing.List[str]: + """ + Find Feedback Score names + + Parameters + ---------- + project_id : typing.Optional[str] + + type : typing.Optional[FindFeedbackScoreNames1RequestType] + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + typing.List[str] + Feedback Scores resource + + Examples + -------- + from Opik import OpikApi + + client = OpikApi() + client.spans.find_feedback_score_names_1() + """ + _response = self._client_wrapper.httpx_client.request( + "v1/private/spans/feedback-scores/names", + method="GET", + params={ + "project_id": project_id, + "type": type, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + typing.List[str], + parse_obj_as( + type_=typing.List[str], # type: ignore + object_=_response.json(), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + def score_batch_of_spans( self, *, @@ -608,8 +709,7 @@ def score_batch_of_spans( Examples -------- - from Opik import FeedbackScoreBatchItem - from Opik.client import OpikApi + from Opik import FeedbackScoreBatchItem, OpikApi client = OpikApi() client.spans.score_batch_of_spans( @@ -626,7 +726,13 @@ def score_batch_of_spans( _response = self._client_wrapper.httpx_client.request( "v1/private/spans/feedback-scores", method="PUT", - json={"scores": scores}, + json={ + "scores": convert_and_respect_annotation_metadata( + object_=scores, + annotation=typing.Sequence[FeedbackScoreBatchItem], + direction="write", + ), + }, request_options=request_options, omit=OMIT, ) @@ -694,7 +800,7 @@ async def add_span_feedback_score( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -781,7 +887,7 @@ async def get_spans_by_project( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -809,7 +915,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(SpanPagePublic, _response.json()) # type: ignore + return typing.cast( + SpanPagePublic, + parse_obj_as( + type_=SpanPagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -883,7 +995,7 @@ async def create_span( import asyncio import datetime - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -957,8 +1069,7 @@ async def create_spans( import asyncio import datetime - from Opik import SpanWrite - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi, SpanWrite client = AsyncOpikApi() @@ -983,7 +1094,16 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/spans/batch", method="POST", - json={"spans": spans}, + json={ + "spans": convert_and_respect_annotation_metadata( + object_=spans, + annotation=typing.Sequence[SpanWrite], + direction="write", + ), + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -1017,7 +1137,7 @@ async def get_span_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1037,11 +1157,23 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(SpanPublic, _response.json()) # type: ignore + return typing.cast( + SpanPublic, + parse_obj_as( + type_=SpanPublic, # type: ignore + object_=_response.json(), + ), + ) if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1068,7 +1200,7 @@ async def delete_span_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1091,8 +1223,14 @@ async def main() -> None: return if _response.status_code == 501: raise NotImplementedError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1160,7 +1298,7 @@ async def update_span( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1191,6 +1329,9 @@ async def main() -> None: "tags": tags, "usage": usage, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -1199,8 +1340,14 @@ async def main() -> None: return if _response.status_code == 404: raise NotFoundError( - pydantic_v1.parse_obj_as(typing.Any, _response.json()) - ) # type: ignore + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1233,7 +1380,7 @@ async def delete_span_feedback_score( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1250,7 +1397,9 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( f"v1/private/spans/{jsonable_encoder(id)}/feedback-scores/delete", method="POST", - json={"name": name}, + json={ + "name": name, + }, request_options=request_options, omit=OMIT, ) @@ -1262,6 +1411,68 @@ async def main() -> None: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + async def find_feedback_score_names_1( + self, + *, + project_id: typing.Optional[str] = None, + type: typing.Optional[FindFeedbackScoreNames1RequestType] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> typing.List[str]: + """ + Find Feedback Score names + + Parameters + ---------- + project_id : typing.Optional[str] + + type : typing.Optional[FindFeedbackScoreNames1RequestType] + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + typing.List[str] + Feedback Scores resource + + Examples + -------- + import asyncio + + from Opik import AsyncOpikApi + + client = AsyncOpikApi() + + + async def main() -> None: + await client.spans.find_feedback_score_names_1() + + + asyncio.run(main()) + """ + _response = await self._client_wrapper.httpx_client.request( + "v1/private/spans/feedback-scores/names", + method="GET", + params={ + "project_id": project_id, + "type": type, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + typing.List[str], + parse_obj_as( + type_=typing.List[str], # type: ignore + object_=_response.json(), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + async def score_batch_of_spans( self, *, @@ -1286,8 +1497,7 @@ async def score_batch_of_spans( -------- import asyncio - from Opik import FeedbackScoreBatchItem - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi, FeedbackScoreBatchItem client = AsyncOpikApi() @@ -1310,7 +1520,13 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/spans/feedback-scores", method="PUT", - json={"scores": scores}, + json={ + "scores": convert_and_respect_annotation_metadata( + object_=scores, + annotation=typing.Sequence[FeedbackScoreBatchItem], + direction="write", + ), + }, request_options=request_options, omit=OMIT, ) diff --git a/sdks/python/src/opik/rest_api/spans/types/__init__.py b/sdks/python/src/opik/rest_api/spans/types/__init__.py index 33fe1d6bb6..ec4b65da57 100644 --- a/sdks/python/src/opik/rest_api/spans/types/__init__.py +++ b/sdks/python/src/opik/rest_api/spans/types/__init__.py @@ -1,5 +1,6 @@ # This file was auto-generated by Fern from our API Definition. +from .find_feedback_score_names_1_request_type import FindFeedbackScoreNames1RequestType from .get_spans_by_project_request_type import GetSpansByProjectRequestType -__all__ = ["GetSpansByProjectRequestType"] +__all__ = ["FindFeedbackScoreNames1RequestType", "GetSpansByProjectRequestType"] diff --git a/sdks/python/src/opik/rest_api/spans/types/find_feedback_score_names_1_request_type.py b/sdks/python/src/opik/rest_api/spans/types/find_feedback_score_names_1_request_type.py new file mode 100644 index 0000000000..ab3f81afc5 --- /dev/null +++ b/sdks/python/src/opik/rest_api/spans/types/find_feedback_score_names_1_request_type.py @@ -0,0 +1,7 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +FindFeedbackScoreNames1RequestType = typing.Union[ + typing.Literal["general", "tool", "llm"], typing.Any +] diff --git a/sdks/python/src/opik/rest_api/system_usage/client.py b/sdks/python/src/opik/rest_api/system_usage/client.py index 1ca28c3f02..995a55ffab 100644 --- a/sdks/python/src/opik/rest_api/system_usage/client.py +++ b/sdks/python/src/opik/rest_api/system_usage/client.py @@ -1,14 +1,14 @@ # This file was auto-generated by Fern from our API Definition. +from ..core.client_wrapper import SyncClientWrapper import typing -from json.decoder import JSONDecodeError - -from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.pydantic_utilities import pydantic_v1 from ..core.request_options import RequestOptions from ..types.bi_information_response import BiInformationResponse +from ..core.pydantic_utilities import parse_obj_as +from json.decoder import JSONDecodeError +from ..core.api_error import ApiError from ..types.trace_count_response import TraceCountResponse +from ..core.client_wrapper import AsyncClientWrapper class SystemUsageClient: @@ -33,7 +33,7 @@ def get_dataset_bi_info( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.system_usage.get_dataset_bi_info() @@ -45,7 +45,13 @@ def get_dataset_bi_info( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(BiInformationResponse, _response.json()) # type: ignore + return typing.cast( + BiInformationResponse, + parse_obj_as( + type_=BiInformationResponse, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -69,7 +75,7 @@ def get_experiment_bi_info( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.system_usage.get_experiment_bi_info() @@ -81,7 +87,13 @@ def get_experiment_bi_info( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(BiInformationResponse, _response.json()) # type: ignore + return typing.cast( + BiInformationResponse, + parse_obj_as( + type_=BiInformationResponse, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -105,17 +117,25 @@ def get_traces_bi_info( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.system_usage.get_traces_bi_info() """ _response = self._client_wrapper.httpx_client.request( - "v1/internal/usage/bi-traces", method="GET", request_options=request_options + "v1/internal/usage/bi-traces", + method="GET", + request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(BiInformationResponse, _response.json()) # type: ignore + return typing.cast( + BiInformationResponse, + parse_obj_as( + type_=BiInformationResponse, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -139,7 +159,7 @@ def get_traces_count_for_workspaces( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.system_usage.get_traces_count_for_workspaces() @@ -151,7 +171,13 @@ def get_traces_count_for_workspaces( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(TraceCountResponse, _response.json()) # type: ignore + return typing.cast( + TraceCountResponse, + parse_obj_as( + type_=TraceCountResponse, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -182,7 +208,7 @@ async def get_dataset_bi_info( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -200,7 +226,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(BiInformationResponse, _response.json()) # type: ignore + return typing.cast( + BiInformationResponse, + parse_obj_as( + type_=BiInformationResponse, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -226,7 +258,7 @@ async def get_experiment_bi_info( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -244,7 +276,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(BiInformationResponse, _response.json()) # type: ignore + return typing.cast( + BiInformationResponse, + parse_obj_as( + type_=BiInformationResponse, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -270,7 +308,7 @@ async def get_traces_bi_info( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -282,11 +320,19 @@ async def main() -> None: asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( - "v1/internal/usage/bi-traces", method="GET", request_options=request_options + "v1/internal/usage/bi-traces", + method="GET", + request_options=request_options, ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(BiInformationResponse, _response.json()) # type: ignore + return typing.cast( + BiInformationResponse, + parse_obj_as( + type_=BiInformationResponse, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -312,7 +358,7 @@ async def get_traces_count_for_workspaces( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -330,7 +376,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(TraceCountResponse, _response.json()) # type: ignore + return typing.cast( + TraceCountResponse, + parse_obj_as( + type_=TraceCountResponse, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/sdks/python/src/opik/rest_api/tests/utils/test_http_client.py b/sdks/python/src/opik/rest_api/tests/utils/test_http_client.py deleted file mode 100644 index 2228cdb826..0000000000 --- a/sdks/python/src/opik/rest_api/tests/utils/test_http_client.py +++ /dev/null @@ -1,59 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -from Opik.core.http_client import get_request_body -from Opik.core.request_options import RequestOptions - - -def get_request_options() -> RequestOptions: - return {"additional_body_parameters": {"see you": "later"}} - - -def test_get_json_request_body() -> None: - json_body, data_body = get_request_body( - json={"hello": "world"}, data=None, request_options=None, omit=None - ) - assert json_body == {"hello": "world"} - assert data_body is None - - json_body_extras, data_body_extras = get_request_body( - json={"goodbye": "world"}, - data=None, - request_options=get_request_options(), - omit=None, - ) - - assert json_body_extras == {"goodbye": "world", "see you": "later"} - assert data_body_extras is None - - -def test_get_files_request_body() -> None: - json_body, data_body = get_request_body( - json=None, data={"hello": "world"}, request_options=None, omit=None - ) - assert data_body == {"hello": "world"} - assert json_body is None - - json_body_extras, data_body_extras = get_request_body( - json=None, - data={"goodbye": "world"}, - request_options=get_request_options(), - omit=None, - ) - - assert data_body_extras == {"goodbye": "world", "see you": "later"} - assert json_body_extras is None - - -def test_get_none_request_body() -> None: - json_body, data_body = get_request_body( - json=None, data=None, request_options=None, omit=None - ) - assert data_body is None - assert json_body is None - - json_body_extras, data_body_extras = get_request_body( - json=None, data=None, request_options=get_request_options(), omit=None - ) - - assert json_body_extras == {"see you": "later"} - assert data_body_extras is None diff --git a/sdks/python/src/opik/rest_api/tests/utils/test_query_encoding.py b/sdks/python/src/opik/rest_api/tests/utils/test_query_encoding.py deleted file mode 100644 index 8587301ae8..0000000000 --- a/sdks/python/src/opik/rest_api/tests/utils/test_query_encoding.py +++ /dev/null @@ -1,19 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -from Opik.core.query_encoder import encode_query - - -def test_query_encoding() -> None: - assert encode_query({"hello world": "hello world"}) == { - "hello world": "hello world" - } - assert encode_query({"hello_world": {"hello": "world"}}) == { - "hello_world[hello]": "world" - } - assert encode_query( - {"hello_world": {"hello": {"world": "today"}, "test": "this"}, "hi": "there"} - ) == { - "hello_world[hello][world]": "today", - "hello_world[test]": "this", - "hi": "there", - } diff --git a/sdks/python/src/opik/rest_api/traces/client.py b/sdks/python/src/opik/rest_api/traces/client.py index 4e91b51fa5..ac58ae8ac7 100644 --- a/sdks/python/src/opik/rest_api/traces/client.py +++ b/sdks/python/src/opik/rest_api/traces/client.py @@ -1,21 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt import typing +from ..core.client_wrapper import SyncClientWrapper +from ..types.feedback_score_source import FeedbackScoreSource +import datetime as dt +from ..core.request_options import RequestOptions +from ..core.jsonable_encoder import jsonable_encoder from json.decoder import JSONDecodeError - from ..core.api_error import ApiError -from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import pydantic_v1 -from ..core.request_options import RequestOptions -from ..types.feedback_score_batch_item import FeedbackScoreBatchItem -from ..types.feedback_score_source import FeedbackScoreSource -from ..types.json_node import JsonNode -from ..types.json_node_write import JsonNodeWrite from ..types.trace_page_public import TracePagePublic -from ..types.trace_public import TracePublic +from ..core.pydantic_utilities import parse_obj_as +from ..types.json_node_write import JsonNodeWrite from ..types.trace_write import TraceWrite +from ..core.serialization import convert_and_respect_annotation_metadata +from ..types.trace_public import TracePublic +from ..types.json_node import JsonNode +from ..types.feedback_score_batch_item import FeedbackScoreBatchItem +from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -74,7 +75,7 @@ def add_trace_feedback_score( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.traces.add_trace_feedback_score( @@ -147,7 +148,7 @@ def get_traces_by_project( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.traces.get_traces_by_project() @@ -167,7 +168,13 @@ def get_traces_by_project( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(TracePagePublic, _response.json()) # type: ignore + return typing.cast( + TracePagePublic, + parse_obj_as( + type_=TracePagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -222,7 +229,7 @@ def create_trace( -------- import datetime - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.traces.create_trace( @@ -281,8 +288,7 @@ def create_traces( -------- import datetime - from Opik import TraceWrite - from Opik.client import OpikApi + from Opik import OpikApi, TraceWrite client = OpikApi() client.traces.create_traces( @@ -299,7 +305,16 @@ def create_traces( _response = self._client_wrapper.httpx_client.request( "v1/private/traces/batch", method="POST", - json={"traces": traces}, + json={ + "traces": convert_and_respect_annotation_metadata( + object_=traces, + annotation=typing.Sequence[TraceWrite], + direction="write", + ), + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -331,7 +346,7 @@ def get_trace_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.traces.get_trace_by_id( @@ -345,7 +360,13 @@ def get_trace_by_id( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(TracePublic, _response.json()) # type: ignore + return typing.cast( + TracePublic, + parse_obj_as( + type_=TracePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -370,7 +391,7 @@ def delete_trace_by_id( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.traces.delete_trace_by_id( @@ -435,7 +456,7 @@ def update_trace( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.traces.update_trace( @@ -454,6 +475,9 @@ def update_trace( "metadata": metadata, "tags": tags, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -490,7 +514,7 @@ def delete_trace_feedback_score( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.traces.delete_trace_feedback_score( @@ -501,7 +525,9 @@ def delete_trace_feedback_score( _response = self._client_wrapper.httpx_client.request( f"v1/private/traces/{jsonable_encoder(id)}/feedback-scores/delete", method="POST", - json={"name": name}, + json={ + "name": name, + }, request_options=request_options, omit=OMIT, ) @@ -535,7 +561,7 @@ def delete_traces( Examples -------- - from Opik.client import OpikApi + from Opik import OpikApi client = OpikApi() client.traces.delete_traces( @@ -545,7 +571,12 @@ def delete_traces( _response = self._client_wrapper.httpx_client.request( "v1/private/traces/delete", method="POST", - json={"ids": ids}, + json={ + "ids": ids, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -557,6 +588,56 @@ def delete_traces( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def find_feedback_score_names_2( + self, + *, + project_id: typing.Optional[str] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> typing.List[str]: + """ + Find Feedback Score names + + Parameters + ---------- + project_id : typing.Optional[str] + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + typing.List[str] + Feedback Scores resource + + Examples + -------- + from Opik import OpikApi + + client = OpikApi() + client.traces.find_feedback_score_names_2() + """ + _response = self._client_wrapper.httpx_client.request( + "v1/private/traces/feedback-scores/names", + method="GET", + params={ + "project_id": project_id, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + typing.List[str], + parse_obj_as( + type_=typing.List[str], # type: ignore + object_=_response.json(), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + def score_batch_of_traces( self, *, @@ -579,8 +660,7 @@ def score_batch_of_traces( Examples -------- - from Opik import FeedbackScoreBatchItem - from Opik.client import OpikApi + from Opik import FeedbackScoreBatchItem, OpikApi client = OpikApi() client.traces.score_batch_of_traces( @@ -597,7 +677,13 @@ def score_batch_of_traces( _response = self._client_wrapper.httpx_client.request( "v1/private/traces/feedback-scores", method="PUT", - json={"scores": scores}, + json={ + "scores": convert_and_respect_annotation_metadata( + object_=scores, + annotation=typing.Sequence[FeedbackScoreBatchItem], + direction="write", + ), + }, request_options=request_options, omit=OMIT, ) @@ -665,7 +751,7 @@ async def add_trace_feedback_score( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -746,7 +832,7 @@ async def get_traces_by_project( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -772,7 +858,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(TracePagePublic, _response.json()) # type: ignore + return typing.cast( + TracePagePublic, + parse_obj_as( + type_=TracePagePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -828,7 +920,7 @@ async def create_trace( import asyncio import datetime - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -894,8 +986,7 @@ async def create_traces( import asyncio import datetime - from Opik import TraceWrite - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi, TraceWrite client = AsyncOpikApi() @@ -918,7 +1009,16 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/traces/batch", method="POST", - json={"traces": traces}, + json={ + "traces": convert_and_respect_annotation_metadata( + object_=traces, + annotation=typing.Sequence[TraceWrite], + direction="write", + ), + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -952,7 +1052,7 @@ async def get_trace_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -972,7 +1072,13 @@ async def main() -> None: ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(TracePublic, _response.json()) # type: ignore + return typing.cast( + TracePublic, + parse_obj_as( + type_=TracePublic, # type: ignore + object_=_response.json(), + ), + ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -999,7 +1105,7 @@ async def delete_trace_by_id( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1072,7 +1178,7 @@ async def update_trace( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1097,6 +1203,9 @@ async def main() -> None: "metadata": metadata, "tags": tags, }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -1135,7 +1244,7 @@ async def delete_trace_feedback_score( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1152,7 +1261,9 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( f"v1/private/traces/{jsonable_encoder(id)}/feedback-scores/delete", method="POST", - json={"name": name}, + json={ + "name": name, + }, request_options=request_options, omit=OMIT, ) @@ -1188,7 +1299,7 @@ async def delete_traces( -------- import asyncio - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi client = AsyncOpikApi() @@ -1204,7 +1315,12 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/traces/delete", method="POST", - json={"ids": ids}, + json={ + "ids": ids, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, omit=OMIT, ) @@ -1216,6 +1332,64 @@ async def main() -> None: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + async def find_feedback_score_names_2( + self, + *, + project_id: typing.Optional[str] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> typing.List[str]: + """ + Find Feedback Score names + + Parameters + ---------- + project_id : typing.Optional[str] + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + typing.List[str] + Feedback Scores resource + + Examples + -------- + import asyncio + + from Opik import AsyncOpikApi + + client = AsyncOpikApi() + + + async def main() -> None: + await client.traces.find_feedback_score_names_2() + + + asyncio.run(main()) + """ + _response = await self._client_wrapper.httpx_client.request( + "v1/private/traces/feedback-scores/names", + method="GET", + params={ + "project_id": project_id, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + typing.List[str], + parse_obj_as( + type_=typing.List[str], # type: ignore + object_=_response.json(), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + async def score_batch_of_traces( self, *, @@ -1240,8 +1414,7 @@ async def score_batch_of_traces( -------- import asyncio - from Opik import FeedbackScoreBatchItem - from Opik.client import AsyncOpikApi + from Opik import AsyncOpikApi, FeedbackScoreBatchItem client = AsyncOpikApi() @@ -1264,7 +1437,13 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/private/traces/feedback-scores", method="PUT", - json={"scores": scores}, + json={ + "scores": convert_and_respect_annotation_metadata( + object_=scores, + annotation=typing.Sequence[FeedbackScoreBatchItem], + direction="write", + ), + }, request_options=request_options, omit=OMIT, ) diff --git a/sdks/python/src/opik/rest_api/types/bi_information.py b/sdks/python/src/opik/rest_api/types/bi_information.py index 87c07760f3..d6fff7eda6 100644 --- a/sdks/python/src/opik/rest_api/types/bi_information.py +++ b/sdks/python/src/opik/rest_api/types/bi_information.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class BiInformation(pydantic_v1.BaseModel): +class BiInformation(UniversalBaseModel): workspace_id: typing.Optional[str] = None user: typing.Optional[str] = None count: typing.Optional[int] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/bi_information_response.py b/sdks/python/src/opik/rest_api/types/bi_information_response.py index ecbaae8029..5fbc8467b3 100644 --- a/sdks/python/src/opik/rest_api/types/bi_information_response.py +++ b/sdks/python/src/opik/rest_api/types/bi_information_response.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .bi_information import BiInformation +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class BiInformationResponse(pydantic_v1.BaseModel): +class BiInformationResponse(UniversalBaseModel): bi_information: typing.Optional[typing.List[BiInformation]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/categorical_feedback_definition.py b/sdks/python/src/opik/rest_api/types/categorical_feedback_definition.py index ffc3e2706b..49eac45a39 100644 --- a/sdks/python/src/opik/rest_api/types/categorical_feedback_definition.py +++ b/sdks/python/src/opik/rest_api/types/categorical_feedback_definition.py @@ -1,47 +1,27 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .categorical_feedback_detail import CategoricalFeedbackDetail +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class CategoricalFeedbackDefinition(pydantic_v1.BaseModel): +class CategoricalFeedbackDefinition(UniversalBaseModel): details: typing.Optional[CategoricalFeedbackDetail] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_create.py b/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_create.py index 86a2f15b0c..c691c77b28 100644 --- a/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_create.py +++ b/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_create.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .categorical_feedback_detail_create import CategoricalFeedbackDetailCreate +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class CategoricalFeedbackDefinitionCreate(pydantic_v1.BaseModel): +class CategoricalFeedbackDefinitionCreate(UniversalBaseModel): details: typing.Optional[CategoricalFeedbackDetailCreate] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_public.py b/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_public.py index 30bbe3a9de..65dde965fb 100644 --- a/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_public.py +++ b/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_public.py @@ -1,47 +1,27 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .categorical_feedback_detail_public import CategoricalFeedbackDetailPublic +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class CategoricalFeedbackDefinitionPublic(pydantic_v1.BaseModel): +class CategoricalFeedbackDefinitionPublic(UniversalBaseModel): details: typing.Optional[CategoricalFeedbackDetailPublic] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_update.py b/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_update.py index c781c03609..bdc9229979 100644 --- a/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_update.py +++ b/sdks/python/src/opik/rest_api/types/categorical_feedback_definition_update.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .categorical_feedback_detail_update import CategoricalFeedbackDetailUpdate +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class CategoricalFeedbackDefinitionUpdate(pydantic_v1.BaseModel): +class CategoricalFeedbackDefinitionUpdate(UniversalBaseModel): details: typing.Optional[CategoricalFeedbackDetailUpdate] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/categorical_feedback_detail.py b/sdks/python/src/opik/rest_api/types/categorical_feedback_detail.py index 3059b7b7bb..567db16a8e 100644 --- a/sdks/python/src/opik/rest_api/types/categorical_feedback_detail.py +++ b/sdks/python/src/opik/rest_api/types/categorical_feedback_detail.py @@ -1,42 +1,21 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class CategoricalFeedbackDetail(pydantic_v1.BaseModel): +class CategoricalFeedbackDetail(UniversalBaseModel): categories: typing.Dict[str, float] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_create.py b/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_create.py index dc906eda68..68665251ff 100644 --- a/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_create.py +++ b/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_create.py @@ -1,42 +1,21 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class CategoricalFeedbackDetailCreate(pydantic_v1.BaseModel): +class CategoricalFeedbackDetailCreate(UniversalBaseModel): categories: typing.Dict[str, float] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_public.py b/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_public.py index 8006d385da..93507a8be9 100644 --- a/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_public.py +++ b/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_public.py @@ -1,42 +1,21 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class CategoricalFeedbackDetailPublic(pydantic_v1.BaseModel): +class CategoricalFeedbackDetailPublic(UniversalBaseModel): categories: typing.Dict[str, float] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_update.py b/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_update.py index ed34b86184..5f674a025e 100644 --- a/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_update.py +++ b/sdks/python/src/opik/rest_api/types/categorical_feedback_detail_update.py @@ -1,42 +1,21 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class CategoricalFeedbackDetailUpdate(pydantic_v1.BaseModel): +class CategoricalFeedbackDetailUpdate(UniversalBaseModel): categories: typing.Dict[str, float] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/chunked_output_json_node.py b/sdks/python/src/opik/rest_api/types/chunked_output_json_node.py index 0857b39b5b..e71448ef9f 100644 --- a/sdks/python/src/opik/rest_api/types/chunked_output_json_node.py +++ b/sdks/python/src/opik/rest_api/types/chunked_output_json_node.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chunked_output_json_node_type import ChunkedOutputJsonNodeType +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ChunkedOutputJsonNode(pydantic_v1.BaseModel): +class ChunkedOutputJsonNode(UniversalBaseModel): type: typing.Optional[ChunkedOutputJsonNodeType] = None closed: typing.Optional[bool] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/chunked_output_json_node_type.py b/sdks/python/src/opik/rest_api/types/chunked_output_json_node_type.py index f4117572b0..2c633f61ec 100644 --- a/sdks/python/src/opik/rest_api/types/chunked_output_json_node_type.py +++ b/sdks/python/src/opik/rest_api/types/chunked_output_json_node_type.py @@ -1,44 +1,25 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +import typing_extensions import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - - -class ChunkedOutputJsonNodeType(pydantic_v1.BaseModel): - type_name: typing.Optional[str] = pydantic_v1.Field(alias="typeName", default=None) - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) - - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} +from ..core.serialization import FieldMetadata +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic + + +class ChunkedOutputJsonNodeType(UniversalBaseModel): + type_name: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="typeName") + ] = None + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/column_compare.py b/sdks/python/src/opik/rest_api/types/column_compare.py index 6fe395dd03..2050f5bc13 100644 --- a/sdks/python/src/opik/rest_api/types/column_compare.py +++ b/sdks/python/src/opik/rest_api/types/column_compare.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .column_compare_types_item import ColumnCompareTypesItem +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ColumnCompare(pydantic_v1.BaseModel): +class ColumnCompare(UniversalBaseModel): name: typing.Optional[str] = None types: typing.Optional[typing.List[ColumnCompareTypesItem]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/column_public.py b/sdks/python/src/opik/rest_api/types/column_public.py index b5f62436bc..c99ca5c51b 100644 --- a/sdks/python/src/opik/rest_api/types/column_public.py +++ b/sdks/python/src/opik/rest_api/types/column_public.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .column_public_types_item import ColumnPublicTypesItem +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ColumnPublic(pydantic_v1.BaseModel): +class ColumnPublic(UniversalBaseModel): name: typing.Optional[str] = None types: typing.Optional[typing.List[ColumnPublicTypesItem]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/data_point_public.py b/sdks/python/src/opik/rest_api/types/data_point_public.py index cf50defe09..2a3a30488e 100644 --- a/sdks/python/src/opik/rest_api/types/data_point_public.py +++ b/sdks/python/src/opik/rest_api/types/data_point_public.py @@ -1,43 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DataPointPublic(pydantic_v1.BaseModel): +class DataPointPublic(UniversalBaseModel): time: typing.Optional[dt.datetime] = None value: typing.Optional[float] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset.py b/sdks/python/src/opik/rest_api/types/dataset.py index 3dfbfb07d1..9396ad4e63 100644 --- a/sdks/python/src/opik/rest_api/types/dataset.py +++ b/sdks/python/src/opik/rest_api/types/dataset.py @@ -1,13 +1,13 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class Dataset(pydantic_v1.BaseModel): +class Dataset(UniversalBaseModel): id: typing.Optional[str] = None name: str description: typing.Optional[str] = None @@ -20,33 +20,13 @@ class Dataset(pydantic_v1.BaseModel): most_recent_experiment_at: typing.Optional[dt.datetime] = None last_created_experiment_at: typing.Optional[dt.datetime] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_item.py b/sdks/python/src/opik/rest_api/types/dataset_item.py index 06ae202968..1b07a11d22 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_item.py +++ b/sdks/python/src/opik/rest_api/types/dataset_item.py @@ -1,16 +1,16 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .json_node import JsonNode from .dataset_item_source import DatasetItemSource from .experiment_item import ExperimentItem -from .json_node import JsonNode +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DatasetItem(pydantic_v1.BaseModel): +class DatasetItem(UniversalBaseModel): id: typing.Optional[str] = None input: typing.Optional[JsonNode] = None expected_output: typing.Optional[JsonNode] = None @@ -25,33 +25,13 @@ class DatasetItem(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_item_batch.py b/sdks/python/src/opik/rest_api/types/dataset_item_batch.py index b3ac4b2678..18355cea84 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_item_batch.py +++ b/sdks/python/src/opik/rest_api/types/dataset_item_batch.py @@ -1,53 +1,32 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import pydantic from .dataset_item import DatasetItem +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class DatasetItemBatch(pydantic_v1.BaseModel): - dataset_name: typing.Optional[str] = pydantic_v1.Field(default=None) +class DatasetItemBatch(UniversalBaseModel): + dataset_name: typing.Optional[str] = pydantic.Field(default=None) """ If null, dataset_id must be provided """ - dataset_id: typing.Optional[str] = pydantic_v1.Field(default=None) + dataset_id: typing.Optional[str] = pydantic.Field(default=None) """ If null, dataset_name must be provided """ items: typing.List[DatasetItem] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_item_compare.py b/sdks/python/src/opik/rest_api/types/dataset_item_compare.py index e9c784d7fd..49a01e543f 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_item_compare.py +++ b/sdks/python/src/opik/rest_api/types/dataset_item_compare.py @@ -1,17 +1,17 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .json_node_compare import JsonNodeCompare from .dataset_item_compare_source import DatasetItemCompareSource -from .experiment_item_compare import ExperimentItemCompare from .json_node import JsonNode -from .json_node_compare import JsonNodeCompare +from .experiment_item_compare import ExperimentItemCompare +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DatasetItemCompare(pydantic_v1.BaseModel): +class DatasetItemCompare(UniversalBaseModel): id: typing.Optional[str] = None input: typing.Optional[JsonNodeCompare] = None expected_output: typing.Optional[JsonNodeCompare] = None @@ -26,33 +26,13 @@ class DatasetItemCompare(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_item_page_compare.py b/sdks/python/src/opik/rest_api/types/dataset_item_page_compare.py index 68a262a1e0..418f104e79 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_item_page_compare.py +++ b/sdks/python/src/opik/rest_api/types/dataset_item_page_compare.py @@ -1,48 +1,27 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .column_compare import ColumnCompare from .dataset_item_compare import DatasetItemCompare +from .column_compare import ColumnCompare +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DatasetItemPageCompare(pydantic_v1.BaseModel): +class DatasetItemPageCompare(UniversalBaseModel): content: typing.Optional[typing.List[DatasetItemCompare]] = None page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None columns: typing.Optional[typing.List[ColumnCompare]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_item_page_public.py b/sdks/python/src/opik/rest_api/types/dataset_item_page_public.py index d1d8f2744b..9ca84e9256 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_item_page_public.py +++ b/sdks/python/src/opik/rest_api/types/dataset_item_page_public.py @@ -1,48 +1,27 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .column_public import ColumnPublic from .dataset_item_public import DatasetItemPublic +from .column_public import ColumnPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DatasetItemPagePublic(pydantic_v1.BaseModel): +class DatasetItemPagePublic(UniversalBaseModel): content: typing.Optional[typing.List[DatasetItemPublic]] = None page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None columns: typing.Optional[typing.List[ColumnPublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_item_public.py b/sdks/python/src/opik/rest_api/types/dataset_item_public.py index 59e1a4a853..98fe67adcd 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_item_public.py +++ b/sdks/python/src/opik/rest_api/types/dataset_item_public.py @@ -1,17 +1,17 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .json_node_public import JsonNodePublic from .dataset_item_public_source import DatasetItemPublicSource -from .experiment_item_public import ExperimentItemPublic from .json_node import JsonNode -from .json_node_public import JsonNodePublic +from .experiment_item_public import ExperimentItemPublic +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DatasetItemPublic(pydantic_v1.BaseModel): +class DatasetItemPublic(UniversalBaseModel): id: typing.Optional[str] = None input: typing.Optional[JsonNodePublic] = None expected_output: typing.Optional[JsonNodePublic] = None @@ -26,33 +26,13 @@ class DatasetItemPublic(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_item_write.py b/sdks/python/src/opik/rest_api/types/dataset_item_write.py index a198c2faaf..e3ed37e2f3 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_item_write.py +++ b/sdks/python/src/opik/rest_api/types/dataset_item_write.py @@ -1,16 +1,15 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +from .json_node_write import JsonNodeWrite from .dataset_item_write_source import DatasetItemWriteSource from .json_node import JsonNode -from .json_node_write import JsonNodeWrite +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DatasetItemWrite(pydantic_v1.BaseModel): +class DatasetItemWrite(UniversalBaseModel): id: typing.Optional[str] = None input: typing.Optional[JsonNodeWrite] = None expected_output: typing.Optional[JsonNodeWrite] = None @@ -20,33 +19,13 @@ class DatasetItemWrite(pydantic_v1.BaseModel): source: DatasetItemWriteSource data: typing.Optional[JsonNode] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_page_public.py b/sdks/python/src/opik/rest_api/types/dataset_page_public.py index 0f8dbe3896..eee476098f 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_page_public.py +++ b/sdks/python/src/opik/rest_api/types/dataset_page_public.py @@ -1,46 +1,25 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .dataset_public import DatasetPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DatasetPagePublic(pydantic_v1.BaseModel): +class DatasetPagePublic(UniversalBaseModel): content: typing.Optional[typing.List[DatasetPublic]] = None page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/dataset_public.py b/sdks/python/src/opik/rest_api/types/dataset_public.py index 84950279c6..1a02dd7680 100644 --- a/sdks/python/src/opik/rest_api/types/dataset_public.py +++ b/sdks/python/src/opik/rest_api/types/dataset_public.py @@ -1,13 +1,13 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class DatasetPublic(pydantic_v1.BaseModel): +class DatasetPublic(UniversalBaseModel): id: typing.Optional[str] = None name: str description: typing.Optional[str] = None @@ -20,33 +20,13 @@ class DatasetPublic(pydantic_v1.BaseModel): most_recent_experiment_at: typing.Optional[dt.datetime] = None last_created_experiment_at: typing.Optional[dt.datetime] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/delete_feedback_score.py b/sdks/python/src/opik/rest_api/types/delete_feedback_score.py index f29de89fd3..007d55cde9 100644 --- a/sdks/python/src/opik/rest_api/types/delete_feedback_score.py +++ b/sdks/python/src/opik/rest_api/types/delete_feedback_score.py @@ -1,42 +1,21 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +from ..core.pydantic_utilities import IS_PYDANTIC_V2 import typing +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class DeleteFeedbackScore(pydantic_v1.BaseModel): +class DeleteFeedbackScore(UniversalBaseModel): name: str - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/error_message.py b/sdks/python/src/opik/rest_api/types/error_message.py index 3569837d3c..20e26386df 100644 --- a/sdks/python/src/opik/rest_api/types/error_message.py +++ b/sdks/python/src/opik/rest_api/types/error_message.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class ErrorMessage(pydantic_v1.BaseModel): +class ErrorMessage(UniversalBaseModel): code: typing.Optional[int] = None message: typing.Optional[str] = None details: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/error_message_detail.py b/sdks/python/src/opik/rest_api/types/error_message_detail.py index 879c0e484e..ee3aefafb3 100644 --- a/sdks/python/src/opik/rest_api/types/error_message_detail.py +++ b/sdks/python/src/opik/rest_api/types/error_message_detail.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class ErrorMessageDetail(pydantic_v1.BaseModel): +class ErrorMessageDetail(UniversalBaseModel): code: typing.Optional[int] = None message: typing.Optional[str] = None details: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/error_message_public.py b/sdks/python/src/opik/rest_api/types/error_message_public.py index b723102c64..21596ace52 100644 --- a/sdks/python/src/opik/rest_api/types/error_message_public.py +++ b/sdks/python/src/opik/rest_api/types/error_message_public.py @@ -1,42 +1,21 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class ErrorMessagePublic(pydantic_v1.BaseModel): +class ErrorMessagePublic(UniversalBaseModel): errors: typing.Optional[typing.List[str]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/experiment.py b/sdks/python/src/opik/rest_api/types/experiment.py index 4c7d4377dc..9e9a5a043d 100644 --- a/sdks/python/src/opik/rest_api/types/experiment.py +++ b/sdks/python/src/opik/rest_api/types/experiment.py @@ -1,16 +1,16 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .feedback_score_average import FeedbackScoreAverage from .json_node import JsonNode +from .feedback_score_average import FeedbackScoreAverage +import datetime as dt from .prompt_version_link import PromptVersionLink +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class Experiment(pydantic_v1.BaseModel): +class Experiment(UniversalBaseModel): id: typing.Optional[str] = None dataset_name: str dataset_id: typing.Optional[str] = None @@ -24,33 +24,13 @@ class Experiment(pydantic_v1.BaseModel): last_updated_by: typing.Optional[str] = None prompt_version: typing.Optional[PromptVersionLink] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/experiment_item.py b/sdks/python/src/opik/rest_api/types/experiment_item.py index eb4a05bca3..993fe7e2ee 100644 --- a/sdks/python/src/opik/rest_api/types/experiment_item.py +++ b/sdks/python/src/opik/rest_api/types/experiment_item.py @@ -1,15 +1,15 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .feedback_score import FeedbackScore from .json_node import JsonNode +from .feedback_score import FeedbackScore +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ExperimentItem(pydantic_v1.BaseModel): +class ExperimentItem(UniversalBaseModel): id: typing.Optional[str] = None experiment_id: str dataset_item_id: str @@ -22,33 +22,13 @@ class ExperimentItem(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/experiment_item_compare.py b/sdks/python/src/opik/rest_api/types/experiment_item_compare.py index 8ccf5b88b0..76a016d2f8 100644 --- a/sdks/python/src/opik/rest_api/types/experiment_item_compare.py +++ b/sdks/python/src/opik/rest_api/types/experiment_item_compare.py @@ -1,15 +1,15 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .feedback_score_compare import FeedbackScoreCompare from .json_node_compare import JsonNodeCompare +from .feedback_score_compare import FeedbackScoreCompare +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ExperimentItemCompare(pydantic_v1.BaseModel): +class ExperimentItemCompare(UniversalBaseModel): id: typing.Optional[str] = None experiment_id: str dataset_item_id: str @@ -22,33 +22,13 @@ class ExperimentItemCompare(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/experiment_item_public.py b/sdks/python/src/opik/rest_api/types/experiment_item_public.py index 7aecffbff4..83a33ce2d6 100644 --- a/sdks/python/src/opik/rest_api/types/experiment_item_public.py +++ b/sdks/python/src/opik/rest_api/types/experiment_item_public.py @@ -1,13 +1,13 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ExperimentItemPublic(pydantic_v1.BaseModel): +class ExperimentItemPublic(UniversalBaseModel): id: typing.Optional[str] = None experiment_id: str dataset_item_id: str @@ -17,33 +17,13 @@ class ExperimentItemPublic(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/experiment_page_public.py b/sdks/python/src/opik/rest_api/types/experiment_page_public.py index 1a655e8e2a..4642d805be 100644 --- a/sdks/python/src/opik/rest_api/types/experiment_page_public.py +++ b/sdks/python/src/opik/rest_api/types/experiment_page_public.py @@ -1,46 +1,25 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .experiment_public import ExperimentPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ExperimentPagePublic(pydantic_v1.BaseModel): +class ExperimentPagePublic(UniversalBaseModel): page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None content: typing.Optional[typing.List[ExperimentPublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/experiment_public.py b/sdks/python/src/opik/rest_api/types/experiment_public.py index fe9f1ea67c..1f3983d097 100644 --- a/sdks/python/src/opik/rest_api/types/experiment_public.py +++ b/sdks/python/src/opik/rest_api/types/experiment_public.py @@ -1,16 +1,16 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .feedback_score_average_public import FeedbackScoreAveragePublic from .json_node_public import JsonNodePublic +from .feedback_score_average_public import FeedbackScoreAveragePublic +import datetime as dt from .prompt_version_link_public import PromptVersionLinkPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ExperimentPublic(pydantic_v1.BaseModel): +class ExperimentPublic(UniversalBaseModel): id: typing.Optional[str] = None dataset_name: str dataset_id: typing.Optional[str] = None @@ -24,33 +24,13 @@ class ExperimentPublic(pydantic_v1.BaseModel): last_updated_by: typing.Optional[str] = None prompt_version: typing.Optional[PromptVersionLinkPublic] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback.py b/sdks/python/src/opik/rest_api/types/feedback.py index c130ddfce0..3d667485cd 100644 --- a/sdks/python/src/opik/rest_api/types/feedback.py +++ b/sdks/python/src/opik/rest_api/types/feedback.py @@ -1,149 +1,84 @@ # This file was auto-generated by Fern from our API Definition. from __future__ import annotations - -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .categorical_feedback_detail import CategoricalFeedbackDetail +import typing_extensions +import datetime as dt +from ..core.serialization import FieldMetadata +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic from .numerical_feedback_detail import NumericalFeedbackDetail +from .categorical_feedback_detail import CategoricalFeedbackDetail -class Base(pydantic_v1.BaseModel): +class Base(UniversalBaseModel): id: typing.Optional[str] = None name: str - details: typing.Dict[str, typing.Any] - created_at: typing.Optional[dt.datetime] = pydantic_v1.Field( - alias="createdAt", default=None - ) - created_by: typing.Optional[str] = pydantic_v1.Field( - alias="createdBy", default=None - ) - last_updated_at: typing.Optional[dt.datetime] = pydantic_v1.Field( - alias="lastUpdatedAt", default=None - ) - last_updated_by: typing.Optional[str] = pydantic_v1.Field( - alias="lastUpdatedBy", default=None - ) - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) - - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + details: typing.Dict[str, typing.Optional[typing.Any]] + created_at: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="createdAt") + ] = None + created_by: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="createdBy") + ] = None + last_updated_at: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="lastUpdatedAt") + ] = None + last_updated_by: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="lastUpdatedBy") + ] = None + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class Feedback_Numerical(Base): + type: typing.Literal["numerical"] = "numerical" details: typing.Optional[NumericalFeedbackDetail] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - type: typing.Literal["numerical"] = "numerical" - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class Feedback_Categorical(Base): + type: typing.Literal["categorical"] = "categorical" details: typing.Optional[CategoricalFeedbackDetail] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - type: typing.Literal["categorical"] = "categorical" - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow Feedback = typing.Union[Feedback_Numerical, Feedback_Categorical] diff --git a/sdks/python/src/opik/rest_api/types/feedback_create.py b/sdks/python/src/opik/rest_api/types/feedback_create.py index 11b5a93520..5fbed0e259 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_create.py +++ b/sdks/python/src/opik/rest_api/types/feedback_create.py @@ -1,127 +1,61 @@ # This file was auto-generated by Fern from our API Definition. from __future__ import annotations - -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .categorical_feedback_detail_create import CategoricalFeedbackDetailCreate +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic from .numerical_feedback_detail_create import NumericalFeedbackDetailCreate +from .categorical_feedback_detail_create import CategoricalFeedbackDetailCreate -class Base(pydantic_v1.BaseModel): +class Base(UniversalBaseModel): id: typing.Optional[str] = None name: str - details: typing.Dict[str, typing.Any] + details: typing.Dict[str, typing.Optional[typing.Any]] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) - - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class FeedbackCreate_Numerical(Base): - details: typing.Optional[NumericalFeedbackDetailCreate] = None type: typing.Literal["numerical"] = "numerical" + details: typing.Optional[NumericalFeedbackDetailCreate] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class FeedbackCreate_Categorical(Base): - details: typing.Optional[CategoricalFeedbackDetailCreate] = None type: typing.Literal["categorical"] = "categorical" + details: typing.Optional[CategoricalFeedbackDetailCreate] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow FeedbackCreate = typing.Union[FeedbackCreate_Numerical, FeedbackCreate_Categorical] diff --git a/sdks/python/src/opik/rest_api/types/feedback_definition_page_public.py b/sdks/python/src/opik/rest_api/types/feedback_definition_page_public.py index b44296d23c..8c41a5a1e6 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_definition_page_public.py +++ b/sdks/python/src/opik/rest_api/types/feedback_definition_page_public.py @@ -1,46 +1,25 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .feedback_object_public import FeedbackObjectPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class FeedbackDefinitionPagePublic(pydantic_v1.BaseModel): +class FeedbackDefinitionPagePublic(UniversalBaseModel): page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None content: typing.Optional[typing.List[FeedbackObjectPublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback_object_public.py b/sdks/python/src/opik/rest_api/types/feedback_object_public.py index 6b02e658de..a8fc5b8657 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_object_public.py +++ b/sdks/python/src/opik/rest_api/types/feedback_object_public.py @@ -1,149 +1,84 @@ # This file was auto-generated by Fern from our API Definition. from __future__ import annotations - -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .categorical_feedback_detail_public import CategoricalFeedbackDetailPublic +import typing_extensions +import datetime as dt +from ..core.serialization import FieldMetadata +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic from .numerical_feedback_detail_public import NumericalFeedbackDetailPublic +from .categorical_feedback_detail_public import CategoricalFeedbackDetailPublic -class Base(pydantic_v1.BaseModel): +class Base(UniversalBaseModel): id: typing.Optional[str] = None name: str - details: typing.Dict[str, typing.Any] - created_at: typing.Optional[dt.datetime] = pydantic_v1.Field( - alias="createdAt", default=None - ) - created_by: typing.Optional[str] = pydantic_v1.Field( - alias="createdBy", default=None - ) - last_updated_at: typing.Optional[dt.datetime] = pydantic_v1.Field( - alias="lastUpdatedAt", default=None - ) - last_updated_by: typing.Optional[str] = pydantic_v1.Field( - alias="lastUpdatedBy", default=None - ) - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) - - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + details: typing.Dict[str, typing.Optional[typing.Any]] + created_at: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="createdAt") + ] = None + created_by: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="createdBy") + ] = None + last_updated_at: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="lastUpdatedAt") + ] = None + last_updated_by: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="lastUpdatedBy") + ] = None + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class FeedbackObjectPublic_Numerical(Base): + type: typing.Literal["numerical"] = "numerical" details: typing.Optional[NumericalFeedbackDetailPublic] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - type: typing.Literal["numerical"] = "numerical" - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class FeedbackObjectPublic_Categorical(Base): + type: typing.Literal["categorical"] = "categorical" details: typing.Optional[CategoricalFeedbackDetailPublic] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - type: typing.Literal["categorical"] = "categorical" - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow FeedbackObjectPublic = typing.Union[ diff --git a/sdks/python/src/opik/rest_api/types/feedback_public.py b/sdks/python/src/opik/rest_api/types/feedback_public.py index dea4a5679b..6cb999e202 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_public.py +++ b/sdks/python/src/opik/rest_api/types/feedback_public.py @@ -1,149 +1,84 @@ # This file was auto-generated by Fern from our API Definition. from __future__ import annotations - -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .categorical_feedback_detail_public import CategoricalFeedbackDetailPublic +import typing_extensions +import datetime as dt +from ..core.serialization import FieldMetadata +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic from .numerical_feedback_detail_public import NumericalFeedbackDetailPublic +from .categorical_feedback_detail_public import CategoricalFeedbackDetailPublic -class Base(pydantic_v1.BaseModel): +class Base(UniversalBaseModel): id: typing.Optional[str] = None name: str - details: typing.Dict[str, typing.Any] - created_at: typing.Optional[dt.datetime] = pydantic_v1.Field( - alias="createdAt", default=None - ) - created_by: typing.Optional[str] = pydantic_v1.Field( - alias="createdBy", default=None - ) - last_updated_at: typing.Optional[dt.datetime] = pydantic_v1.Field( - alias="lastUpdatedAt", default=None - ) - last_updated_by: typing.Optional[str] = pydantic_v1.Field( - alias="lastUpdatedBy", default=None - ) - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) - - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + details: typing.Dict[str, typing.Optional[typing.Any]] + created_at: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="createdAt") + ] = None + created_by: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="createdBy") + ] = None + last_updated_at: typing_extensions.Annotated[ + typing.Optional[dt.datetime], FieldMetadata(alias="lastUpdatedAt") + ] = None + last_updated_by: typing_extensions.Annotated[ + typing.Optional[str], FieldMetadata(alias="lastUpdatedBy") + ] = None + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class FeedbackPublic_Numerical(Base): + type: typing.Literal["numerical"] = "numerical" details: typing.Optional[NumericalFeedbackDetailPublic] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - type: typing.Literal["numerical"] = "numerical" - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class FeedbackPublic_Categorical(Base): + type: typing.Literal["categorical"] = "categorical" details: typing.Optional[CategoricalFeedbackDetailPublic] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - type: typing.Literal["categorical"] = "categorical" - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow FeedbackPublic = typing.Union[FeedbackPublic_Numerical, FeedbackPublic_Categorical] diff --git a/sdks/python/src/opik/rest_api/types/feedback_score.py b/sdks/python/src/opik/rest_api/types/feedback_score.py index f544efb893..ca870e9b59 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_score.py +++ b/sdks/python/src/opik/rest_api/types/feedback_score.py @@ -1,14 +1,14 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .feedback_score_source import FeedbackScoreSource +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class FeedbackScore(pydantic_v1.BaseModel): +class FeedbackScore(UniversalBaseModel): name: str category_name: typing.Optional[str] = None value: float @@ -19,33 +19,13 @@ class FeedbackScore(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback_score_average.py b/sdks/python/src/opik/rest_api/types/feedback_score_average.py index 4c38e75aaa..8fed87515a 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_score_average.py +++ b/sdks/python/src/opik/rest_api/types/feedback_score_average.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +from ..core.pydantic_utilities import IS_PYDANTIC_V2 import typing +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class FeedbackScoreAverage(pydantic_v1.BaseModel): +class FeedbackScoreAverage(UniversalBaseModel): name: str value: float - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback_score_average_public.py b/sdks/python/src/opik/rest_api/types/feedback_score_average_public.py index bfd1f756a2..e608c57a41 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_score_average_public.py +++ b/sdks/python/src/opik/rest_api/types/feedback_score_average_public.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +from ..core.pydantic_utilities import IS_PYDANTIC_V2 import typing +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class FeedbackScoreAveragePublic(pydantic_v1.BaseModel): +class FeedbackScoreAveragePublic(UniversalBaseModel): name: str value: float - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback_score_batch.py b/sdks/python/src/opik/rest_api/types/feedback_score_batch.py index 541eb6d042..8cfd846043 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_score_batch.py +++ b/sdks/python/src/opik/rest_api/types/feedback_score_batch.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .feedback_score_batch_item import FeedbackScoreBatchItem +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class FeedbackScoreBatch(pydantic_v1.BaseModel): +class FeedbackScoreBatch(UniversalBaseModel): scores: typing.List[FeedbackScoreBatchItem] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback_score_batch_item.py b/sdks/python/src/opik/rest_api/types/feedback_score_batch_item.py index eb32f4c16d..0462b4e81b 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_score_batch_item.py +++ b/sdks/python/src/opik/rest_api/types/feedback_score_batch_item.py @@ -1,16 +1,15 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import pydantic from .feedback_score_batch_item_source import FeedbackScoreBatchItemSource +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class FeedbackScoreBatchItem(pydantic_v1.BaseModel): +class FeedbackScoreBatchItem(UniversalBaseModel): id: str - project_name: typing.Optional[str] = pydantic_v1.Field(default=None) + project_name: typing.Optional[str] = pydantic.Field(default=None) """ If null, the default project is used """ @@ -21,33 +20,13 @@ class FeedbackScoreBatchItem(pydantic_v1.BaseModel): reason: typing.Optional[str] = None source: FeedbackScoreBatchItemSource - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback_score_compare.py b/sdks/python/src/opik/rest_api/types/feedback_score_compare.py index 88c210a9a0..3d7537c4c2 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_score_compare.py +++ b/sdks/python/src/opik/rest_api/types/feedback_score_compare.py @@ -1,14 +1,14 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .feedback_score_compare_source import FeedbackScoreCompareSource +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class FeedbackScoreCompare(pydantic_v1.BaseModel): +class FeedbackScoreCompare(UniversalBaseModel): name: str category_name: typing.Optional[str] = None value: float @@ -19,33 +19,13 @@ class FeedbackScoreCompare(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback_score_public.py b/sdks/python/src/opik/rest_api/types/feedback_score_public.py index ec81982263..88ba45da20 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_score_public.py +++ b/sdks/python/src/opik/rest_api/types/feedback_score_public.py @@ -1,14 +1,14 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .feedback_score_public_source import FeedbackScorePublicSource +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class FeedbackScorePublic(pydantic_v1.BaseModel): +class FeedbackScorePublic(UniversalBaseModel): name: str category_name: typing.Optional[str] = None value: float @@ -19,33 +19,13 @@ class FeedbackScorePublic(pydantic_v1.BaseModel): created_by: typing.Optional[str] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/feedback_update.py b/sdks/python/src/opik/rest_api/types/feedback_update.py index 0692eab388..29da05021b 100644 --- a/sdks/python/src/opik/rest_api/types/feedback_update.py +++ b/sdks/python/src/opik/rest_api/types/feedback_update.py @@ -1,127 +1,61 @@ # This file was auto-generated by Fern from our API Definition. from __future__ import annotations - -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .categorical_feedback_detail_update import CategoricalFeedbackDetailUpdate +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic from .numerical_feedback_detail_update import NumericalFeedbackDetailUpdate +from .categorical_feedback_detail_update import CategoricalFeedbackDetailUpdate -class Base(pydantic_v1.BaseModel): +class Base(UniversalBaseModel): id: typing.Optional[str] = None name: str - details: typing.Dict[str, typing.Any] + details: typing.Dict[str, typing.Optional[typing.Any]] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) - - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class FeedbackUpdate_Numerical(Base): - details: typing.Optional[NumericalFeedbackDetailUpdate] = None type: typing.Literal["numerical"] = "numerical" + details: typing.Optional[NumericalFeedbackDetailUpdate] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow class FeedbackUpdate_Categorical(Base): - details: typing.Optional[CategoricalFeedbackDetailUpdate] = None type: typing.Literal["categorical"] = "categorical" + details: typing.Optional[CategoricalFeedbackDetailUpdate] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow FeedbackUpdate = typing.Union[FeedbackUpdate_Numerical, FeedbackUpdate_Categorical] diff --git a/sdks/python/src/opik/rest_api/types/json_node.py b/sdks/python/src/opik/rest_api/types/json_node.py index 32715f8841..6214e0aa50 100644 --- a/sdks/python/src/opik/rest_api/types/json_node.py +++ b/sdks/python/src/opik/rest_api/types/json_node.py @@ -2,4 +2,4 @@ import typing -JsonNode = typing.Dict[str, typing.Any] +JsonNode = typing.Dict[str, typing.Optional[typing.Any]] diff --git a/sdks/python/src/opik/rest_api/types/json_node_compare.py b/sdks/python/src/opik/rest_api/types/json_node_compare.py index cda78e376c..aa70a13799 100644 --- a/sdks/python/src/opik/rest_api/types/json_node_compare.py +++ b/sdks/python/src/opik/rest_api/types/json_node_compare.py @@ -2,4 +2,4 @@ import typing -JsonNodeCompare = typing.Dict[str, typing.Any] +JsonNodeCompare = typing.Dict[str, typing.Optional[typing.Any]] diff --git a/sdks/python/src/opik/rest_api/types/json_node_public.py b/sdks/python/src/opik/rest_api/types/json_node_public.py index 342c333992..cd1432ee77 100644 --- a/sdks/python/src/opik/rest_api/types/json_node_public.py +++ b/sdks/python/src/opik/rest_api/types/json_node_public.py @@ -2,4 +2,4 @@ import typing -JsonNodePublic = typing.Dict[str, typing.Any] +JsonNodePublic = typing.Dict[str, typing.Optional[typing.Any]] diff --git a/sdks/python/src/opik/rest_api/types/json_node_write.py b/sdks/python/src/opik/rest_api/types/json_node_write.py index f99b5cd874..7c0f5ba5f2 100644 --- a/sdks/python/src/opik/rest_api/types/json_node_write.py +++ b/sdks/python/src/opik/rest_api/types/json_node_write.py @@ -2,4 +2,4 @@ import typing -JsonNodeWrite = typing.Dict[str, typing.Any] +JsonNodeWrite = typing.Dict[str, typing.Optional[typing.Any]] diff --git a/sdks/python/src/opik/rest_api/types/numerical_feedback_definition.py b/sdks/python/src/opik/rest_api/types/numerical_feedback_definition.py index 297ef380e6..aa5e09c561 100644 --- a/sdks/python/src/opik/rest_api/types/numerical_feedback_definition.py +++ b/sdks/python/src/opik/rest_api/types/numerical_feedback_definition.py @@ -1,47 +1,27 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .numerical_feedback_detail import NumericalFeedbackDetail +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class NumericalFeedbackDefinition(pydantic_v1.BaseModel): +class NumericalFeedbackDefinition(UniversalBaseModel): details: typing.Optional[NumericalFeedbackDetail] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_create.py b/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_create.py index 72feeb1e03..8b9a01a749 100644 --- a/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_create.py +++ b/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_create.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .numerical_feedback_detail_create import NumericalFeedbackDetailCreate +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class NumericalFeedbackDefinitionCreate(pydantic_v1.BaseModel): +class NumericalFeedbackDefinitionCreate(UniversalBaseModel): details: typing.Optional[NumericalFeedbackDetailCreate] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_public.py b/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_public.py index bfd594424d..490d01236a 100644 --- a/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_public.py +++ b/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_public.py @@ -1,47 +1,27 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .numerical_feedback_detail_public import NumericalFeedbackDetailPublic +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class NumericalFeedbackDefinitionPublic(pydantic_v1.BaseModel): +class NumericalFeedbackDefinitionPublic(UniversalBaseModel): details: typing.Optional[NumericalFeedbackDetailPublic] = None created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None last_updated_at: typing.Optional[dt.datetime] = None last_updated_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_update.py b/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_update.py index 01a9a9ec78..791ccdbaec 100644 --- a/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_update.py +++ b/sdks/python/src/opik/rest_api/types/numerical_feedback_definition_update.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .numerical_feedback_detail_update import NumericalFeedbackDetailUpdate +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class NumericalFeedbackDefinitionUpdate(pydantic_v1.BaseModel): +class NumericalFeedbackDefinitionUpdate(UniversalBaseModel): details: typing.Optional[NumericalFeedbackDetailUpdate] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/numerical_feedback_detail.py b/sdks/python/src/opik/rest_api/types/numerical_feedback_detail.py index e6c1f22b1e..24de1a3a24 100644 --- a/sdks/python/src/opik/rest_api/types/numerical_feedback_detail.py +++ b/sdks/python/src/opik/rest_api/types/numerical_feedback_detail.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +from ..core.pydantic_utilities import IS_PYDANTIC_V2 import typing +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class NumericalFeedbackDetail(pydantic_v1.BaseModel): +class NumericalFeedbackDetail(UniversalBaseModel): max: float min: float - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_create.py b/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_create.py index a0d83a32f9..3d619ee8b4 100644 --- a/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_create.py +++ b/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_create.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +from ..core.pydantic_utilities import IS_PYDANTIC_V2 import typing +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class NumericalFeedbackDetailCreate(pydantic_v1.BaseModel): +class NumericalFeedbackDetailCreate(UniversalBaseModel): max: float min: float - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_public.py b/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_public.py index bc53eb77d0..a1662b6d5b 100644 --- a/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_public.py +++ b/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_public.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +from ..core.pydantic_utilities import IS_PYDANTIC_V2 import typing +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class NumericalFeedbackDetailPublic(pydantic_v1.BaseModel): +class NumericalFeedbackDetailPublic(UniversalBaseModel): max: float min: float - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_update.py b/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_update.py index 0afb98ad87..df112a4ab7 100644 --- a/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_update.py +++ b/sdks/python/src/opik/rest_api/types/numerical_feedback_detail_update.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +from ..core.pydantic_utilities import IS_PYDANTIC_V2 import typing +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class NumericalFeedbackDetailUpdate(pydantic_v1.BaseModel): +class NumericalFeedbackDetailUpdate(UniversalBaseModel): max: float min: float - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/project.py b/sdks/python/src/opik/rest_api/types/project.py index 08e06bc03f..885c599e3d 100644 --- a/sdks/python/src/opik/rest_api/types/project.py +++ b/sdks/python/src/opik/rest_api/types/project.py @@ -1,13 +1,13 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class Project(pydantic_v1.BaseModel): +class Project(UniversalBaseModel): id: typing.Optional[str] = None name: str description: typing.Optional[str] = None @@ -17,33 +17,13 @@ class Project(pydantic_v1.BaseModel): last_updated_by: typing.Optional[str] = None last_updated_trace_at: typing.Optional[dt.datetime] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/project_metric_response_public.py b/sdks/python/src/opik/rest_api/types/project_metric_response_public.py index a5c0676e67..13e691193f 100644 --- a/sdks/python/src/opik/rest_api/types/project_metric_response_public.py +++ b/sdks/python/src/opik/rest_api/types/project_metric_response_public.py @@ -1,50 +1,29 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .project_metric_response_public_interval import ProjectMetricResponsePublicInterval from .project_metric_response_public_metric_type import ( ProjectMetricResponsePublicMetricType, ) +from .project_metric_response_public_interval import ProjectMetricResponsePublicInterval from .results_public import ResultsPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ProjectMetricResponsePublic(pydantic_v1.BaseModel): +class ProjectMetricResponsePublic(UniversalBaseModel): project_id: typing.Optional[str] = None metric_type: typing.Optional[ProjectMetricResponsePublicMetricType] = None interval: typing.Optional[ProjectMetricResponsePublicInterval] = None results: typing.Optional[typing.List[ResultsPublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/project_page_public.py b/sdks/python/src/opik/rest_api/types/project_page_public.py index 4572e31902..15dee4c7c1 100644 --- a/sdks/python/src/opik/rest_api/types/project_page_public.py +++ b/sdks/python/src/opik/rest_api/types/project_page_public.py @@ -1,51 +1,30 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .project_public import ProjectPublic +import typing_extensions +from ..core.serialization import FieldMetadata +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ProjectPagePublic(pydantic_v1.BaseModel): +class ProjectPagePublic(UniversalBaseModel): page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None content: typing.Optional[typing.List[ProjectPublic]] = None - sortable_by: typing.Optional[typing.List[str]] = pydantic_v1.Field( - alias="sortableBy", default=None - ) - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) - - class Config: - frozen = True - smart_union = True - allow_population_by_field_name = True - populate_by_name = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + sortable_by: typing_extensions.Annotated[ + typing.Optional[typing.List[str]], FieldMetadata(alias="sortableBy") + ] = None + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/project_public.py b/sdks/python/src/opik/rest_api/types/project_public.py index e4ad37b782..f96ac0c9e4 100644 --- a/sdks/python/src/opik/rest_api/types/project_public.py +++ b/sdks/python/src/opik/rest_api/types/project_public.py @@ -1,13 +1,13 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ProjectPublic(pydantic_v1.BaseModel): +class ProjectPublic(UniversalBaseModel): id: typing.Optional[str] = None name: str description: typing.Optional[str] = None @@ -17,33 +17,13 @@ class ProjectPublic(pydantic_v1.BaseModel): last_updated_by: typing.Optional[str] = None last_updated_trace_at: typing.Optional[dt.datetime] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt.py b/sdks/python/src/opik/rest_api/types/prompt.py index ed2d44022c..f8e87146be 100644 --- a/sdks/python/src/opik/rest_api/types/prompt.py +++ b/sdks/python/src/opik/rest_api/types/prompt.py @@ -1,14 +1,14 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt from .prompt_version import PromptVersion +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class Prompt(pydantic_v1.BaseModel): +class Prompt(UniversalBaseModel): id: typing.Optional[str] = None name: str description: typing.Optional[str] = None @@ -20,33 +20,13 @@ class Prompt(pydantic_v1.BaseModel): version_count: typing.Optional[int] = None latest_version: typing.Optional[PromptVersion] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_detail.py b/sdks/python/src/opik/rest_api/types/prompt_detail.py index 95d729f0b2..16b8fd343f 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_detail.py +++ b/sdks/python/src/opik/rest_api/types/prompt_detail.py @@ -1,14 +1,14 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt from .prompt_version_detail import PromptVersionDetail +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class PromptDetail(pydantic_v1.BaseModel): +class PromptDetail(UniversalBaseModel): id: typing.Optional[str] = None name: str description: typing.Optional[str] = None @@ -19,33 +19,13 @@ class PromptDetail(pydantic_v1.BaseModel): version_count: typing.Optional[int] = None latest_version: typing.Optional[PromptVersionDetail] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_page_public.py b/sdks/python/src/opik/rest_api/types/prompt_page_public.py index 66c3d8488a..93848a0d79 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_page_public.py +++ b/sdks/python/src/opik/rest_api/types/prompt_page_public.py @@ -1,46 +1,25 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .prompt_public import PromptPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class PromptPagePublic(pydantic_v1.BaseModel): +class PromptPagePublic(UniversalBaseModel): page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None content: typing.Optional[typing.List[PromptPublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_public.py b/sdks/python/src/opik/rest_api/types/prompt_public.py index 45b674ac72..93c0224439 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_public.py +++ b/sdks/python/src/opik/rest_api/types/prompt_public.py @@ -1,13 +1,13 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class PromptPublic(pydantic_v1.BaseModel): +class PromptPublic(UniversalBaseModel): id: typing.Optional[str] = None name: str description: typing.Optional[str] = None @@ -17,33 +17,13 @@ class PromptPublic(pydantic_v1.BaseModel): last_updated_by: typing.Optional[str] = None version_count: typing.Optional[int] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_version.py b/sdks/python/src/opik/rest_api/types/prompt_version.py index a505b075d9..d84e1343b7 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_version.py +++ b/sdks/python/src/opik/rest_api/types/prompt_version.py @@ -1,20 +1,20 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import pydantic +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class PromptVersion(pydantic_v1.BaseModel): - id: typing.Optional[str] = pydantic_v1.Field(default=None) +class PromptVersion(UniversalBaseModel): + id: typing.Optional[str] = pydantic.Field(default=None) """ version unique identifier, generated if absent """ prompt_id: typing.Optional[str] = None - commit: typing.Optional[str] = pydantic_v1.Field(default=None) + commit: typing.Optional[str] = pydantic.Field(default=None) """ version short unique identifier, generated if absent. it must be 8 characters long """ @@ -24,33 +24,13 @@ class PromptVersion(pydantic_v1.BaseModel): created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_version_detail.py b/sdks/python/src/opik/rest_api/types/prompt_version_detail.py index 4e9c79490c..983645e4fe 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_version_detail.py +++ b/sdks/python/src/opik/rest_api/types/prompt_version_detail.py @@ -1,20 +1,20 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import pydantic +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class PromptVersionDetail(pydantic_v1.BaseModel): - id: typing.Optional[str] = pydantic_v1.Field(default=None) +class PromptVersionDetail(UniversalBaseModel): + id: typing.Optional[str] = pydantic.Field(default=None) """ version unique identifier, generated if absent """ prompt_id: typing.Optional[str] = None - commit: typing.Optional[str] = pydantic_v1.Field(default=None) + commit: typing.Optional[str] = pydantic.Field(default=None) """ version short unique identifier, generated if absent. it must be 8 characters long """ @@ -24,33 +24,13 @@ class PromptVersionDetail(pydantic_v1.BaseModel): created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_version_link.py b/sdks/python/src/opik/rest_api/types/prompt_version_link.py index bc4934c193..c61a969f0e 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_version_link.py +++ b/sdks/python/src/opik/rest_api/types/prompt_version_link.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class PromptVersionLink(pydantic_v1.BaseModel): +class PromptVersionLink(UniversalBaseModel): id: str commit: typing.Optional[str] = None prompt_id: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_version_link_public.py b/sdks/python/src/opik/rest_api/types/prompt_version_link_public.py index 4fb8518a2d..e937f66c35 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_version_link_public.py +++ b/sdks/python/src/opik/rest_api/types/prompt_version_link_public.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class PromptVersionLinkPublic(pydantic_v1.BaseModel): +class PromptVersionLinkPublic(UniversalBaseModel): id: str commit: typing.Optional[str] = None prompt_id: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_version_link_write.py b/sdks/python/src/opik/rest_api/types/prompt_version_link_write.py index 6f535712df..d716721244 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_version_link_write.py +++ b/sdks/python/src/opik/rest_api/types/prompt_version_link_write.py @@ -1,42 +1,21 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel +from ..core.pydantic_utilities import IS_PYDANTIC_V2 import typing +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class PromptVersionLinkWrite(pydantic_v1.BaseModel): +class PromptVersionLinkWrite(UniversalBaseModel): id: str - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_version_page_public.py b/sdks/python/src/opik/rest_api/types/prompt_version_page_public.py index c33d836115..f203590c0d 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_version_page_public.py +++ b/sdks/python/src/opik/rest_api/types/prompt_version_page_public.py @@ -1,46 +1,25 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .prompt_version_public import PromptVersionPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class PromptVersionPagePublic(pydantic_v1.BaseModel): +class PromptVersionPagePublic(UniversalBaseModel): page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None content: typing.Optional[typing.List[PromptVersionPublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/prompt_version_public.py b/sdks/python/src/opik/rest_api/types/prompt_version_public.py index 8b2c36d181..eb9ef705a8 100644 --- a/sdks/python/src/opik/rest_api/types/prompt_version_public.py +++ b/sdks/python/src/opik/rest_api/types/prompt_version_public.py @@ -1,20 +1,20 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import pydantic +import datetime as dt +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class PromptVersionPublic(pydantic_v1.BaseModel): - id: typing.Optional[str] = pydantic_v1.Field(default=None) +class PromptVersionPublic(UniversalBaseModel): + id: typing.Optional[str] = pydantic.Field(default=None) """ version unique identifier, generated if absent """ prompt_id: typing.Optional[str] = None - commit: typing.Optional[str] = pydantic_v1.Field(default=None) + commit: typing.Optional[str] = pydantic.Field(default=None) """ version short unique identifier, generated if absent. it must be 8 characters long """ @@ -23,33 +23,13 @@ class PromptVersionPublic(pydantic_v1.BaseModel): created_at: typing.Optional[dt.datetime] = None created_by: typing.Optional[str] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/results_public.py b/sdks/python/src/opik/rest_api/types/results_public.py index 79c865abe1..4afb9bff93 100644 --- a/sdks/python/src/opik/rest_api/types/results_public.py +++ b/sdks/python/src/opik/rest_api/types/results_public.py @@ -1,44 +1,23 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .data_point_public import DataPointPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class ResultsPublic(pydantic_v1.BaseModel): +class ResultsPublic(UniversalBaseModel): name: typing.Optional[str] = None data: typing.Optional[typing.List[DataPointPublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/span.py b/sdks/python/src/opik/rest_api/types/span.py index 09f3aa13ad..a9d420b9b9 100644 --- a/sdks/python/src/opik/rest_api/types/span.py +++ b/sdks/python/src/opik/rest_api/types/span.py @@ -1,18 +1,18 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .feedback_score import FeedbackScore -from .json_node import JsonNode +import pydantic from .span_type import SpanType +import datetime as dt +from .json_node import JsonNode +from .feedback_score import FeedbackScore +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class Span(pydantic_v1.BaseModel): +class Span(UniversalBaseModel): id: typing.Optional[str] = None - project_name: typing.Optional[str] = pydantic_v1.Field(default=None) + project_name: typing.Optional[str] = pydantic.Field(default=None) """ If null, the default project is used """ @@ -38,33 +38,13 @@ class Span(pydantic_v1.BaseModel): feedback_scores: typing.Optional[typing.List[FeedbackScore]] = None total_estimated_cost: typing.Optional[float] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/span_batch.py b/sdks/python/src/opik/rest_api/types/span_batch.py index 3e4d287c28..714f1d54b9 100644 --- a/sdks/python/src/opik/rest_api/types/span_batch.py +++ b/sdks/python/src/opik/rest_api/types/span_batch.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .span import Span +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class SpanBatch(pydantic_v1.BaseModel): +class SpanBatch(UniversalBaseModel): spans: typing.List[Span] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/span_page_public.py b/sdks/python/src/opik/rest_api/types/span_page_public.py index a05b903006..487cd5e5e6 100644 --- a/sdks/python/src/opik/rest_api/types/span_page_public.py +++ b/sdks/python/src/opik/rest_api/types/span_page_public.py @@ -1,46 +1,25 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .span_public import SpanPublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class SpanPagePublic(pydantic_v1.BaseModel): +class SpanPagePublic(UniversalBaseModel): page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None content: typing.Optional[typing.List[SpanPublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/span_public.py b/sdks/python/src/opik/rest_api/types/span_public.py index 098eb648a0..c99621ade7 100644 --- a/sdks/python/src/opik/rest_api/types/span_public.py +++ b/sdks/python/src/opik/rest_api/types/span_public.py @@ -1,16 +1,16 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .feedback_score_public import FeedbackScorePublic -from .json_node_public import JsonNodePublic from .span_public_type import SpanPublicType +import datetime as dt +from .json_node_public import JsonNodePublic +from .feedback_score_public import FeedbackScorePublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class SpanPublic(pydantic_v1.BaseModel): +class SpanPublic(UniversalBaseModel): id: typing.Optional[str] = None project_id: typing.Optional[str] = None trace_id: str @@ -33,33 +33,13 @@ class SpanPublic(pydantic_v1.BaseModel): feedback_scores: typing.Optional[typing.List[FeedbackScorePublic]] = None total_estimated_cost: typing.Optional[float] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/span_write.py b/sdks/python/src/opik/rest_api/types/span_write.py index 819d431c89..9cb7a3bea4 100644 --- a/sdks/python/src/opik/rest_api/types/span_write.py +++ b/sdks/python/src/opik/rest_api/types/span_write.py @@ -1,17 +1,17 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .json_node_write import JsonNodeWrite +import pydantic from .span_write_type import SpanWriteType +import datetime as dt +from .json_node_write import JsonNodeWrite +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class SpanWrite(pydantic_v1.BaseModel): +class SpanWrite(UniversalBaseModel): id: typing.Optional[str] = None - project_name: typing.Optional[str] = pydantic_v1.Field(default=None) + project_name: typing.Optional[str] = pydantic.Field(default=None) """ If null, the default project is used """ @@ -30,33 +30,13 @@ class SpanWrite(pydantic_v1.BaseModel): tags: typing.Optional[typing.List[str]] = None usage: typing.Optional[typing.Dict[str, int]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/trace.py b/sdks/python/src/opik/rest_api/types/trace.py index 272635ed26..08c0e1efd1 100644 --- a/sdks/python/src/opik/rest_api/types/trace.py +++ b/sdks/python/src/opik/rest_api/types/trace.py @@ -1,17 +1,17 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .feedback_score import FeedbackScore +import pydantic +import datetime as dt from .json_node import JsonNode +from .feedback_score import FeedbackScore +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class Trace(pydantic_v1.BaseModel): +class Trace(UniversalBaseModel): id: typing.Optional[str] = None - project_name: typing.Optional[str] = pydantic_v1.Field(default=None) + project_name: typing.Optional[str] = pydantic.Field(default=None) """ If null, the default project is used """ @@ -31,33 +31,13 @@ class Trace(pydantic_v1.BaseModel): last_updated_by: typing.Optional[str] = None feedback_scores: typing.Optional[typing.List[FeedbackScore]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/trace_batch.py b/sdks/python/src/opik/rest_api/types/trace_batch.py index 51a78ff261..2a6707cf77 100644 --- a/sdks/python/src/opik/rest_api/types/trace_batch.py +++ b/sdks/python/src/opik/rest_api/types/trace_batch.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .trace import Trace +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class TraceBatch(pydantic_v1.BaseModel): +class TraceBatch(UniversalBaseModel): traces: typing.List[Trace] - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/trace_count_response.py b/sdks/python/src/opik/rest_api/types/trace_count_response.py index 0bb8d1f0b9..319dc99f0b 100644 --- a/sdks/python/src/opik/rest_api/types/trace_count_response.py +++ b/sdks/python/src/opik/rest_api/types/trace_count_response.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .workspace_trace_count import WorkspaceTraceCount +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class TraceCountResponse(pydantic_v1.BaseModel): +class TraceCountResponse(UniversalBaseModel): workspaces_traces_count: typing.Optional[typing.List[WorkspaceTraceCount]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/trace_page_public.py b/sdks/python/src/opik/rest_api/types/trace_page_public.py index a5ae6ab6c9..3ea4c594b2 100644 --- a/sdks/python/src/opik/rest_api/types/trace_page_public.py +++ b/sdks/python/src/opik/rest_api/types/trace_page_public.py @@ -1,46 +1,25 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .trace_public import TracePublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class TracePagePublic(pydantic_v1.BaseModel): +class TracePagePublic(UniversalBaseModel): page: typing.Optional[int] = None size: typing.Optional[int] = None total: typing.Optional[int] = None content: typing.Optional[typing.List[TracePublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/trace_public.py b/sdks/python/src/opik/rest_api/types/trace_public.py index cdff1ec876..bdfab3e763 100644 --- a/sdks/python/src/opik/rest_api/types/trace_public.py +++ b/sdks/python/src/opik/rest_api/types/trace_public.py @@ -1,15 +1,15 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 -from .feedback_score_public import FeedbackScorePublic +import datetime as dt from .json_node_public import JsonNodePublic +from .feedback_score_public import FeedbackScorePublic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -class TracePublic(pydantic_v1.BaseModel): +class TracePublic(UniversalBaseModel): id: typing.Optional[str] = None project_id: typing.Optional[str] = None name: str @@ -26,33 +26,13 @@ class TracePublic(pydantic_v1.BaseModel): last_updated_by: typing.Optional[str] = None feedback_scores: typing.Optional[typing.List[FeedbackScorePublic]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/trace_write.py b/sdks/python/src/opik/rest_api/types/trace_write.py index 3d06797884..be5fd5dc8b 100644 --- a/sdks/python/src/opik/rest_api/types/trace_write.py +++ b/sdks/python/src/opik/rest_api/types/trace_write.py @@ -1,16 +1,16 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing - -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 +import pydantic +import datetime as dt from .json_node_write import JsonNodeWrite +from ..core.pydantic_utilities import IS_PYDANTIC_V2 -class TraceWrite(pydantic_v1.BaseModel): +class TraceWrite(UniversalBaseModel): id: typing.Optional[str] = None - project_name: typing.Optional[str] = pydantic_v1.Field(default=None) + project_name: typing.Optional[str] = pydantic.Field(default=None) """ If null, the default project is used """ @@ -23,33 +23,13 @@ class TraceWrite(pydantic_v1.BaseModel): metadata: typing.Optional[JsonNodeWrite] = None tags: typing.Optional[typing.List[str]] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/sdks/python/src/opik/rest_api/types/workspace_trace_count.py b/sdks/python/src/opik/rest_api/types/workspace_trace_count.py index bbd8957d21..18c3d2a835 100644 --- a/sdks/python/src/opik/rest_api/types/workspace_trace_count.py +++ b/sdks/python/src/opik/rest_api/types/workspace_trace_count.py @@ -1,43 +1,22 @@ # This file was auto-generated by Fern from our API Definition. -import datetime as dt +from ..core.pydantic_utilities import UniversalBaseModel import typing +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +import pydantic -from ..core.datetime_utils import serialize_datetime -from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 - -class WorkspaceTraceCount(pydantic_v1.BaseModel): +class WorkspaceTraceCount(UniversalBaseModel): workspace: typing.Optional[str] = None trace_count: typing.Optional[int] = None - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = { - "by_alias": True, - "exclude_unset": True, - **kwargs, - } - kwargs_with_defaults_exclude_none: typing.Any = { - "by_alias": True, - "exclude_none": True, - **kwargs, - } - - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), - super().dict(**kwargs_with_defaults_exclude_none), - ) + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( + extra="allow", frozen=True + ) # type: ignore # Pydantic v2 + else: - class Config: - frozen = True - smart_union = True - extra = pydantic_v1.Extra.allow - json_encoders = {dt.datetime: serialize_datetime} + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow