From 5427b5646f1f2ce8a2bab1765f21a6efe05ffcac Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:25:19 +0000 Subject: [PATCH] chore(internal): codegen related update (#37) --- .github/workflows/release-doctor.yml | 2 ++ README.md | 8 +++++++- src/writerai/_base_client.py | 12 ++++++------ src/writerai/_compat.py | 6 +++--- src/writerai/types/file_upload_params.py | 2 -- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index 93c5ed1..43d314d 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -1,6 +1,8 @@ name: Release Doctor on: pull_request: + branches: + - main workflow_dispatch: jobs: diff --git a/README.md b/README.md index 7945f56..d08939d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It is generated with [Stainless](https://www.stainlessapi.com/). ## Documentation -The REST API documentation can be found [on dev.writer.com](https://dev.writer.com/api-guides/introduction). The full API of this library can be found in [api.md](api.md). +The REST API documentation can be found on [dev.writer.com](https://dev.writer.com/api-guides/introduction). The full API of this library can be found in [api.md](api.md). ## Installation @@ -372,6 +372,12 @@ client = Writer( ) ``` +You can also customize the client on a per-request basis by using `with_options()`: + +```python +client.with_options(http_client=DefaultHttpxClient(...)) +``` + ### Managing HTTP resources By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting. diff --git a/src/writerai/_base_client.py b/src/writerai/_base_client.py index 920075c..2315f57 100644 --- a/src/writerai/_base_client.py +++ b/src/writerai/_base_client.py @@ -879,9 +879,9 @@ def __exit__( def _prepare_options( self, options: FinalRequestOptions, # noqa: ARG002 - ) -> None: + ) -> FinalRequestOptions: """Hook for mutating the given options""" - return None + return options def _prepare_request( self, @@ -961,7 +961,7 @@ def _request( input_options = model_copy(options) cast_to = self._maybe_override_cast_to(cast_to, options) - self._prepare_options(options) + options = self._prepare_options(options) retries = self._remaining_retries(remaining_retries, options) request = self._build_request(options) @@ -1442,9 +1442,9 @@ async def __aexit__( async def _prepare_options( self, options: FinalRequestOptions, # noqa: ARG002 - ) -> None: + ) -> FinalRequestOptions: """Hook for mutating the given options""" - return None + return options async def _prepare_request( self, @@ -1529,7 +1529,7 @@ async def _request( input_options = model_copy(options) cast_to = self._maybe_override_cast_to(cast_to, options) - await self._prepare_options(options) + options = await self._prepare_options(options) retries = self._remaining_retries(remaining_retries, options) request = self._build_request(options) diff --git a/src/writerai/_compat.py b/src/writerai/_compat.py index 74c7639..c919b5a 100644 --- a/src/writerai/_compat.py +++ b/src/writerai/_compat.py @@ -118,10 +118,10 @@ def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]: return model.__fields__ # type: ignore -def model_copy(model: _ModelT) -> _ModelT: +def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT: if PYDANTIC_V2: - return model.model_copy() - return model.copy() # type: ignore + return model.model_copy(deep=deep) + return model.copy(deep=deep) # type: ignore def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str: diff --git a/src/writerai/types/file_upload_params.py b/src/writerai/types/file_upload_params.py index 4a47b72..14077b9 100644 --- a/src/writerai/types/file_upload_params.py +++ b/src/writerai/types/file_upload_params.py @@ -15,6 +15,4 @@ class FileUploadParams(TypedDict, total=False): content_disposition: Required[Annotated[str, PropertyInfo(alias="Content-Disposition")]] - content_length: Required[Annotated[int, PropertyInfo(alias="Content-Length")]] - content_type: Required[Annotated[str, PropertyInfo(alias="Content-Type")]]