From 66f5e146cc6d0246adfe17b136f107bbacf47f22 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:45:49 +0000 Subject: [PATCH 1/2] SDK regeneration --- .mock/definition/__package__.yml | 16 +++++++ .mock/definition/prompts/versions.yml | 12 ++--- poetry.lock | 14 +++--- src/label_studio_sdk/__init__.py | 2 + .../prompts/versions/client.py | 13 ++--- src/label_studio_sdk/types/__init__.py | 2 + .../types/refined_prompt_response.py | 47 +++++++++++++++++++ tests/prompts/test_versions.py | 23 ++------- 8 files changed, 87 insertions(+), 42 deletions(-) create mode 100644 src/label_studio_sdk/types/refined_prompt_response.py diff --git a/.mock/definition/__package__.yml b/.mock/definition/__package__.yml index ae77adcd4..9f24749a8 100644 --- a/.mock/definition/__package__.yml +++ b/.mock/definition/__package__.yml @@ -2347,6 +2347,22 @@ types: organization: optional source: openapi: openapi/openapi.yaml + RefinedPromptResponse: + properties: + title: + type: string + docs: Title of the refined prompt + reasoning: + type: string + docs: Reasoning behind the refinement + prompt: + type: string + docs: The refined prompt text + refinement_job_id: + type: string + docs: Unique identifier for the refinement job + source: + openapi: openapi/openapi.yaml InferenceRunOrganization: discriminated: false union: diff --git a/.mock/definition/prompts/versions.yml b/.mock/definition/prompts/versions.yml index 4e0df35d4..2decea25d 100644 --- a/.mock/definition/prompts/versions.yml +++ b/.mock/definition/prompts/versions.yml @@ -192,7 +192,7 @@ service: docs: Project ID to target the refined prompt for response: docs: '' - type: root.PromptVersion + type: root.RefinedPromptResponse examples: - path-parameters: prompt_id: 1 @@ -201,15 +201,9 @@ service: response: body: title: title - parent_model: 1 - model_provider_connection: 1 + reasoning: reasoning prompt: prompt - provider: OpenAI - provider_model_id: provider_model_id - created_by: 1 - created_at: '2024-01-15T09:30:00Z' - updated_at: '2024-01-15T09:30:00Z' - organization: 1 + refinement_job_id: refinement_job_id audiences: - public source: diff --git a/poetry.lock b/poetry.lock index 864798fe0..ec01a31f7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1426,13 +1426,13 @@ files = [ [[package]] name = "tomli" -version = "2.0.1" +version = "2.0.2" description = "A lil' TOML parser" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, - {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, + {file = "tomli-2.0.2-py3-none-any.whl", hash = "sha256:2ebe24485c53d303f690b0ec092806a085f07af5a5aa1464f3931eec36caaa38"}, + {file = "tomli-2.0.2.tar.gz", hash = "sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed"}, ] [[package]] @@ -1457,13 +1457,13 @@ telegram = ["requests"] [[package]] name = "types-python-dateutil" -version = "2.9.0.20240906" +version = "2.9.0.20241003" description = "Typing stubs for python-dateutil" optional = false python-versions = ">=3.8" files = [ - {file = "types-python-dateutil-2.9.0.20240906.tar.gz", hash = "sha256:9706c3b68284c25adffc47319ecc7947e5bb86b3773f843c73906fd598bc176e"}, - {file = "types_python_dateutil-2.9.0.20240906-py3-none-any.whl", hash = "sha256:27c8cc2d058ccb14946eebcaaa503088f4f6dbc4fb6093d3d456a49aef2753f6"}, + {file = "types-python-dateutil-2.9.0.20241003.tar.gz", hash = "sha256:58cb85449b2a56d6684e41aeefb4c4280631246a0da1a719bdbe6f3fb0317446"}, + {file = "types_python_dateutil-2.9.0.20241003-py3-none-any.whl", hash = "sha256:250e1d8e80e7bbc3a6c99b907762711d1a1cdd00e978ad39cb5940f6f0a87f3d"}, ] [[package]] diff --git a/src/label_studio_sdk/__init__.py b/src/label_studio_sdk/__init__.py index c0829e6c8..2e46761f7 100644 --- a/src/label_studio_sdk/__init__.py +++ b/src/label_studio_sdk/__init__.py @@ -74,6 +74,7 @@ RedisExportStorageStatus, RedisImportStorage, RedisImportStorageStatus, + RefinedPromptResponse, S3ExportStorage, S3ExportStorageStatus, S3ImportStorage, @@ -275,6 +276,7 @@ "RedisExportStorageStatus", "RedisImportStorage", "RedisImportStorageStatus", + "RefinedPromptResponse", "S3ExportStorage", "S3ExportStorageStatus", "S3ImportStorage", diff --git a/src/label_studio_sdk/prompts/versions/client.py b/src/label_studio_sdk/prompts/versions/client.py index c0c65062d..061752028 100644 --- a/src/label_studio_sdk/prompts/versions/client.py +++ b/src/label_studio_sdk/prompts/versions/client.py @@ -13,6 +13,7 @@ from ...types.prompt_version_created_by import PromptVersionCreatedBy from ...types.prompt_version_organization import PromptVersionOrganization from ...types.prompt_version_provider import PromptVersionProvider +from ...types.refined_prompt_response import RefinedPromptResponse # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -344,7 +345,7 @@ def refine_prompt( teacher_model_name: typing.Optional[str] = OMIT, project_id: typing.Optional[int] = OMIT, request_options: typing.Optional[RequestOptions] = None, - ) -> PromptVersion: + ) -> RefinedPromptResponse: """ Refine a prompt version using a teacher model and save the refined prompt as a new version. @@ -370,7 +371,7 @@ def refine_prompt( Returns ------- - PromptVersion + RefinedPromptResponse Examples @@ -398,7 +399,7 @@ def refine_prompt( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptVersion, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(RefinedPromptResponse, _response.json()) # type: ignore _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -735,7 +736,7 @@ async def refine_prompt( teacher_model_name: typing.Optional[str] = OMIT, project_id: typing.Optional[int] = OMIT, request_options: typing.Optional[RequestOptions] = None, - ) -> PromptVersion: + ) -> RefinedPromptResponse: """ Refine a prompt version using a teacher model and save the refined prompt as a new version. @@ -761,7 +762,7 @@ async def refine_prompt( Returns ------- - PromptVersion + RefinedPromptResponse Examples @@ -789,7 +790,7 @@ async def refine_prompt( ) try: if 200 <= _response.status_code < 300: - return pydantic_v1.parse_obj_as(PromptVersion, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(RefinedPromptResponse, _response.json()) # type: ignore _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/src/label_studio_sdk/types/__init__.py b/src/label_studio_sdk/types/__init__.py index 63b00095e..3b5316d3c 100644 --- a/src/label_studio_sdk/types/__init__.py +++ b/src/label_studio_sdk/types/__init__.py @@ -73,6 +73,7 @@ from .redis_export_storage_status import RedisExportStorageStatus from .redis_import_storage import RedisImportStorage from .redis_import_storage_status import RedisImportStorageStatus +from .refined_prompt_response import RefinedPromptResponse from .s3export_storage import S3ExportStorage from .s3export_storage_status import S3ExportStorageStatus from .s3import_storage import S3ImportStorage @@ -167,6 +168,7 @@ "RedisExportStorageStatus", "RedisImportStorage", "RedisImportStorageStatus", + "RefinedPromptResponse", "S3ExportStorage", "S3ExportStorageStatus", "S3ImportStorage", diff --git a/src/label_studio_sdk/types/refined_prompt_response.py b/src/label_studio_sdk/types/refined_prompt_response.py new file mode 100644 index 000000000..1b37313f1 --- /dev/null +++ b/src/label_studio_sdk/types/refined_prompt_response.py @@ -0,0 +1,47 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 + + +class RefinedPromptResponse(pydantic_v1.BaseModel): + title: str = pydantic_v1.Field() + """ + Title of the refined prompt + """ + + reasoning: str = pydantic_v1.Field() + """ + Reasoning behind the refinement + """ + + prompt: str = pydantic_v1.Field() + """ + The refined prompt text + """ + + refinement_job_id: str = pydantic_v1.Field() + """ + Unique identifier for the refinement job + """ + + 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 + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/tests/prompts/test_versions.py b/tests/prompts/test_versions.py index 585e5a9c9..1226b91a0 100644 --- a/tests/prompts/test_versions.py +++ b/tests/prompts/test_versions.py @@ -152,28 +152,11 @@ async def test_update(client: LabelStudio, async_client: AsyncLabelStudio) -> No async def test_refine_prompt(client: LabelStudio, async_client: AsyncLabelStudio) -> None: expected_response: typing.Any = { "title": "title", - "parent_model": 1, - "model_provider_connection": 1, + "reasoning": "reasoning", "prompt": "prompt", - "provider": "OpenAI", - "provider_model_id": "provider_model_id", - "created_by": 1, - "created_at": "2024-01-15T09:30:00Z", - "updated_at": "2024-01-15T09:30:00Z", - "organization": 1, - } - expected_types: typing.Any = { - "title": None, - "parent_model": "integer", - "model_provider_connection": "integer", - "prompt": None, - "provider": None, - "provider_model_id": None, - "created_by": "integer", - "created_at": "datetime", - "updated_at": "datetime", - "organization": "integer", + "refinement_job_id": "refinement_job_id", } + expected_types: typing.Any = {"title": None, "reasoning": None, "prompt": None, "refinement_job_id": None} response = client.prompts.versions.refine_prompt(prompt_id=1, version_id=1) validate_response(response, expected_response, expected_types) From a01b540ec610089473b44e63afcdf7dff6064852 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:51:33 +0000 Subject: [PATCH 2/2] SDK regeneration