diff --git a/.release-please-manifest.json b/.release-please-manifest.json index f1d45d57..e7a306f4 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.3.2-rc1" + ".": "2.3.2-rc2" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 1822dc87..b3d54722 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 33 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-3f87c8deb39e443022f2e04252994a6c9d25473872503edf9eec00d874576b2d.yml -openapi_spec_hash: 5de52bf1d78e00b13a04f6e9ce2f2fb5 -config_hash: 7a38bab086b53b43d2a719cb4d883264 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-4ec783072dd7f57c6e021a746df7650fb8d7a164d8ec25c7d5cab06c33bc114f.yml +openapi_spec_hash: ceab065d515f3681b0c33137da308968 +config_hash: 089fd5502b9cf91247887b19117f1ca2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cbcdb5b..18f25547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ # Changelog +## 2.3.2-rc2 (2025-10-01) + +Full Changelog: [v2.3.2-rc1...v2.3.2-rc2](https://github.com/writer/writer-python/compare/v2.3.2-rc1...v2.3.2-rc2) + +### Features + +* **api:** manual updates ([4fb84e2](https://github.com/writer/writer-python/commit/4fb84e2d911b8a32a2fc34bb88bcd7ac7b15d2f2)) +* **api:** manual updates ([d7b4637](https://github.com/writer/writer-python/commit/d7b463727d2d9b3cd90fcab9e7d5376a3d5a1a38)) + + +### Chores + +* do not install brew dependencies in ./scripts/bootstrap by default ([7912ae2](https://github.com/writer/writer-python/commit/7912ae28b073194868bbcdc59bbff92b49a50f60)) +* **internal:** update pydantic dependency ([c2f8537](https://github.com/writer/writer-python/commit/c2f85373ed1ed9e0e80a3b3d182794dc619d8b87)) +* **types:** change optional parameter type from NotGiven to Omit ([702d003](https://github.com/writer/writer-python/commit/702d003ebd5c955986898f7afadc425f9a9c4fd1)) +* update more locations to use Omit ([5f1a99c](https://github.com/writer/writer-python/commit/5f1a99c3546308523ce977ce3bf1f145209ad44b)) + + +### Documentation + +* **api:** updates to API spec ([7e349a9](https://github.com/writer/writer-python/commit/7e349a9c9782b10803ef932ee7eaf9c618750d2b)) + ## 2.3.2-rc1 (2025-09-11) Full Changelog: [v2.3.1...v2.3.2-rc1](https://github.com/writer/writer-python/compare/v2.3.1...v2.3.2-rc1) diff --git a/pyproject.toml b/pyproject.toml index 6dc6a4bc..59fe6fa8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "writer-sdk" -version = "2.3.2-rc1" +version = "2.3.2-rc2" description = "The official Python library for the writer API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/requirements-dev.lock b/requirements-dev.lock index 7c31b2f7..ad44866d 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -96,9 +96,9 @@ pluggy==1.5.0 propcache==0.3.1 # via aiohttp # via yarl -pydantic==2.10.3 +pydantic==2.11.9 # via writer-sdk -pydantic-core==2.27.1 +pydantic-core==2.33.2 # via pydantic pygments==2.18.0 # via rich @@ -135,7 +135,10 @@ typing-extensions==4.12.2 # via pydantic # via pydantic-core # via pyright + # via typing-inspection # via writer-sdk +typing-inspection==0.4.1 + # via pydantic virtualenv==20.24.5 # via nox yarl==1.20.0 diff --git a/requirements.lock b/requirements.lock index 87f0c543..466a8f8d 100644 --- a/requirements.lock +++ b/requirements.lock @@ -57,9 +57,9 @@ multidict==6.4.4 propcache==0.3.1 # via aiohttp # via yarl -pydantic==2.10.3 +pydantic==2.11.9 # via writer-sdk -pydantic-core==2.27.1 +pydantic-core==2.33.2 # via pydantic sniffio==1.3.0 # via anyio @@ -69,6 +69,9 @@ typing-extensions==4.12.2 # via multidict # via pydantic # via pydantic-core + # via typing-inspection # via writer-sdk +typing-inspection==0.4.1 + # via pydantic yarl==1.20.0 # via aiohttp diff --git a/scripts/bootstrap b/scripts/bootstrap index e84fe62c..b430fee3 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -4,10 +4,18 @@ set -e cd "$(dirname "$0")/.." -if ! command -v rye >/dev/null 2>&1 && [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then +if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then brew bundle check >/dev/null 2>&1 || { - echo "==> Installing Homebrew dependencies…" - brew bundle + echo -n "==> Install Homebrew dependencies? (y/N): " + read -r response + case "$response" in + [yY][eE][sS]|[yY]) + brew bundle + ;; + *) + ;; + esac + echo } fi diff --git a/src/writerai/__init__.py b/src/writerai/__init__.py index 6a6582e3..bd174b56 100644 --- a/src/writerai/__init__.py +++ b/src/writerai/__init__.py @@ -3,7 +3,7 @@ import typing as _t from . import types -from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes +from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes, omit, not_given from ._utils import file_from_path from ._client import Client, Stream, Writer, Timeout, Transport, AsyncClient, AsyncStream, AsyncWriter, RequestOptions from ._models import BaseModel @@ -41,7 +41,9 @@ "ProxiesTypes", "NotGiven", "NOT_GIVEN", + "not_given", "Omit", + "omit", "WriterError", "APIError", "APIStatusError", diff --git a/src/writerai/_base_client.py b/src/writerai/_base_client.py index a4c4b639..bf5efcbe 100644 --- a/src/writerai/_base_client.py +++ b/src/writerai/_base_client.py @@ -42,7 +42,6 @@ from ._qs import Querystring from ._files import to_httpx_files, _transform_file, get_file_content, async_to_httpx_files, _async_transform_file from ._types import ( - NOT_GIVEN, Body, Omit, Query, @@ -58,6 +57,7 @@ RequestOptions, HttpxRequestFiles, ModelBuilderProtocol, + not_given, ) from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping from ._compat import PYDANTIC_V1, model_copy, model_dump @@ -146,9 +146,9 @@ def __init__( def __init__( self, *, - url: URL | NotGiven = NOT_GIVEN, - json: Body | NotGiven = NOT_GIVEN, - params: Query | NotGiven = NOT_GIVEN, + url: URL | NotGiven = not_given, + json: Body | NotGiven = not_given, + params: Query | NotGiven = not_given, ) -> None: self.url = url self.json = json @@ -598,7 +598,7 @@ def _maybe_override_cast_to(self, cast_to: type[ResponseT], options: FinalReques # we internally support defining a temporary header to override the # default `cast_to` type for use with `.with_raw_response` and `.with_streaming_response` # see _response.py for implementation details - override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, NOT_GIVEN) + override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, not_given) if is_given(override_cast_to): options.headers = headers return cast(Type[ResponseT], override_cast_to) @@ -828,7 +828,7 @@ def __init__( version: str, base_url: str | URL, max_retries: int = DEFAULT_MAX_RETRIES, - timeout: float | Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | Timeout | None | NotGiven = not_given, http_client: httpx.Client | None = None, custom_headers: Mapping[str, str] | None = None, custom_query: Mapping[str, object] | None = None, @@ -1368,7 +1368,7 @@ def __init__( base_url: str | URL, _strict_response_validation: bool, max_retries: int = DEFAULT_MAX_RETRIES, - timeout: float | Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | Timeout | None | NotGiven = not_given, http_client: httpx.AsyncClient | None = None, custom_headers: Mapping[str, str] | None = None, custom_query: Mapping[str, object] | None = None, @@ -1839,8 +1839,8 @@ def make_request_options( extra_query: Query | None = None, extra_body: Body | None = None, idempotency_key: str | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - post_parser: PostParser | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + post_parser: PostParser | NotGiven = not_given, ) -> RequestOptions: """Create a dict of type RequestOptions without keys of NotGiven values.""" options: RequestOptions = {} diff --git a/src/writerai/_client.py b/src/writerai/_client.py index 0f9ef3b7..5d9aec84 100644 --- a/src/writerai/_client.py +++ b/src/writerai/_client.py @@ -3,7 +3,7 @@ from __future__ import annotations import os -from typing import Any, Union, Mapping +from typing import Any, Mapping from typing_extensions import Self, override import httpx @@ -12,13 +12,13 @@ from ._qs import Querystring from ._types import ( - NOT_GIVEN, Omit, Timeout, NotGiven, Transport, ProxiesTypes, RequestOptions, + not_given, ) from ._utils import is_given, get_async_library from ._version import __version__ @@ -87,7 +87,7 @@ def __init__( *, api_key: str | None = None, base_url: str | httpx.URL | None = None, - timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, + timeout: float | Timeout | None | NotGiven = not_given, max_retries: int = DEFAULT_MAX_RETRIES, default_headers: Mapping[str, str] | None = None, default_query: Mapping[str, object] | None = None, @@ -175,9 +175,9 @@ def copy( *, api_key: str | None = None, base_url: str | httpx.URL | None = None, - timeout: float | Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | Timeout | None | NotGiven = not_given, http_client: httpx.Client | None = None, - max_retries: int | NotGiven = NOT_GIVEN, + max_retries: int | NotGiven = not_given, default_headers: Mapping[str, str] | None = None, set_default_headers: Mapping[str, str] | None = None, default_query: Mapping[str, object] | None = None, @@ -276,7 +276,7 @@ def __init__( *, api_key: str | None = None, base_url: str | httpx.URL | None = None, - timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, + timeout: float | Timeout | None | NotGiven = not_given, max_retries: int = DEFAULT_MAX_RETRIES, default_headers: Mapping[str, str] | None = None, default_query: Mapping[str, object] | None = None, @@ -364,9 +364,9 @@ def copy( *, api_key: str | None = None, base_url: str | httpx.URL | None = None, - timeout: float | Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | Timeout | None | NotGiven = not_given, http_client: httpx.AsyncClient | None = None, - max_retries: int | NotGiven = NOT_GIVEN, + max_retries: int | NotGiven = not_given, default_headers: Mapping[str, str] | None = None, set_default_headers: Mapping[str, str] | None = None, default_query: Mapping[str, object] | None = None, diff --git a/src/writerai/_models.py b/src/writerai/_models.py index 057a807f..14fd47f0 100644 --- a/src/writerai/_models.py +++ b/src/writerai/_models.py @@ -257,7 +257,7 @@ def model_dump( mode: Literal["json", "python"] | str = "python", include: IncEx | None = None, exclude: IncEx | None = None, - by_alias: bool = False, + by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, @@ -265,6 +265,7 @@ def model_dump( warnings: bool | Literal["none", "warn", "error"] = True, context: dict[str, Any] | None = None, serialize_as_any: bool = False, + fallback: Callable[[Any], Any] | None = None, ) -> dict[str, Any]: """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump @@ -296,10 +297,12 @@ def model_dump( raise ValueError("context is only supported in Pydantic v2") if serialize_as_any != False: raise ValueError("serialize_as_any is only supported in Pydantic v2") + if fallback is not None: + raise ValueError("fallback is only supported in Pydantic v2") dumped = super().dict( # pyright: ignore[reportDeprecated] include=include, exclude=exclude, - by_alias=by_alias, + by_alias=by_alias if by_alias is not None else False, exclude_unset=exclude_unset, exclude_defaults=exclude_defaults, exclude_none=exclude_none, @@ -314,13 +317,14 @@ def model_dump_json( indent: int | None = None, include: IncEx | None = None, exclude: IncEx | None = None, - by_alias: bool = False, + by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: bool | Literal["none", "warn", "error"] = True, context: dict[str, Any] | None = None, + fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False, ) -> str: """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json @@ -349,11 +353,13 @@ def model_dump_json( raise ValueError("context is only supported in Pydantic v2") if serialize_as_any != False: raise ValueError("serialize_as_any is only supported in Pydantic v2") + if fallback is not None: + raise ValueError("fallback is only supported in Pydantic v2") return super().json( # type: ignore[reportDeprecated] indent=indent, include=include, exclude=exclude, - by_alias=by_alias, + by_alias=by_alias if by_alias is not None else False, exclude_unset=exclude_unset, exclude_defaults=exclude_defaults, exclude_none=exclude_none, diff --git a/src/writerai/_qs.py b/src/writerai/_qs.py index 274320ca..ada6fd3f 100644 --- a/src/writerai/_qs.py +++ b/src/writerai/_qs.py @@ -4,7 +4,7 @@ from urllib.parse import parse_qs, urlencode from typing_extensions import Literal, get_args -from ._types import NOT_GIVEN, NotGiven, NotGivenOr +from ._types import NotGiven, not_given from ._utils import flatten _T = TypeVar("_T") @@ -41,8 +41,8 @@ def stringify( self, params: Params, *, - array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN, - nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN, + array_format: ArrayFormat | NotGiven = not_given, + nested_format: NestedFormat | NotGiven = not_given, ) -> str: return urlencode( self.stringify_items( @@ -56,8 +56,8 @@ def stringify_items( self, params: Params, *, - array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN, - nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN, + array_format: ArrayFormat | NotGiven = not_given, + nested_format: NestedFormat | NotGiven = not_given, ) -> list[tuple[str, str]]: opts = Options( qs=self, @@ -143,8 +143,8 @@ def __init__( self, qs: Querystring = _qs, *, - array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN, - nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN, + array_format: ArrayFormat | NotGiven = not_given, + nested_format: NestedFormat | NotGiven = not_given, ) -> None: self.array_format = qs.array_format if isinstance(array_format, NotGiven) else array_format self.nested_format = qs.nested_format if isinstance(nested_format, NotGiven) else nested_format diff --git a/src/writerai/_types.py b/src/writerai/_types.py index 31170df3..146fcfb6 100644 --- a/src/writerai/_types.py +++ b/src/writerai/_types.py @@ -117,18 +117,21 @@ class RequestOptions(TypedDict, total=False): # Sentinel class used until PEP 0661 is accepted class NotGiven: """ - A sentinel singleton class used to distinguish omitted keyword arguments - from those passed in with the value None (which may have different behavior). + For parameters with a meaningful None value, we need to distinguish between + the user explicitly passing None, and the user not passing the parameter at + all. + + User code shouldn't need to use not_given directly. For example: ```py - def get(timeout: Union[int, NotGiven, None] = NotGiven()) -> Response: ... + def create(timeout: Timeout | None | NotGiven = not_given): ... - get(timeout=1) # 1s timeout - get(timeout=None) # No timeout - get() # Default timeout behavior, which may not be statically known at the method definition. + create(timeout=1) # 1s timeout + create(timeout=None) # No timeout + create() # Default timeout behavior ``` """ @@ -140,13 +143,14 @@ def __repr__(self) -> str: return "NOT_GIVEN" -NotGivenOr = Union[_T, NotGiven] +not_given = NotGiven() +# for backwards compatibility: NOT_GIVEN = NotGiven() class Omit: - """In certain situations you need to be able to represent a case where a default value has - to be explicitly removed and `None` is not an appropriate substitute, for example: + """ + To explicitly omit something from being sent in a request, use `omit`. ```py # as the default `Content-Type` header is `application/json` that will be sent @@ -156,8 +160,8 @@ class Omit: # to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983' client.post(..., headers={"Content-Type": "multipart/form-data"}) - # instead you can remove the default `application/json` header by passing Omit - client.post(..., headers={"Content-Type": Omit()}) + # instead you can remove the default `application/json` header by passing omit + client.post(..., headers={"Content-Type": omit}) ``` """ @@ -165,6 +169,9 @@ def __bool__(self) -> Literal[False]: return False +omit = Omit() + + @runtime_checkable class ModelBuilderProtocol(Protocol): @classmethod diff --git a/src/writerai/_utils/_transform.py b/src/writerai/_utils/_transform.py index c19124f0..52075492 100644 --- a/src/writerai/_utils/_transform.py +++ b/src/writerai/_utils/_transform.py @@ -268,7 +268,7 @@ def _transform_typeddict( annotations = get_type_hints(expected_type, include_extras=True) for key, value in data.items(): if not is_given(value): - # we don't need to include `NotGiven` values here as they'll + # we don't need to include omitted values here as they'll # be stripped out before the request is sent anyway continue @@ -434,7 +434,7 @@ async def _async_transform_typeddict( annotations = get_type_hints(expected_type, include_extras=True) for key, value in data.items(): if not is_given(value): - # we don't need to include `NotGiven` values here as they'll + # we don't need to include omitted values here as they'll # be stripped out before the request is sent anyway continue diff --git a/src/writerai/_utils/_utils.py b/src/writerai/_utils/_utils.py index f0818595..50d59269 100644 --- a/src/writerai/_utils/_utils.py +++ b/src/writerai/_utils/_utils.py @@ -21,7 +21,7 @@ import sniffio -from .._types import NotGiven, FileTypes, NotGivenOr, HeadersLike +from .._types import Omit, NotGiven, FileTypes, HeadersLike _T = TypeVar("_T") _TupleT = TypeVar("_TupleT", bound=Tuple[object, ...]) @@ -63,7 +63,7 @@ def _extract_items( try: key = path[index] except IndexError: - if isinstance(obj, NotGiven): + if not is_given(obj): # no value was provided - we can safely ignore return [] @@ -126,8 +126,8 @@ def _extract_items( return [] -def is_given(obj: NotGivenOr[_T]) -> TypeGuard[_T]: - return not isinstance(obj, NotGiven) +def is_given(obj: _T | NotGiven | Omit) -> TypeGuard[_T]: + return not isinstance(obj, NotGiven) and not isinstance(obj, Omit) # Type safe methods for narrowing types with TypeVars. diff --git a/src/writerai/_version.py b/src/writerai/_version.py index 8269c8fb..2241a325 100644 --- a/src/writerai/_version.py +++ b/src/writerai/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "writerai" -__version__ = "2.3.2-rc1" # x-release-please-version +__version__ = "2.3.2-rc2" # x-release-please-version diff --git a/src/writerai/lib/_parsing/_completions.py b/src/writerai/lib/_parsing/_completions.py index 6788f4b0..e7a6be3c 100644 --- a/src/writerai/lib/_parsing/_completions.py +++ b/src/writerai/lib/_parsing/_completions.py @@ -7,7 +7,7 @@ import pydantic from .._tools import PydanticFunctionTool -from ..._types import NOT_GIVEN, NotGiven +from ..._types import Omit, omit from ..._utils import is_dict, is_given from ..._compat import PYDANTIC_V1, model_parse_json from ..._models import construct_type_unchecked @@ -35,7 +35,7 @@ def validate_input_tools( - tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, + tools: Iterable[ChatCompletionToolParam] | Omit = omit, ) -> None: if not is_given(tools): return @@ -55,8 +55,8 @@ def validate_input_tools( def parse_chat_completion( *, - response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, - input_tools: Iterable[ChatCompletionToolParam] | NotGiven, + response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, + input_tools: Iterable[ChatCompletionToolParam] | Omit, chat_completion: ChatCompletion | ParsedChatCompletion[object], ) -> ParsedChatCompletion[ResponseFormatT]: if is_given(input_tools): @@ -153,7 +153,7 @@ def parse_function_tool_arguments( def maybe_parse_content( *, - response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, + response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, message: ChatCompletionMessage | ParsedChatCompletionMessage[object], ) -> ResponseFormatT | None: if has_rich_response_format(response_format) and message.content and not message.refusal: @@ -163,7 +163,7 @@ def maybe_parse_content( def solve_response_format_t( - response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, + response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, ) -> type[ResponseFormatT]: """Return the runtime type for the given response format. @@ -178,8 +178,8 @@ def solve_response_format_t( def has_parseable_input( *, - response_format: type | ResponseFormatParam | NotGiven, - input_tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, + response_format: type | ResponseFormatParam | Omit, + input_tools: Iterable[ChatCompletionToolParam] | Omit = omit, ) -> bool: if has_rich_response_format(response_format): return True @@ -192,7 +192,7 @@ def has_parseable_input( def has_rich_response_format( - response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, + response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, ) -> TypeGuard[type[ResponseFormatT]]: if not is_given(response_format): return False @@ -229,10 +229,10 @@ def _parse_content(response_format: type[ResponseFormatT], content: str) -> Resp def type_to_response_format_param( - response_format: type | ResponseFormatParam | NotGiven, -) -> ResponseFormatParam | NotGiven: + response_format: type | ResponseFormatParam | Omit, +) -> ResponseFormatParam | Omit: if not is_given(response_format): - return NOT_GIVEN + return omit if is_response_format_param(response_format): return response_format diff --git a/src/writerai/lib/streaming/chat/_completions.py b/src/writerai/lib/streaming/chat/_completions.py index 61d4d38d..87077c5e 100644 --- a/src/writerai/lib/streaming/chat/_completions.py +++ b/src/writerai/lib/streaming/chat/_completions.py @@ -27,7 +27,7 @@ FunctionToolCallArgumentsDeltaEvent, ) from .._deltas import accumulate_delta -from ...._types import NOT_GIVEN, IncEx, NotGiven +from ...._types import Omit, IncEx, omit from ...._utils import is_given, consume_sync_iterator, consume_async_iterator from ...._compat import model_dump from ...._models import build, construct_type @@ -59,9 +59,9 @@ def __init__( self, *, raw_stream: Stream[ChatCompletionChunk], - # response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, - response_format: type[ResponseFormatT] | NotGiven, - input_tools: Iterable[ToolParam] | NotGiven, + # response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, + response_format: type[ResponseFormatT] | Omit, + input_tools: Iterable[ToolParam] | Omit, ) -> None: self._raw_stream = raw_stream self._response = raw_stream.response @@ -139,9 +139,9 @@ def __init__( self, api_request: Callable[[], Stream[ChatCompletionChunk]], *, - # response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, - response_format: type[ResponseFormatT] | NotGiven, - input_tools: Iterable[ToolParam] | NotGiven, + # response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, + response_format: type[ResponseFormatT] | Omit, + input_tools: Iterable[ToolParam] | Omit, ) -> None: self.__stream: ChatCompletionStream[ResponseFormatT] | None = None self.__api_request = api_request @@ -180,9 +180,9 @@ def __init__( self, *, raw_stream: AsyncStream[ChatCompletionChunk], - # response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, - response_format: type[ResponseFormatT] | NotGiven, - input_tools: Iterable[ToolParam] | NotGiven, + # response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, + response_format: type[ResponseFormatT] | Omit, + input_tools: Iterable[ToolParam] | Omit, ) -> None: self._raw_stream = raw_stream self._response = raw_stream.response @@ -260,9 +260,9 @@ def __init__( self, api_request: Awaitable[AsyncStream[ChatCompletionChunk]], *, - # response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, - response_format: type[ResponseFormatT] | NotGiven, - input_tools: Iterable[ToolParam] | NotGiven, + # response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, + response_format: type[ResponseFormatT] | Omit, + input_tools: Iterable[ToolParam] | Omit, ) -> None: self.__stream: AsyncChatCompletionStream[ResponseFormatT] | None = None self.__api_request = api_request @@ -294,16 +294,16 @@ class ChatCompletionStreamState(Generic[ResponseFormatT]): def __init__( self, *, - input_tools: Iterable[ToolParam] | NotGiven, - # response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, - response_format: type[ResponseFormatT] | NotGiven, + input_tools: Iterable[ToolParam] | Omit, + # response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, + response_format: type[ResponseFormatT] | Omit, ) -> None: self.__current_completion_snapshot: ParsedChatCompletionSnapshot | None = None self.__choice_event_states: list[ChoiceEventState] = [] self._input_tools = [tool for tool in input_tools] if is_given(input_tools) else [] self._response_format = response_format - self._rich_response_format: type | NotGiven = response_format if inspect.isclass(response_format) else NOT_GIVEN + self._rich_response_format: type | Omit = response_format if inspect.isclass(response_format) else omit def get_final_completion(self) -> ParsedChatCompletion[ResponseFormatT]: return parse_chat_completion( @@ -575,8 +575,8 @@ def get_done_events( *, choice_chunk: ChoiceChunk, choice_snapshot: ParsedChatCompletionChoiceSnapshot, - # response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, - response_format: type[ResponseFormatT] | NotGiven, + # response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, + response_format: type[ResponseFormatT] | Omit, ) -> list[ChatCompletionStreamEvent[ResponseFormatT]]: events_to_fire: list[ChatCompletionStreamEvent[ResponseFormatT]] = [] @@ -616,8 +616,8 @@ def _content_done_events( self, *, choice_snapshot: ParsedChatCompletionChoiceSnapshot, - # response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven, - response_format: type[ResponseFormatT] | NotGiven, + # response_format: type[ResponseFormatT] | ResponseFormatParam | Omit, + response_format: type[ResponseFormatT] | Omit, ) -> list[ChatCompletionStreamEvent[ResponseFormatT]]: events_to_fire: list[ChatCompletionStreamEvent[ResponseFormatT]] = [] diff --git a/src/writerai/resources/applications/applications.py b/src/writerai/resources/applications/applications.py index 4a0e5f6d..d58d476f 100644 --- a/src/writerai/resources/applications/applications.py +++ b/src/writerai/resources/applications/applications.py @@ -24,7 +24,7 @@ AsyncGraphsResourceWithStreamingResponse, ) from ...types import application_list_params, application_generate_content_params -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ..._utils import required_args, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource @@ -82,7 +82,7 @@ def retrieve( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationRetrieveResponse: """ Retrieves detailed information for a specific no-code agent (formerly called @@ -110,17 +110,17 @@ def retrieve( def list( self, *, - after: str | NotGiven = NOT_GIVEN, - before: str | NotGiven = NOT_GIVEN, - limit: int | NotGiven = NOT_GIVEN, - order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, - type: Literal["generation"] | NotGiven = NOT_GIVEN, + after: str | Omit = omit, + before: str | Omit = omit, + limit: int | Omit = omit, + order: Literal["asc", "desc"] | Omit = omit, + type: Literal["generation"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncCursorPage[ApplicationListResponse]: """ Retrieves a paginated list of no-code agents (formerly called no-code @@ -173,13 +173,13 @@ def generate_content( application_id: str, *, inputs: Iterable[application_generate_content_params.Input], - stream: Literal[False] | NotGiven = NOT_GIVEN, + stream: Literal[False] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGenerateContentResponse: """ Generate content from an existing no-code agent (formerly called no-code @@ -211,7 +211,7 @@ def generate_content( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Stream[ApplicationGenerateContentChunk]: """ Generate content from an existing no-code agent (formerly called no-code @@ -243,7 +243,7 @@ def generate_content( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGenerateContentResponse | Stream[ApplicationGenerateContentChunk]: """ Generate content from an existing no-code agent (formerly called no-code @@ -269,13 +269,13 @@ def generate_content( application_id: str, *, inputs: Iterable[application_generate_content_params.Input], - stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, + stream: Literal[False] | Literal[True] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGenerateContentResponse | Stream[ApplicationGenerateContentChunk]: if not application_id: raise ValueError(f"Expected a non-empty value for `application_id` but received {application_id!r}") @@ -336,7 +336,7 @@ async def retrieve( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationRetrieveResponse: """ Retrieves detailed information for a specific no-code agent (formerly called @@ -364,17 +364,17 @@ async def retrieve( def list( self, *, - after: str | NotGiven = NOT_GIVEN, - before: str | NotGiven = NOT_GIVEN, - limit: int | NotGiven = NOT_GIVEN, - order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, - type: Literal["generation"] | NotGiven = NOT_GIVEN, + after: str | Omit = omit, + before: str | Omit = omit, + limit: int | Omit = omit, + order: Literal["asc", "desc"] | Omit = omit, + type: Literal["generation"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[ApplicationListResponse, AsyncCursorPage[ApplicationListResponse]]: """ Retrieves a paginated list of no-code agents (formerly called no-code @@ -427,13 +427,13 @@ async def generate_content( application_id: str, *, inputs: Iterable[application_generate_content_params.Input], - stream: Literal[False] | NotGiven = NOT_GIVEN, + stream: Literal[False] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGenerateContentResponse: """ Generate content from an existing no-code agent (formerly called no-code @@ -465,7 +465,7 @@ async def generate_content( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncStream[ApplicationGenerateContentChunk]: """ Generate content from an existing no-code agent (formerly called no-code @@ -497,7 +497,7 @@ async def generate_content( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGenerateContentResponse | AsyncStream[ApplicationGenerateContentChunk]: """ Generate content from an existing no-code agent (formerly called no-code @@ -523,13 +523,13 @@ async def generate_content( application_id: str, *, inputs: Iterable[application_generate_content_params.Input], - stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, + stream: Literal[False] | Literal[True] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGenerateContentResponse | AsyncStream[ApplicationGenerateContentChunk]: if not application_id: raise ValueError(f"Expected a non-empty value for `application_id` but received {application_id!r}") diff --git a/src/writerai/resources/applications/graphs.py b/src/writerai/resources/applications/graphs.py index cff8d7c6..2ef559a4 100644 --- a/src/writerai/resources/applications/graphs.py +++ b/src/writerai/resources/applications/graphs.py @@ -4,7 +4,7 @@ import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr +from ..._types import Body, Query, Headers, NotGiven, SequenceNotStr, not_given from ..._utils import maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource @@ -51,7 +51,7 @@ def update( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGraphsResponse: """ Updates the list of Knowledge Graphs associated with a no-code chat agent. @@ -89,7 +89,7 @@ def list( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGraphsResponse: """ Retrieve Knowledge Graphs associated with a no-code agent that has chat @@ -145,7 +145,7 @@ async def update( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGraphsResponse: """ Updates the list of Knowledge Graphs associated with a no-code chat agent. @@ -183,7 +183,7 @@ async def list( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGraphsResponse: """ Retrieve Knowledge Graphs associated with a no-code agent that has chat diff --git a/src/writerai/resources/applications/jobs.py b/src/writerai/resources/applications/jobs.py index 6a277cc0..f27f6a3e 100644 --- a/src/writerai/resources/applications/jobs.py +++ b/src/writerai/resources/applications/jobs.py @@ -7,7 +7,7 @@ import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ..._utils import maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource @@ -57,7 +57,7 @@ def create( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> JobCreateResponse: """ Generate content asynchronously from an existing no-code agent (formerly called @@ -94,7 +94,7 @@ def retrieve( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGenerateAsyncResponse: """ Retrieves a single job created via the Async API. @@ -122,15 +122,15 @@ def list( self, application_id: str, *, - limit: int | NotGiven = NOT_GIVEN, - offset: int | NotGiven = NOT_GIVEN, - status: Literal["in_progress", "failed", "completed"] | NotGiven = NOT_GIVEN, + limit: int | Omit = omit, + offset: int | Omit = omit, + status: Literal["in_progress", "failed", "completed"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncApplicationJobsOffset[ApplicationGenerateAsyncResponse]: """ Retrieve all jobs created via the async API, linked to the provided application @@ -182,7 +182,7 @@ def retry( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> JobRetryResponse: """ Re-triggers the async execution of a single job previously created via the Async @@ -238,7 +238,7 @@ async def create( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> JobCreateResponse: """ Generate content asynchronously from an existing no-code agent (formerly called @@ -275,7 +275,7 @@ async def retrieve( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ApplicationGenerateAsyncResponse: """ Retrieves a single job created via the Async API. @@ -303,15 +303,15 @@ def list( self, application_id: str, *, - limit: int | NotGiven = NOT_GIVEN, - offset: int | NotGiven = NOT_GIVEN, - status: Literal["in_progress", "failed", "completed"] | NotGiven = NOT_GIVEN, + limit: int | Omit = omit, + offset: int | Omit = omit, + status: Literal["in_progress", "failed", "completed"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[ApplicationGenerateAsyncResponse, AsyncApplicationJobsOffset[ApplicationGenerateAsyncResponse]]: """ Retrieve all jobs created via the async API, linked to the provided application @@ -363,7 +363,7 @@ async def retry( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> JobRetryResponse: """ Re-triggers the async execution of a single job previously created via the Async diff --git a/src/writerai/resources/chat.py b/src/writerai/resources/chat.py index e178aa7f..5e837271 100644 --- a/src/writerai/resources/chat.py +++ b/src/writerai/resources/chat.py @@ -9,7 +9,7 @@ import httpx from ..types import chat_chat_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr +from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given from .._utils import required_args, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource @@ -27,6 +27,7 @@ parse_chat_completion, type_to_response_format_param, ) +from .._utils._utils import is_given from ..types.parsed_chat import ParsedChatCompletion from ..lib.streaming.chat import ChatCompletionStreamManager, AsyncChatCompletionStreamManager from ..types.chat_completion import ChatCompletion @@ -64,23 +65,23 @@ def chat( *, messages: Iterable[chat_chat_params.Message], model: str, - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - response_format: chat_chat_params.ResponseFormat | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream: Literal[False] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + response_format: chat_chat_params.ResponseFormat | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream: Literal[False] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ChatCompletion: """Generate a chat completion based on the provided messages. @@ -172,22 +173,22 @@ def chat( messages: Iterable[chat_chat_params.Message], model: str, stream: Literal[True], - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - response_format: chat_chat_params.ResponseFormat | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + response_format: chat_chat_params.ResponseFormat | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Stream[ChatCompletionChunk]: """Generate a chat completion based on the provided messages. @@ -279,22 +280,22 @@ def chat( messages: Iterable[chat_chat_params.Message], model: str, stream: bool, - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - response_format: chat_chat_params.ResponseFormat | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + response_format: chat_chat_params.ResponseFormat | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ChatCompletion | Stream[ChatCompletionChunk]: """Generate a chat completion based on the provided messages. @@ -385,23 +386,23 @@ def chat( *, messages: Iterable[chat_chat_params.Message], model: str, - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - response_format: chat_chat_params.ResponseFormat | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + response_format: chat_chat_params.ResponseFormat | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream: Literal[False] | Literal[True] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ChatCompletion | Stream[ChatCompletionChunk]: return self._post( "/v1/chat", @@ -437,20 +438,20 @@ def parse( model: str, messages: Iterable[chat_chat_params.Message], response_format: Type[T], - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ParsedChatCompletion[T]: """ Generate a chat completion with a structured response based on the provided messages. @@ -537,7 +538,7 @@ def parse( return parse_chat_completion( response_format=response_format, - input_tools=tools if tools is not NOT_GIVEN else [], + input_tools=tools if is_given(tools) else [], chat_completion=chat_completion, ) @@ -546,21 +547,21 @@ def stream( *, messages: Iterable[chat_chat_params.Message], model: str, - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ChatCompletionStreamManager[ResponseFormatT]: """Wrapper over the `client.chat.chat(stream=True)` method that provides a more granular event API and automatic accumulation of each delta. @@ -607,7 +608,7 @@ def stream( ) return ChatCompletionStreamManager( api_request, - response_format=NOT_GIVEN, + response_format=omit, input_tools=tools, ) @@ -638,23 +639,23 @@ async def chat( *, messages: Iterable[chat_chat_params.Message], model: str, - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - response_format: chat_chat_params.ResponseFormat | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream: Literal[False] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + response_format: chat_chat_params.ResponseFormat | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream: Literal[False] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ChatCompletion: """Generate a chat completion based on the provided messages. @@ -746,22 +747,22 @@ async def chat( messages: Iterable[chat_chat_params.Message], model: str, stream: Literal[True], - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - response_format: chat_chat_params.ResponseFormat | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + response_format: chat_chat_params.ResponseFormat | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncStream[ChatCompletionChunk]: """Generate a chat completion based on the provided messages. @@ -853,22 +854,22 @@ async def chat( messages: Iterable[chat_chat_params.Message], model: str, stream: bool, - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - response_format: chat_chat_params.ResponseFormat | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + response_format: chat_chat_params.ResponseFormat | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ChatCompletion | AsyncStream[ChatCompletionChunk]: """Generate a chat completion based on the provided messages. @@ -959,23 +960,23 @@ async def chat( *, messages: Iterable[chat_chat_params.Message], model: str, - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - response_format: chat_chat_params.ResponseFormat | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + response_format: chat_chat_params.ResponseFormat | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream: Literal[False] | Literal[True] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ChatCompletion | AsyncStream[ChatCompletionChunk]: return await self._post( "/v1/chat", @@ -1011,20 +1012,20 @@ async def parse( model: str, messages: Iterable[chat_chat_params.Message], response_format: Type[T], - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ParsedChatCompletion[T]: """ Generate a chat completion with a structured response based on the provided messages. @@ -1111,7 +1112,7 @@ async def parse( return parse_chat_completion( response_format=response_format, - input_tools=tools if tools is not NOT_GIVEN else [], + input_tools=tools if is_given(tools) else [], chat_completion=chat_completion, ) @@ -1120,21 +1121,21 @@ def stream( *, messages: Iterable[chat_chat_params.Message], model: str, - logprobs: bool | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - n: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream_options: chat_chat_params.StreamOptions | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - tool_choice: chat_chat_params.ToolChoice | NotGiven = NOT_GIVEN, - tools: Iterable[ToolParam] | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + logprobs: bool | Omit = omit, + max_tokens: int | Omit = omit, + n: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream_options: chat_chat_params.StreamOptions | Omit = omit, + temperature: float | Omit = omit, + tool_choice: chat_chat_params.ToolChoice | Omit = omit, + tools: Iterable[ToolParam] | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncChatCompletionStreamManager[ResponseFormatT]: """Wrapper over the `client.chat.chat(stream=True)` method that provides a more granular event API and automatic accumulation of each delta. @@ -1180,7 +1181,7 @@ def stream( ) return AsyncChatCompletionStreamManager( api_request, - response_format=NOT_GIVEN, + response_format=omit, input_tools=tools, ) diff --git a/src/writerai/resources/completions.py b/src/writerai/resources/completions.py index 417eecc9..382cb6a0 100644 --- a/src/writerai/resources/completions.py +++ b/src/writerai/resources/completions.py @@ -8,7 +8,7 @@ import httpx from ..types import completion_create_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr +from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given from .._utils import required_args, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource @@ -52,19 +52,19 @@ def create( *, model: str, prompt: str, - best_of: int | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - random_seed: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream: Literal[False] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + best_of: int | Omit = omit, + max_tokens: int | Omit = omit, + random_seed: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream: Literal[False] | Omit = omit, + temperature: float | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Completion: """Generate text completions using the specified model and prompt. @@ -118,18 +118,18 @@ def create( model: str, prompt: str, stream: Literal[True], - best_of: int | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - random_seed: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + best_of: int | Omit = omit, + max_tokens: int | Omit = omit, + random_seed: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + temperature: float | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Stream[CompletionChunk]: """Generate text completions using the specified model and prompt. @@ -183,18 +183,18 @@ def create( model: str, prompt: str, stream: bool, - best_of: int | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - random_seed: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + best_of: int | Omit = omit, + max_tokens: int | Omit = omit, + random_seed: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + temperature: float | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Completion | Stream[CompletionChunk]: """Generate text completions using the specified model and prompt. @@ -247,19 +247,19 @@ def create( *, model: str, prompt: str, - best_of: int | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - random_seed: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + best_of: int | Omit = omit, + max_tokens: int | Omit = omit, + random_seed: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream: Literal[False] | Literal[True] | Omit = omit, + temperature: float | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Completion | Stream[CompletionChunk]: return self._post( "/v1/completions", @@ -314,19 +314,19 @@ async def create( *, model: str, prompt: str, - best_of: int | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - random_seed: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream: Literal[False] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + best_of: int | Omit = omit, + max_tokens: int | Omit = omit, + random_seed: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream: Literal[False] | Omit = omit, + temperature: float | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Completion: """Generate text completions using the specified model and prompt. @@ -380,18 +380,18 @@ async def create( model: str, prompt: str, stream: Literal[True], - best_of: int | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - random_seed: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + best_of: int | Omit = omit, + max_tokens: int | Omit = omit, + random_seed: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + temperature: float | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncStream[CompletionChunk]: """Generate text completions using the specified model and prompt. @@ -445,18 +445,18 @@ async def create( model: str, prompt: str, stream: bool, - best_of: int | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - random_seed: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + best_of: int | Omit = omit, + max_tokens: int | Omit = omit, + random_seed: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + temperature: float | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Completion | AsyncStream[CompletionChunk]: """Generate text completions using the specified model and prompt. @@ -509,19 +509,19 @@ async def create( *, model: str, prompt: str, - best_of: int | NotGiven = NOT_GIVEN, - max_tokens: int | NotGiven = NOT_GIVEN, - random_seed: int | NotGiven = NOT_GIVEN, - stop: Union[SequenceNotStr[str], str] | NotGiven = NOT_GIVEN, - stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, - temperature: float | NotGiven = NOT_GIVEN, - top_p: float | NotGiven = NOT_GIVEN, + best_of: int | Omit = omit, + max_tokens: int | Omit = omit, + random_seed: int | Omit = omit, + stop: Union[SequenceNotStr[str], str] | Omit = omit, + stream: Literal[False] | Literal[True] | Omit = omit, + temperature: float | Omit = omit, + top_p: float | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Completion | AsyncStream[CompletionChunk]: return await self._post( "/v1/completions", diff --git a/src/writerai/resources/files.py b/src/writerai/resources/files.py index 60f47979..f8547d33 100644 --- a/src/writerai/resources/files.py +++ b/src/writerai/resources/files.py @@ -7,7 +7,7 @@ import httpx from ..types import file_list_params, file_retry_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes, SequenceNotStr +from .._types import Body, Omit, Query, Headers, NotGiven, FileTypes, SequenceNotStr, omit, not_given from .._utils import maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource @@ -63,7 +63,7 @@ def retrieve( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> File: """ Retrieve detailed information about a specific file, including its metadata, @@ -91,19 +91,19 @@ def retrieve( def list( self, *, - after: str | NotGiven = NOT_GIVEN, - before: str | NotGiven = NOT_GIVEN, - file_types: str | NotGiven = NOT_GIVEN, - graph_id: str | NotGiven = NOT_GIVEN, - limit: int | NotGiven = NOT_GIVEN, - order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, - status: Literal["in_progress", "completed", "failed"] | NotGiven = NOT_GIVEN, + after: str | Omit = omit, + before: str | Omit = omit, + file_types: str | Omit = omit, + graph_id: str | Omit = omit, + limit: int | Omit = omit, + order: Literal["asc", "desc"] | Omit = omit, + status: Literal["in_progress", "completed", "failed"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncCursorPage[File]: """ Retrieve a paginated list of files with optional filtering by status, graph @@ -171,7 +171,7 @@ def delete( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> FileDeleteResponse: """Permanently delete a file from the system. @@ -205,7 +205,7 @@ def download( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> BinaryAPIResponse: """Download the binary content of a file. @@ -241,7 +241,7 @@ def retry( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> FileRetryResponse: """Retry processing of files that previously failed to process. @@ -279,7 +279,7 @@ def upload( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> File: """Upload a new file to the system. @@ -339,7 +339,7 @@ async def retrieve( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> File: """ Retrieve detailed information about a specific file, including its metadata, @@ -367,19 +367,19 @@ async def retrieve( def list( self, *, - after: str | NotGiven = NOT_GIVEN, - before: str | NotGiven = NOT_GIVEN, - file_types: str | NotGiven = NOT_GIVEN, - graph_id: str | NotGiven = NOT_GIVEN, - limit: int | NotGiven = NOT_GIVEN, - order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, - status: Literal["in_progress", "completed", "failed"] | NotGiven = NOT_GIVEN, + after: str | Omit = omit, + before: str | Omit = omit, + file_types: str | Omit = omit, + graph_id: str | Omit = omit, + limit: int | Omit = omit, + order: Literal["asc", "desc"] | Omit = omit, + status: Literal["in_progress", "completed", "failed"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[File, AsyncCursorPage[File]]: """ Retrieve a paginated list of files with optional filtering by status, graph @@ -447,7 +447,7 @@ async def delete( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> FileDeleteResponse: """Permanently delete a file from the system. @@ -481,7 +481,7 @@ async def download( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncBinaryAPIResponse: """Download the binary content of a file. @@ -517,7 +517,7 @@ async def retry( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> FileRetryResponse: """Retry processing of files that previously failed to process. @@ -555,7 +555,7 @@ async def upload( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> File: """Upload a new file to the system. diff --git a/src/writerai/resources/graphs.py b/src/writerai/resources/graphs.py index ebb822c8..8669d8a2 100644 --- a/src/writerai/resources/graphs.py +++ b/src/writerai/resources/graphs.py @@ -14,7 +14,7 @@ graph_question_params, graph_add_file_to_graph_params, ) -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes, SequenceNotStr +from .._types import Body, Omit, Query, Headers, NotGiven, FileTypes, SequenceNotStr, omit, not_given from .._utils import required_args, maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource @@ -62,14 +62,14 @@ def with_streaming_response(self) -> GraphsResourceWithStreamingResponse: def create( self, *, - description: str | NotGiven = NOT_GIVEN, - name: str | NotGiven = NOT_GIVEN, + description: str | Omit = omit, + name: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> GraphCreateResponse: """ Create a new Knowledge Graph. @@ -113,7 +113,7 @@ def retrieve( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Graph: """ Retrieve a Knowledge Graph. @@ -141,15 +141,15 @@ def update( self, graph_id: str, *, - description: str | NotGiven = NOT_GIVEN, - name: str | NotGiven = NOT_GIVEN, - urls: Iterable[graph_update_params.URL] | NotGiven = NOT_GIVEN, + description: str | Omit = omit, + name: str | Omit = omit, + urls: Iterable[graph_update_params.URL] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> GraphUpdateResponse: """ Update the name and description of a Knowledge Graph. @@ -194,16 +194,16 @@ def update( def list( self, *, - after: str | NotGiven = NOT_GIVEN, - before: str | NotGiven = NOT_GIVEN, - limit: int | NotGiven = NOT_GIVEN, - order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, + after: str | Omit = omit, + before: str | Omit = omit, + limit: int | Omit = omit, + order: Literal["asc", "desc"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncCursorPage[Graph]: """ Retrieve a list of Knowledge Graphs. @@ -259,7 +259,7 @@ def delete( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> GraphDeleteResponse: """ Delete a Knowledge Graph. @@ -293,7 +293,7 @@ def add_file_to_graph( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> File: """ Add a file to a Knowledge Graph. @@ -332,7 +332,7 @@ def upload_and_add_file_to_graph( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> File: if not graph_id: raise ValueError(f"Expected a non-empty value for `graph_id` but received {graph_id!r}") @@ -360,15 +360,15 @@ def question( *, graph_ids: SequenceNotStr[str], question: str, - query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN, - stream: Literal[False] | NotGiven = NOT_GIVEN, - subqueries: bool | NotGiven = NOT_GIVEN, + query_config: graph_question_params.QueryConfig | Omit = omit, + stream: Literal[False] | Omit = omit, + subqueries: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Question: """ Ask a question to specified Knowledge Graphs. @@ -404,14 +404,14 @@ def question( graph_ids: SequenceNotStr[str], question: str, stream: Literal[True], - query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN, - subqueries: bool | NotGiven = NOT_GIVEN, + query_config: graph_question_params.QueryConfig | Omit = omit, + subqueries: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Stream[QuestionResponseChunk]: """ Ask a question to specified Knowledge Graphs. @@ -447,14 +447,14 @@ def question( graph_ids: SequenceNotStr[str], question: str, stream: bool, - query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN, - subqueries: bool | NotGiven = NOT_GIVEN, + query_config: graph_question_params.QueryConfig | Omit = omit, + subqueries: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Question | Stream[QuestionResponseChunk]: """ Ask a question to specified Knowledge Graphs. @@ -489,15 +489,15 @@ def question( *, graph_ids: SequenceNotStr[str], question: str, - query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN, - stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, - subqueries: bool | NotGiven = NOT_GIVEN, + query_config: graph_question_params.QueryConfig | Omit = omit, + stream: Literal[False] | Literal[True] | Omit = omit, + subqueries: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Question | Stream[QuestionResponseChunk]: return self._post( "/v1/graphs/question", @@ -531,7 +531,7 @@ def remove_file_from_graph( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> GraphRemoveFileFromGraphResponse: """ Remove a file from a Knowledge Graph. @@ -581,14 +581,14 @@ def with_streaming_response(self) -> AsyncGraphsResourceWithStreamingResponse: async def create( self, *, - description: str | NotGiven = NOT_GIVEN, - name: str | NotGiven = NOT_GIVEN, + description: str | Omit = omit, + name: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> GraphCreateResponse: """ Create a new Knowledge Graph. @@ -632,7 +632,7 @@ async def retrieve( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Graph: """ Retrieve a Knowledge Graph. @@ -660,15 +660,15 @@ async def update( self, graph_id: str, *, - description: str | NotGiven = NOT_GIVEN, - name: str | NotGiven = NOT_GIVEN, - urls: Iterable[graph_update_params.URL] | NotGiven = NOT_GIVEN, + description: str | Omit = omit, + name: str | Omit = omit, + urls: Iterable[graph_update_params.URL] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> GraphUpdateResponse: """ Update the name and description of a Knowledge Graph. @@ -713,16 +713,16 @@ async def update( def list( self, *, - after: str | NotGiven = NOT_GIVEN, - before: str | NotGiven = NOT_GIVEN, - limit: int | NotGiven = NOT_GIVEN, - order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, + after: str | Omit = omit, + before: str | Omit = omit, + limit: int | Omit = omit, + order: Literal["asc", "desc"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[Graph, AsyncCursorPage[Graph]]: """ Retrieve a list of Knowledge Graphs. @@ -778,7 +778,7 @@ async def delete( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> GraphDeleteResponse: """ Delete a Knowledge Graph. @@ -812,7 +812,7 @@ async def add_file_to_graph( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> File: """ Add a file to a Knowledge Graph. @@ -853,7 +853,7 @@ async def upload_and_add_file_to_graph( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> File: if not graph_id: raise ValueError(f"Expected a non-empty value for `graph_id` but received {graph_id!r}") @@ -881,15 +881,15 @@ async def question( *, graph_ids: SequenceNotStr[str], question: str, - query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN, - stream: Literal[False] | NotGiven = NOT_GIVEN, - subqueries: bool | NotGiven = NOT_GIVEN, + query_config: graph_question_params.QueryConfig | Omit = omit, + stream: Literal[False] | Omit = omit, + subqueries: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Question: """ Ask a question to specified Knowledge Graphs. @@ -925,14 +925,14 @@ async def question( graph_ids: SequenceNotStr[str], question: str, stream: Literal[True], - query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN, - subqueries: bool | NotGiven = NOT_GIVEN, + query_config: graph_question_params.QueryConfig | Omit = omit, + subqueries: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncStream[QuestionResponseChunk]: """ Ask a question to specified Knowledge Graphs. @@ -968,14 +968,14 @@ async def question( graph_ids: SequenceNotStr[str], question: str, stream: bool, - query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN, - subqueries: bool | NotGiven = NOT_GIVEN, + query_config: graph_question_params.QueryConfig | Omit = omit, + subqueries: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Question | AsyncStream[QuestionResponseChunk]: """ Ask a question to specified Knowledge Graphs. @@ -1010,15 +1010,15 @@ async def question( *, graph_ids: SequenceNotStr[str], question: str, - query_config: graph_question_params.QueryConfig | NotGiven = NOT_GIVEN, - stream: Literal[False] | Literal[True] | NotGiven = NOT_GIVEN, - subqueries: bool | NotGiven = NOT_GIVEN, + query_config: graph_question_params.QueryConfig | Omit = omit, + stream: Literal[False] | Literal[True] | Omit = omit, + subqueries: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Question | AsyncStream[QuestionResponseChunk]: return await self._post( "/v1/graphs/question", @@ -1052,7 +1052,7 @@ async def remove_file_from_graph( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> GraphRemoveFileFromGraphResponse: """ Remove a file from a Knowledge Graph. diff --git a/src/writerai/resources/models.py b/src/writerai/resources/models.py index b7515656..d7bc28a6 100644 --- a/src/writerai/resources/models.py +++ b/src/writerai/resources/models.py @@ -4,7 +4,7 @@ import httpx -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .._types import Body, Query, Headers, NotGiven, not_given from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import ( @@ -47,7 +47,7 @@ def list( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ModelListResponse: """ Retrieve a list of available models that can be used for text generation, chat @@ -90,7 +90,7 @@ async def list( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ModelListResponse: """ Retrieve a list of available models that can be used for text generation, chat diff --git a/src/writerai/resources/tools/comprehend.py b/src/writerai/resources/tools/comprehend.py index cbae676a..2cff5f4f 100644 --- a/src/writerai/resources/tools/comprehend.py +++ b/src/writerai/resources/tools/comprehend.py @@ -2,11 +2,12 @@ from __future__ import annotations +import typing_extensions from typing_extensions import Literal import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._types import Body, Query, Headers, NotGiven, not_given from ..._utils import maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource @@ -43,6 +44,9 @@ def with_streaming_response(self) -> ComprehendResourceWithStreamingResponse: """ return ComprehendResourceWithStreamingResponse(self) + @typing_extensions.deprecated( + "Will be removed in a future release. Migrate to `chat.chat` with the LLM tool using the `palmyra-med` model for medical analysis. See documentation at dev.writer.com for more information." + ) def medical( self, *, @@ -53,7 +57,7 @@ def medical( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ComprehendMedicalResponse: """ Analyze unstructured medical text to extract entities labeled with standardized @@ -110,6 +114,9 @@ def with_streaming_response(self) -> AsyncComprehendResourceWithStreamingRespons """ return AsyncComprehendResourceWithStreamingResponse(self) + @typing_extensions.deprecated( + "Will be removed in a future release. Migrate to `chat.chat` with the LLM tool using the `palmyra-med` model for medical analysis. See documentation at dev.writer.com for more information." + ) async def medical( self, *, @@ -120,7 +127,7 @@ async def medical( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ComprehendMedicalResponse: """ Analyze unstructured medical text to extract entities labeled with standardized @@ -161,8 +168,10 @@ class ComprehendResourceWithRawResponse: def __init__(self, comprehend: ComprehendResource) -> None: self._comprehend = comprehend - self.medical = to_raw_response_wrapper( - comprehend.medical, + self.medical = ( # pyright: ignore[reportDeprecated] + to_raw_response_wrapper( + comprehend.medical, # pyright: ignore[reportDeprecated], + ) ) @@ -170,8 +179,10 @@ class AsyncComprehendResourceWithRawResponse: def __init__(self, comprehend: AsyncComprehendResource) -> None: self._comprehend = comprehend - self.medical = async_to_raw_response_wrapper( - comprehend.medical, + self.medical = ( # pyright: ignore[reportDeprecated] + async_to_raw_response_wrapper( + comprehend.medical, # pyright: ignore[reportDeprecated], + ) ) @@ -179,8 +190,10 @@ class ComprehendResourceWithStreamingResponse: def __init__(self, comprehend: ComprehendResource) -> None: self._comprehend = comprehend - self.medical = to_streamed_response_wrapper( - comprehend.medical, + self.medical = ( # pyright: ignore[reportDeprecated] + to_streamed_response_wrapper( + comprehend.medical, # pyright: ignore[reportDeprecated], + ) ) @@ -188,6 +201,8 @@ class AsyncComprehendResourceWithStreamingResponse: def __init__(self, comprehend: AsyncComprehendResource) -> None: self._comprehend = comprehend - self.medical = async_to_streamed_response_wrapper( - comprehend.medical, + self.medical = ( # pyright: ignore[reportDeprecated] + async_to_streamed_response_wrapper( + comprehend.medical, # pyright: ignore[reportDeprecated], + ) ) diff --git a/src/writerai/resources/tools/tools.py b/src/writerai/resources/tools/tools.py index 1f739424..d48109e0 100644 --- a/src/writerai/resources/tools/tools.py +++ b/src/writerai/resources/tools/tools.py @@ -2,6 +2,7 @@ from __future__ import annotations +import typing_extensions from typing import Union from typing_extensions import Literal @@ -13,7 +14,7 @@ tool_web_search_params, tool_context_aware_splitting_params, ) -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr +from ..._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given from ..._utils import maybe_transform, async_maybe_transform from ..._compat import cached_property from .comprehend import ( @@ -64,6 +65,9 @@ def with_streaming_response(self) -> ToolsResourceWithStreamingResponse: """ return ToolsResourceWithStreamingResponse(self) + @typing_extensions.deprecated( + "Will be removed in a future release. Please migrate to alternative solutions. See documentation at dev.writer.com for more information." + ) def ai_detect( self, *, @@ -73,7 +77,7 @@ def ai_detect( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ToolAIDetectResponse: """Detects if content is AI- or human-generated, with a confidence score. @@ -101,6 +105,9 @@ def ai_detect( cast_to=ToolAIDetectResponse, ) + @typing_extensions.deprecated( + "Will be removed in a future release. Please migrate to alternative solutions. See documentation at dev.writer.com for more information." + ) def context_aware_splitting( self, *, @@ -111,7 +118,7 @@ def context_aware_splitting( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ToolContextAwareSplittingResponse: """ Splits a long block of text (maximum 4000 words) into smaller chunks while @@ -147,6 +154,9 @@ def context_aware_splitting( cast_to=ToolContextAwareSplittingResponse, ) + @typing_extensions.deprecated( + "Will be removed in a future release. A replacement PDF parsing tool for chat completions is planned; see documentation at dev.writer.com for more information." + ) def parse_pdf( self, file_id: str, @@ -157,7 +167,7 @@ def parse_pdf( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ToolParsePdfResponse: """ Parse PDF to other formats. @@ -184,10 +194,13 @@ def parse_pdf( cast_to=ToolParsePdfResponse, ) + @typing_extensions.deprecated( + "Will be removed in a future release. Migrate to `chat.chat` with the web search tool for web search capabilities. See documentation at dev.writer.com for more information." + ) def web_search( self, *, - chunks_per_source: int | NotGiven = NOT_GIVEN, + chunks_per_source: int | Omit = omit, country: Literal[ "afghanistan", "albania", @@ -356,24 +369,24 @@ def web_search( "zambia", "zimbabwe", ] - | NotGiven = NOT_GIVEN, - days: int | NotGiven = NOT_GIVEN, - exclude_domains: SequenceNotStr[str] | NotGiven = NOT_GIVEN, - include_answer: bool | NotGiven = NOT_GIVEN, - include_domains: SequenceNotStr[str] | NotGiven = NOT_GIVEN, - include_raw_content: Union[Literal["text", "markdown"], bool] | NotGiven = NOT_GIVEN, - max_results: int | NotGiven = NOT_GIVEN, - query: str | NotGiven = NOT_GIVEN, - search_depth: Literal["basic", "advanced"] | NotGiven = NOT_GIVEN, - stream: bool | NotGiven = NOT_GIVEN, - time_range: Literal["day", "week", "month", "year", "d", "w", "m", "y"] | NotGiven = NOT_GIVEN, - topic: Literal["general", "news"] | NotGiven = NOT_GIVEN, + | Omit = omit, + days: int | Omit = omit, + exclude_domains: SequenceNotStr[str] | Omit = omit, + include_answer: bool | Omit = omit, + include_domains: SequenceNotStr[str] | Omit = omit, + include_raw_content: Union[Literal["text", "markdown"], bool] | Omit = omit, + max_results: int | Omit = omit, + query: str | Omit = omit, + search_depth: Literal["basic", "advanced"] | Omit = omit, + stream: bool | Omit = omit, + time_range: Literal["day", "week", "month", "year", "d", "w", "m", "y"] | Omit = omit, + topic: Literal["general", "news"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ToolWebSearchResponse: """ Search the web for information about a given query and return relevant results @@ -482,6 +495,9 @@ def with_streaming_response(self) -> AsyncToolsResourceWithStreamingResponse: """ return AsyncToolsResourceWithStreamingResponse(self) + @typing_extensions.deprecated( + "Will be removed in a future release. Please migrate to alternative solutions. See documentation at dev.writer.com for more information." + ) async def ai_detect( self, *, @@ -491,7 +507,7 @@ async def ai_detect( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ToolAIDetectResponse: """Detects if content is AI- or human-generated, with a confidence score. @@ -519,6 +535,9 @@ async def ai_detect( cast_to=ToolAIDetectResponse, ) + @typing_extensions.deprecated( + "Will be removed in a future release. Please migrate to alternative solutions. See documentation at dev.writer.com for more information." + ) async def context_aware_splitting( self, *, @@ -529,7 +548,7 @@ async def context_aware_splitting( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ToolContextAwareSplittingResponse: """ Splits a long block of text (maximum 4000 words) into smaller chunks while @@ -565,6 +584,9 @@ async def context_aware_splitting( cast_to=ToolContextAwareSplittingResponse, ) + @typing_extensions.deprecated( + "Will be removed in a future release. A replacement PDF parsing tool for chat completions is planned; see documentation at dev.writer.com for more information." + ) async def parse_pdf( self, file_id: str, @@ -575,7 +597,7 @@ async def parse_pdf( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ToolParsePdfResponse: """ Parse PDF to other formats. @@ -602,10 +624,13 @@ async def parse_pdf( cast_to=ToolParsePdfResponse, ) + @typing_extensions.deprecated( + "Will be removed in a future release. Migrate to `chat.chat` with the web search tool for web search capabilities. See documentation at dev.writer.com for more information." + ) async def web_search( self, *, - chunks_per_source: int | NotGiven = NOT_GIVEN, + chunks_per_source: int | Omit = omit, country: Literal[ "afghanistan", "albania", @@ -774,24 +799,24 @@ async def web_search( "zambia", "zimbabwe", ] - | NotGiven = NOT_GIVEN, - days: int | NotGiven = NOT_GIVEN, - exclude_domains: SequenceNotStr[str] | NotGiven = NOT_GIVEN, - include_answer: bool | NotGiven = NOT_GIVEN, - include_domains: SequenceNotStr[str] | NotGiven = NOT_GIVEN, - include_raw_content: Union[Literal["text", "markdown"], bool] | NotGiven = NOT_GIVEN, - max_results: int | NotGiven = NOT_GIVEN, - query: str | NotGiven = NOT_GIVEN, - search_depth: Literal["basic", "advanced"] | NotGiven = NOT_GIVEN, - stream: bool | NotGiven = NOT_GIVEN, - time_range: Literal["day", "week", "month", "year", "d", "w", "m", "y"] | NotGiven = NOT_GIVEN, - topic: Literal["general", "news"] | NotGiven = NOT_GIVEN, + | Omit = omit, + days: int | Omit = omit, + exclude_domains: SequenceNotStr[str] | Omit = omit, + include_answer: bool | Omit = omit, + include_domains: SequenceNotStr[str] | Omit = omit, + include_raw_content: Union[Literal["text", "markdown"], bool] | Omit = omit, + max_results: int | Omit = omit, + query: str | Omit = omit, + search_depth: Literal["basic", "advanced"] | Omit = omit, + stream: bool | Omit = omit, + time_range: Literal["day", "week", "month", "year", "d", "w", "m", "y"] | Omit = omit, + topic: Literal["general", "news"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ToolWebSearchResponse: """ Search the web for information about a given query and return relevant results @@ -880,17 +905,25 @@ class ToolsResourceWithRawResponse: def __init__(self, tools: ToolsResource) -> None: self._tools = tools - self.ai_detect = to_raw_response_wrapper( - tools.ai_detect, + self.ai_detect = ( # pyright: ignore[reportDeprecated] + to_raw_response_wrapper( + tools.ai_detect, # pyright: ignore[reportDeprecated], + ) ) - self.context_aware_splitting = to_raw_response_wrapper( - tools.context_aware_splitting, + self.context_aware_splitting = ( # pyright: ignore[reportDeprecated] + to_raw_response_wrapper( + tools.context_aware_splitting, # pyright: ignore[reportDeprecated], + ) ) - self.parse_pdf = to_raw_response_wrapper( - tools.parse_pdf, + self.parse_pdf = ( # pyright: ignore[reportDeprecated] + to_raw_response_wrapper( + tools.parse_pdf, # pyright: ignore[reportDeprecated], + ) ) - self.web_search = to_raw_response_wrapper( - tools.web_search, + self.web_search = ( # pyright: ignore[reportDeprecated] + to_raw_response_wrapper( + tools.web_search, # pyright: ignore[reportDeprecated], + ) ) @cached_property @@ -902,17 +935,25 @@ class AsyncToolsResourceWithRawResponse: def __init__(self, tools: AsyncToolsResource) -> None: self._tools = tools - self.ai_detect = async_to_raw_response_wrapper( - tools.ai_detect, + self.ai_detect = ( # pyright: ignore[reportDeprecated] + async_to_raw_response_wrapper( + tools.ai_detect, # pyright: ignore[reportDeprecated], + ) ) - self.context_aware_splitting = async_to_raw_response_wrapper( - tools.context_aware_splitting, + self.context_aware_splitting = ( # pyright: ignore[reportDeprecated] + async_to_raw_response_wrapper( + tools.context_aware_splitting, # pyright: ignore[reportDeprecated], + ) ) - self.parse_pdf = async_to_raw_response_wrapper( - tools.parse_pdf, + self.parse_pdf = ( # pyright: ignore[reportDeprecated] + async_to_raw_response_wrapper( + tools.parse_pdf, # pyright: ignore[reportDeprecated], + ) ) - self.web_search = async_to_raw_response_wrapper( - tools.web_search, + self.web_search = ( # pyright: ignore[reportDeprecated] + async_to_raw_response_wrapper( + tools.web_search, # pyright: ignore[reportDeprecated], + ) ) @cached_property @@ -924,17 +965,25 @@ class ToolsResourceWithStreamingResponse: def __init__(self, tools: ToolsResource) -> None: self._tools = tools - self.ai_detect = to_streamed_response_wrapper( - tools.ai_detect, + self.ai_detect = ( # pyright: ignore[reportDeprecated] + to_streamed_response_wrapper( + tools.ai_detect, # pyright: ignore[reportDeprecated], + ) ) - self.context_aware_splitting = to_streamed_response_wrapper( - tools.context_aware_splitting, + self.context_aware_splitting = ( # pyright: ignore[reportDeprecated] + to_streamed_response_wrapper( + tools.context_aware_splitting, # pyright: ignore[reportDeprecated], + ) ) - self.parse_pdf = to_streamed_response_wrapper( - tools.parse_pdf, + self.parse_pdf = ( # pyright: ignore[reportDeprecated] + to_streamed_response_wrapper( + tools.parse_pdf, # pyright: ignore[reportDeprecated], + ) ) - self.web_search = to_streamed_response_wrapper( - tools.web_search, + self.web_search = ( # pyright: ignore[reportDeprecated] + to_streamed_response_wrapper( + tools.web_search, # pyright: ignore[reportDeprecated], + ) ) @cached_property @@ -946,17 +995,25 @@ class AsyncToolsResourceWithStreamingResponse: def __init__(self, tools: AsyncToolsResource) -> None: self._tools = tools - self.ai_detect = async_to_streamed_response_wrapper( - tools.ai_detect, + self.ai_detect = ( # pyright: ignore[reportDeprecated] + async_to_streamed_response_wrapper( + tools.ai_detect, # pyright: ignore[reportDeprecated], + ) ) - self.context_aware_splitting = async_to_streamed_response_wrapper( - tools.context_aware_splitting, + self.context_aware_splitting = ( # pyright: ignore[reportDeprecated] + async_to_streamed_response_wrapper( + tools.context_aware_splitting, # pyright: ignore[reportDeprecated], + ) ) - self.parse_pdf = async_to_streamed_response_wrapper( - tools.parse_pdf, + self.parse_pdf = ( # pyright: ignore[reportDeprecated] + async_to_streamed_response_wrapper( + tools.parse_pdf, # pyright: ignore[reportDeprecated], + ) ) - self.web_search = async_to_streamed_response_wrapper( - tools.web_search, + self.web_search = ( # pyright: ignore[reportDeprecated] + async_to_streamed_response_wrapper( + tools.web_search, # pyright: ignore[reportDeprecated], + ) ) @cached_property diff --git a/src/writerai/resources/translation.py b/src/writerai/resources/translation.py index 235ce8d8..36166407 100644 --- a/src/writerai/resources/translation.py +++ b/src/writerai/resources/translation.py @@ -2,12 +2,13 @@ from __future__ import annotations +import typing_extensions from typing_extensions import Literal import httpx from ..types import translation_translate_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .._types import Body, Query, Headers, NotGiven, not_given from .._utils import maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource @@ -43,6 +44,9 @@ def with_streaming_response(self) -> TranslationResourceWithStreamingResponse: """ return TranslationResourceWithStreamingResponse(self) + @typing_extensions.deprecated( + "Will be removed in a future release. Migrate to `chat.chat` with the translate tool for translation capabilities. See documentation at dev.writer.com for more information." + ) def translate( self, *, @@ -58,7 +62,7 @@ def translate( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> TranslationResponse: """ Translate text from one language to another. @@ -145,6 +149,9 @@ def with_streaming_response(self) -> AsyncTranslationResourceWithStreamingRespon """ return AsyncTranslationResourceWithStreamingResponse(self) + @typing_extensions.deprecated( + "Will be removed in a future release. Migrate to `chat.chat` with the translate tool for translation capabilities. See documentation at dev.writer.com for more information." + ) async def translate( self, *, @@ -160,7 +167,7 @@ async def translate( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> TranslationResponse: """ Translate text from one language to another. @@ -231,8 +238,10 @@ class TranslationResourceWithRawResponse: def __init__(self, translation: TranslationResource) -> None: self._translation = translation - self.translate = to_raw_response_wrapper( - translation.translate, + self.translate = ( # pyright: ignore[reportDeprecated] + to_raw_response_wrapper( + translation.translate, # pyright: ignore[reportDeprecated], + ) ) @@ -240,8 +249,10 @@ class AsyncTranslationResourceWithRawResponse: def __init__(self, translation: AsyncTranslationResource) -> None: self._translation = translation - self.translate = async_to_raw_response_wrapper( - translation.translate, + self.translate = ( # pyright: ignore[reportDeprecated] + async_to_raw_response_wrapper( + translation.translate, # pyright: ignore[reportDeprecated], + ) ) @@ -249,8 +260,10 @@ class TranslationResourceWithStreamingResponse: def __init__(self, translation: TranslationResource) -> None: self._translation = translation - self.translate = to_streamed_response_wrapper( - translation.translate, + self.translate = ( # pyright: ignore[reportDeprecated] + to_streamed_response_wrapper( + translation.translate, # pyright: ignore[reportDeprecated], + ) ) @@ -258,6 +271,8 @@ class AsyncTranslationResourceWithStreamingResponse: def __init__(self, translation: AsyncTranslationResource) -> None: self._translation = translation - self.translate = async_to_streamed_response_wrapper( - translation.translate, + self.translate = ( # pyright: ignore[reportDeprecated] + async_to_streamed_response_wrapper( + translation.translate, # pyright: ignore[reportDeprecated], + ) ) diff --git a/src/writerai/resources/vision.py b/src/writerai/resources/vision.py index 0bea951f..d90bf3d3 100644 --- a/src/writerai/resources/vision.py +++ b/src/writerai/resources/vision.py @@ -8,7 +8,7 @@ import httpx from ..types import vision_analyze_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .._types import Body, Query, Headers, NotGiven, not_given from .._utils import maybe_transform, async_maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource @@ -55,7 +55,7 @@ def analyze( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> VisionResponse: """ Submit images and a prompt to generate an analysis of the images. @@ -123,7 +123,7 @@ async def analyze( extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> VisionResponse: """ Submit images and a prompt to generate an analysis of the images. diff --git a/src/writerai/types/shared/graph_data.py b/src/writerai/types/shared/graph_data.py index 6898bddd..6d8eb341 100644 --- a/src/writerai/types/shared/graph_data.py +++ b/src/writerai/types/shared/graph_data.py @@ -3,10 +3,66 @@ from typing import List, Optional from typing_extensions import Literal +from pydantic import Field as FieldInfo + from .source import Source from ..._models import BaseModel -__all__ = ["GraphData", "Subquery"] +__all__ = ["GraphData", "References", "ReferencesFile", "ReferencesWeb", "Subquery"] + + +class ReferencesFile(BaseModel): + file_id: str = FieldInfo(alias="fileId") + """The unique identifier of the file in your Writer account.""" + + score: float + """ + Internal score used during the retrieval process for ranking and selecting + relevant snippets. + """ + + text: str + """ + The exact text snippet from the source document that was used to support the + response. + """ + + cite: Optional[str] = None + """ + Unique citation ID that appears in inline citations within the response text + (null if not cited). + """ + + page: Optional[int] = None + """Page number where this snippet was found in the source document.""" + + +class ReferencesWeb(BaseModel): + score: float + """ + Internal score used during the retrieval process for ranking and selecting + relevant snippets. + """ + + text: str + """ + The exact text snippet from the web source that was used to support the + response. + """ + + title: str + """The title of the web page where this content was found.""" + + url: str + """The URL of the web page where this content was found.""" + + +class References(BaseModel): + files: Optional[List[ReferencesFile]] = None + """Array of file-based references from uploaded documents in the Knowledge Graph.""" + + web: Optional[List[ReferencesWeb]] = None + """Array of web-based references from online sources accessed during the query.""" class Subquery(BaseModel): @@ -21,6 +77,12 @@ class Subquery(BaseModel): class GraphData(BaseModel): + references: Optional[References] = None + """ + Detailed source information organized by reference type, providing comprehensive + metadata about the sources used to generate the response. + """ + sources: Optional[List[Optional[Source]]] = None status: Optional[Literal["processing", "finished"]] = None diff --git a/src/writerai/types/shared_params/graph_data.py b/src/writerai/types/shared_params/graph_data.py index caa1e6d5..6e162c1d 100644 --- a/src/writerai/types/shared_params/graph_data.py +++ b/src/writerai/types/shared_params/graph_data.py @@ -3,11 +3,66 @@ from __future__ import annotations from typing import Iterable, Optional -from typing_extensions import Literal, Required, TypedDict +from typing_extensions import Literal, Required, Annotated, TypedDict from .source import Source +from ..._utils import PropertyInfo -__all__ = ["GraphData", "Subquery"] +__all__ = ["GraphData", "References", "ReferencesFile", "ReferencesWeb", "Subquery"] + + +class ReferencesFile(TypedDict, total=False): + file_id: Required[Annotated[str, PropertyInfo(alias="fileId")]] + """The unique identifier of the file in your Writer account.""" + + score: Required[float] + """ + Internal score used during the retrieval process for ranking and selecting + relevant snippets. + """ + + text: Required[str] + """ + The exact text snippet from the source document that was used to support the + response. + """ + + cite: str + """ + Unique citation ID that appears in inline citations within the response text + (null if not cited). + """ + + page: int + """Page number where this snippet was found in the source document.""" + + +class ReferencesWeb(TypedDict, total=False): + score: Required[float] + """ + Internal score used during the retrieval process for ranking and selecting + relevant snippets. + """ + + text: Required[str] + """ + The exact text snippet from the web source that was used to support the + response. + """ + + title: Required[str] + """The title of the web page where this content was found.""" + + url: Required[str] + """The URL of the web page where this content was found.""" + + +class References(TypedDict, total=False): + files: Iterable[ReferencesFile] + """Array of file-based references from uploaded documents in the Knowledge Graph.""" + + web: Iterable[ReferencesWeb] + """Array of web-based references from online sources accessed during the query.""" class Subquery(TypedDict, total=False): @@ -22,6 +77,12 @@ class Subquery(TypedDict, total=False): class GraphData(TypedDict, total=False): + references: References + """ + Detailed source information organized by reference type, providing comprehensive + metadata about the sources used to generate the response. + """ + sources: Iterable[Optional[Source]] status: Optional[Literal["processing", "finished"]] diff --git a/tests/api_resources/test_chat.py b/tests/api_resources/test_chat.py index 8d072394..ab61287b 100644 --- a/tests/api_resources/test_chat.py +++ b/tests/api_resources/test_chat.py @@ -33,6 +33,25 @@ def test_method_chat_with_all_params_overload_1(self, client: Writer) -> None: "role": "user", "content": "string", "graph_data": { + "references": { + "files": [ + { + "file_id": "fileId", + "score": 0, + "text": "text", + "cite": "cite", + "page": 0, + } + ], + "web": [ + { + "score": 0, + "text": "text", + "title": "title", + "url": "https://example.com", + } + ], + }, "sources": [ { "file_id": "file_id", @@ -139,6 +158,25 @@ def test_method_chat_with_all_params_overload_2(self, client: Writer) -> None: "role": "user", "content": "string", "graph_data": { + "references": { + "files": [ + { + "file_id": "fileId", + "score": 0, + "text": "text", + "cite": "cite", + "page": 0, + } + ], + "web": [ + { + "score": 0, + "text": "text", + "title": "title", + "url": "https://example.com", + } + ], + }, "sources": [ { "file_id": "file_id", @@ -251,6 +289,25 @@ async def test_method_chat_with_all_params_overload_1(self, async_client: AsyncW "role": "user", "content": "string", "graph_data": { + "references": { + "files": [ + { + "file_id": "fileId", + "score": 0, + "text": "text", + "cite": "cite", + "page": 0, + } + ], + "web": [ + { + "score": 0, + "text": "text", + "title": "title", + "url": "https://example.com", + } + ], + }, "sources": [ { "file_id": "file_id", @@ -357,6 +414,25 @@ async def test_method_chat_with_all_params_overload_2(self, async_client: AsyncW "role": "user", "content": "string", "graph_data": { + "references": { + "files": [ + { + "file_id": "fileId", + "score": 0, + "text": "text", + "cite": "cite", + "page": 0, + } + ], + "web": [ + { + "score": 0, + "text": "text", + "title": "title", + "url": "https://example.com", + } + ], + }, "sources": [ { "file_id": "file_id", diff --git a/tests/api_resources/test_tools.py b/tests/api_resources/test_tools.py index 8e2787aa..971657ee 100644 --- a/tests/api_resources/test_tools.py +++ b/tests/api_resources/test_tools.py @@ -16,6 +16,8 @@ ToolContextAwareSplittingResponse, ) +# pyright: reportDeprecated=false + base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -24,16 +26,19 @@ class TestTools: @parametrize def test_method_ai_detect(self, client: Writer) -> None: - tool = client.tools.ai_detect( - input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", - ) + with pytest.warns(DeprecationWarning): + tool = client.tools.ai_detect( + input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", + ) + assert_matches_type(ToolAIDetectResponse, tool, path=["response"]) @parametrize def test_raw_response_ai_detect(self, client: Writer) -> None: - response = client.tools.with_raw_response.ai_detect( - input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", - ) + with pytest.warns(DeprecationWarning): + response = client.tools.with_raw_response.ai_detect( + input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -42,31 +47,35 @@ def test_raw_response_ai_detect(self, client: Writer) -> None: @parametrize def test_streaming_response_ai_detect(self, client: Writer) -> None: - with client.tools.with_streaming_response.ai_detect( - input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + with client.tools.with_streaming_response.ai_detect( + input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = response.parse() - assert_matches_type(ToolAIDetectResponse, tool, path=["response"]) + tool = response.parse() + assert_matches_type(ToolAIDetectResponse, tool, path=["response"]) assert cast(Any, response.is_closed) is True @parametrize def test_method_context_aware_splitting(self, client: Writer) -> None: - tool = client.tools.context_aware_splitting( - strategy="llm_split", - text="text", - ) + with pytest.warns(DeprecationWarning): + tool = client.tools.context_aware_splitting( + strategy="llm_split", + text="text", + ) + assert_matches_type(ToolContextAwareSplittingResponse, tool, path=["response"]) @parametrize def test_raw_response_context_aware_splitting(self, client: Writer) -> None: - response = client.tools.with_raw_response.context_aware_splitting( - strategy="llm_split", - text="text", - ) + with pytest.warns(DeprecationWarning): + response = client.tools.with_raw_response.context_aware_splitting( + strategy="llm_split", + text="text", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -75,32 +84,36 @@ def test_raw_response_context_aware_splitting(self, client: Writer) -> None: @parametrize def test_streaming_response_context_aware_splitting(self, client: Writer) -> None: - with client.tools.with_streaming_response.context_aware_splitting( - strategy="llm_split", - text="text", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + with client.tools.with_streaming_response.context_aware_splitting( + strategy="llm_split", + text="text", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = response.parse() - assert_matches_type(ToolContextAwareSplittingResponse, tool, path=["response"]) + tool = response.parse() + assert_matches_type(ToolContextAwareSplittingResponse, tool, path=["response"]) assert cast(Any, response.is_closed) is True @parametrize def test_method_parse_pdf(self, client: Writer) -> None: - tool = client.tools.parse_pdf( - file_id="file_id", - format="text", - ) + with pytest.warns(DeprecationWarning): + tool = client.tools.parse_pdf( + file_id="file_id", + format="text", + ) + assert_matches_type(ToolParsePdfResponse, tool, path=["response"]) @parametrize def test_raw_response_parse_pdf(self, client: Writer) -> None: - response = client.tools.with_raw_response.parse_pdf( - file_id="file_id", - format="text", - ) + with pytest.warns(DeprecationWarning): + response = client.tools.with_raw_response.parse_pdf( + file_id="file_id", + format="text", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -109,53 +122,60 @@ def test_raw_response_parse_pdf(self, client: Writer) -> None: @parametrize def test_streaming_response_parse_pdf(self, client: Writer) -> None: - with client.tools.with_streaming_response.parse_pdf( - file_id="file_id", - format="text", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + with client.tools.with_streaming_response.parse_pdf( + file_id="file_id", + format="text", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = response.parse() - assert_matches_type(ToolParsePdfResponse, tool, path=["response"]) + tool = response.parse() + assert_matches_type(ToolParsePdfResponse, tool, path=["response"]) assert cast(Any, response.is_closed) is True @parametrize def test_path_params_parse_pdf(self, client: Writer) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): - client.tools.with_raw_response.parse_pdf( - file_id="", - format="text", - ) + with pytest.warns(DeprecationWarning): + with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): + client.tools.with_raw_response.parse_pdf( + file_id="", + format="text", + ) @parametrize def test_method_web_search(self, client: Writer) -> None: - tool = client.tools.web_search() + with pytest.warns(DeprecationWarning): + tool = client.tools.web_search() + assert_matches_type(ToolWebSearchResponse, tool, path=["response"]) @parametrize def test_method_web_search_with_all_params(self, client: Writer) -> None: - tool = client.tools.web_search( - chunks_per_source=0, - country="afghanistan", - days=0, - exclude_domains=["string"], - include_answer=True, - include_domains=["dev.writer.com"], - include_raw_content="text", - max_results=0, - query="How do I get an API key for the Writer API?", - search_depth="basic", - stream=True, - time_range="day", - topic="general", - ) + with pytest.warns(DeprecationWarning): + tool = client.tools.web_search( + chunks_per_source=0, + country="afghanistan", + days=0, + exclude_domains=["string"], + include_answer=True, + include_domains=["dev.writer.com"], + include_raw_content="text", + max_results=0, + query="How do I get an API key for the Writer API?", + search_depth="basic", + stream=True, + time_range="day", + topic="general", + ) + assert_matches_type(ToolWebSearchResponse, tool, path=["response"]) @parametrize def test_raw_response_web_search(self, client: Writer) -> None: - response = client.tools.with_raw_response.web_search() + with pytest.warns(DeprecationWarning): + response = client.tools.with_raw_response.web_search() assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -164,12 +184,13 @@ def test_raw_response_web_search(self, client: Writer) -> None: @parametrize def test_streaming_response_web_search(self, client: Writer) -> None: - with client.tools.with_streaming_response.web_search() as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + with client.tools.with_streaming_response.web_search() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = response.parse() - assert_matches_type(ToolWebSearchResponse, tool, path=["response"]) + tool = response.parse() + assert_matches_type(ToolWebSearchResponse, tool, path=["response"]) assert cast(Any, response.is_closed) is True @@ -181,16 +202,19 @@ class TestAsyncTools: @parametrize async def test_method_ai_detect(self, async_client: AsyncWriter) -> None: - tool = await async_client.tools.ai_detect( - input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", - ) + with pytest.warns(DeprecationWarning): + tool = await async_client.tools.ai_detect( + input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", + ) + assert_matches_type(ToolAIDetectResponse, tool, path=["response"]) @parametrize async def test_raw_response_ai_detect(self, async_client: AsyncWriter) -> None: - response = await async_client.tools.with_raw_response.ai_detect( - input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", - ) + with pytest.warns(DeprecationWarning): + response = await async_client.tools.with_raw_response.ai_detect( + input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -199,31 +223,35 @@ async def test_raw_response_ai_detect(self, async_client: AsyncWriter) -> None: @parametrize async def test_streaming_response_ai_detect(self, async_client: AsyncWriter) -> None: - async with async_client.tools.with_streaming_response.ai_detect( - input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + async with async_client.tools.with_streaming_response.ai_detect( + input="AI and ML continue to be at the forefront of technological advancements. In 2025, we can expect more sophisticated AI systems that can handle complex tasks with greater efficiency. AI will play a crucial role in various sectors, including healthcare, finance, and manufacturing. For instance, AI-powered diagnostic tools will become more accurate, helping doctors detect diseases at an early stage. In finance, AI algorithms will enhance fraud detection and risk management.", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = await response.parse() - assert_matches_type(ToolAIDetectResponse, tool, path=["response"]) + tool = await response.parse() + assert_matches_type(ToolAIDetectResponse, tool, path=["response"]) assert cast(Any, response.is_closed) is True @parametrize async def test_method_context_aware_splitting(self, async_client: AsyncWriter) -> None: - tool = await async_client.tools.context_aware_splitting( - strategy="llm_split", - text="text", - ) + with pytest.warns(DeprecationWarning): + tool = await async_client.tools.context_aware_splitting( + strategy="llm_split", + text="text", + ) + assert_matches_type(ToolContextAwareSplittingResponse, tool, path=["response"]) @parametrize async def test_raw_response_context_aware_splitting(self, async_client: AsyncWriter) -> None: - response = await async_client.tools.with_raw_response.context_aware_splitting( - strategy="llm_split", - text="text", - ) + with pytest.warns(DeprecationWarning): + response = await async_client.tools.with_raw_response.context_aware_splitting( + strategy="llm_split", + text="text", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -232,32 +260,36 @@ async def test_raw_response_context_aware_splitting(self, async_client: AsyncWri @parametrize async def test_streaming_response_context_aware_splitting(self, async_client: AsyncWriter) -> None: - async with async_client.tools.with_streaming_response.context_aware_splitting( - strategy="llm_split", - text="text", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + async with async_client.tools.with_streaming_response.context_aware_splitting( + strategy="llm_split", + text="text", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = await response.parse() - assert_matches_type(ToolContextAwareSplittingResponse, tool, path=["response"]) + tool = await response.parse() + assert_matches_type(ToolContextAwareSplittingResponse, tool, path=["response"]) assert cast(Any, response.is_closed) is True @parametrize async def test_method_parse_pdf(self, async_client: AsyncWriter) -> None: - tool = await async_client.tools.parse_pdf( - file_id="file_id", - format="text", - ) + with pytest.warns(DeprecationWarning): + tool = await async_client.tools.parse_pdf( + file_id="file_id", + format="text", + ) + assert_matches_type(ToolParsePdfResponse, tool, path=["response"]) @parametrize async def test_raw_response_parse_pdf(self, async_client: AsyncWriter) -> None: - response = await async_client.tools.with_raw_response.parse_pdf( - file_id="file_id", - format="text", - ) + with pytest.warns(DeprecationWarning): + response = await async_client.tools.with_raw_response.parse_pdf( + file_id="file_id", + format="text", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -266,53 +298,60 @@ async def test_raw_response_parse_pdf(self, async_client: AsyncWriter) -> None: @parametrize async def test_streaming_response_parse_pdf(self, async_client: AsyncWriter) -> None: - async with async_client.tools.with_streaming_response.parse_pdf( - file_id="file_id", - format="text", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + async with async_client.tools.with_streaming_response.parse_pdf( + file_id="file_id", + format="text", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = await response.parse() - assert_matches_type(ToolParsePdfResponse, tool, path=["response"]) + tool = await response.parse() + assert_matches_type(ToolParsePdfResponse, tool, path=["response"]) assert cast(Any, response.is_closed) is True @parametrize async def test_path_params_parse_pdf(self, async_client: AsyncWriter) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): - await async_client.tools.with_raw_response.parse_pdf( - file_id="", - format="text", - ) + with pytest.warns(DeprecationWarning): + with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): + await async_client.tools.with_raw_response.parse_pdf( + file_id="", + format="text", + ) @parametrize async def test_method_web_search(self, async_client: AsyncWriter) -> None: - tool = await async_client.tools.web_search() + with pytest.warns(DeprecationWarning): + tool = await async_client.tools.web_search() + assert_matches_type(ToolWebSearchResponse, tool, path=["response"]) @parametrize async def test_method_web_search_with_all_params(self, async_client: AsyncWriter) -> None: - tool = await async_client.tools.web_search( - chunks_per_source=0, - country="afghanistan", - days=0, - exclude_domains=["string"], - include_answer=True, - include_domains=["dev.writer.com"], - include_raw_content="text", - max_results=0, - query="How do I get an API key for the Writer API?", - search_depth="basic", - stream=True, - time_range="day", - topic="general", - ) + with pytest.warns(DeprecationWarning): + tool = await async_client.tools.web_search( + chunks_per_source=0, + country="afghanistan", + days=0, + exclude_domains=["string"], + include_answer=True, + include_domains=["dev.writer.com"], + include_raw_content="text", + max_results=0, + query="How do I get an API key for the Writer API?", + search_depth="basic", + stream=True, + time_range="day", + topic="general", + ) + assert_matches_type(ToolWebSearchResponse, tool, path=["response"]) @parametrize async def test_raw_response_web_search(self, async_client: AsyncWriter) -> None: - response = await async_client.tools.with_raw_response.web_search() + with pytest.warns(DeprecationWarning): + response = await async_client.tools.with_raw_response.web_search() assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -321,11 +360,12 @@ async def test_raw_response_web_search(self, async_client: AsyncWriter) -> None: @parametrize async def test_streaming_response_web_search(self, async_client: AsyncWriter) -> None: - async with async_client.tools.with_streaming_response.web_search() as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + async with async_client.tools.with_streaming_response.web_search() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - tool = await response.parse() - assert_matches_type(ToolWebSearchResponse, tool, path=["response"]) + tool = await response.parse() + assert_matches_type(ToolWebSearchResponse, tool, path=["response"]) assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/test_translation.py b/tests/api_resources/test_translation.py index e7a0babc..12497e7a 100644 --- a/tests/api_resources/test_translation.py +++ b/tests/api_resources/test_translation.py @@ -11,6 +11,8 @@ from tests.utils import assert_matches_type from writerai.types import TranslationResponse +# pyright: reportDeprecated=false + base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -19,28 +21,31 @@ class TestTranslation: @parametrize def test_method_translate(self, client: Writer) -> None: - translation = client.translation.translate( - formality=True, - length_control=True, - mask_profanity=True, - model="palmyra-translate", - source_language_code="en", - target_language_code="es", - text="Hello, world!", - ) + with pytest.warns(DeprecationWarning): + translation = client.translation.translate( + formality=True, + length_control=True, + mask_profanity=True, + model="palmyra-translate", + source_language_code="en", + target_language_code="es", + text="Hello, world!", + ) + assert_matches_type(TranslationResponse, translation, path=["response"]) @parametrize def test_raw_response_translate(self, client: Writer) -> None: - response = client.translation.with_raw_response.translate( - formality=True, - length_control=True, - mask_profanity=True, - model="palmyra-translate", - source_language_code="en", - target_language_code="es", - text="Hello, world!", - ) + with pytest.warns(DeprecationWarning): + response = client.translation.with_raw_response.translate( + formality=True, + length_control=True, + mask_profanity=True, + model="palmyra-translate", + source_language_code="en", + target_language_code="es", + text="Hello, world!", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -49,20 +54,21 @@ def test_raw_response_translate(self, client: Writer) -> None: @parametrize def test_streaming_response_translate(self, client: Writer) -> None: - with client.translation.with_streaming_response.translate( - formality=True, - length_control=True, - mask_profanity=True, - model="palmyra-translate", - source_language_code="en", - target_language_code="es", - text="Hello, world!", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - translation = response.parse() - assert_matches_type(TranslationResponse, translation, path=["response"]) + with pytest.warns(DeprecationWarning): + with client.translation.with_streaming_response.translate( + formality=True, + length_control=True, + mask_profanity=True, + model="palmyra-translate", + source_language_code="en", + target_language_code="es", + text="Hello, world!", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + translation = response.parse() + assert_matches_type(TranslationResponse, translation, path=["response"]) assert cast(Any, response.is_closed) is True @@ -74,28 +80,31 @@ class TestAsyncTranslation: @parametrize async def test_method_translate(self, async_client: AsyncWriter) -> None: - translation = await async_client.translation.translate( - formality=True, - length_control=True, - mask_profanity=True, - model="palmyra-translate", - source_language_code="en", - target_language_code="es", - text="Hello, world!", - ) + with pytest.warns(DeprecationWarning): + translation = await async_client.translation.translate( + formality=True, + length_control=True, + mask_profanity=True, + model="palmyra-translate", + source_language_code="en", + target_language_code="es", + text="Hello, world!", + ) + assert_matches_type(TranslationResponse, translation, path=["response"]) @parametrize async def test_raw_response_translate(self, async_client: AsyncWriter) -> None: - response = await async_client.translation.with_raw_response.translate( - formality=True, - length_control=True, - mask_profanity=True, - model="palmyra-translate", - source_language_code="en", - target_language_code="es", - text="Hello, world!", - ) + with pytest.warns(DeprecationWarning): + response = await async_client.translation.with_raw_response.translate( + formality=True, + length_control=True, + mask_profanity=True, + model="palmyra-translate", + source_language_code="en", + target_language_code="es", + text="Hello, world!", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -104,19 +113,20 @@ async def test_raw_response_translate(self, async_client: AsyncWriter) -> None: @parametrize async def test_streaming_response_translate(self, async_client: AsyncWriter) -> None: - async with async_client.translation.with_streaming_response.translate( - formality=True, - length_control=True, - mask_profanity=True, - model="palmyra-translate", - source_language_code="en", - target_language_code="es", - text="Hello, world!", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - translation = await response.parse() - assert_matches_type(TranslationResponse, translation, path=["response"]) + with pytest.warns(DeprecationWarning): + async with async_client.translation.with_streaming_response.translate( + formality=True, + length_control=True, + mask_profanity=True, + model="palmyra-translate", + source_language_code="en", + target_language_code="es", + text="Hello, world!", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + translation = await response.parse() + assert_matches_type(TranslationResponse, translation, path=["response"]) assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/tools/test_comprehend.py b/tests/api_resources/tools/test_comprehend.py index 6f7efe39..59e9dd9f 100644 --- a/tests/api_resources/tools/test_comprehend.py +++ b/tests/api_resources/tools/test_comprehend.py @@ -11,6 +11,8 @@ from tests.utils import assert_matches_type from writerai.types.tools import ComprehendMedicalResponse +# pyright: reportDeprecated=false + base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -19,18 +21,21 @@ class TestComprehend: @parametrize def test_method_medical(self, client: Writer) -> None: - comprehend = client.tools.comprehend.medical( - content="content", - response_type="Entities", - ) + with pytest.warns(DeprecationWarning): + comprehend = client.tools.comprehend.medical( + content="content", + response_type="Entities", + ) + assert_matches_type(ComprehendMedicalResponse, comprehend, path=["response"]) @parametrize def test_raw_response_medical(self, client: Writer) -> None: - response = client.tools.comprehend.with_raw_response.medical( - content="content", - response_type="Entities", - ) + with pytest.warns(DeprecationWarning): + response = client.tools.comprehend.with_raw_response.medical( + content="content", + response_type="Entities", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -39,15 +44,16 @@ def test_raw_response_medical(self, client: Writer) -> None: @parametrize def test_streaming_response_medical(self, client: Writer) -> None: - with client.tools.comprehend.with_streaming_response.medical( - content="content", - response_type="Entities", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + with pytest.warns(DeprecationWarning): + with client.tools.comprehend.with_streaming_response.medical( + content="content", + response_type="Entities", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" - comprehend = response.parse() - assert_matches_type(ComprehendMedicalResponse, comprehend, path=["response"]) + comprehend = response.parse() + assert_matches_type(ComprehendMedicalResponse, comprehend, path=["response"]) assert cast(Any, response.is_closed) is True @@ -59,18 +65,21 @@ class TestAsyncComprehend: @parametrize async def test_method_medical(self, async_client: AsyncWriter) -> None: - comprehend = await async_client.tools.comprehend.medical( - content="content", - response_type="Entities", - ) + with pytest.warns(DeprecationWarning): + comprehend = await async_client.tools.comprehend.medical( + content="content", + response_type="Entities", + ) + assert_matches_type(ComprehendMedicalResponse, comprehend, path=["response"]) @parametrize async def test_raw_response_medical(self, async_client: AsyncWriter) -> None: - response = await async_client.tools.comprehend.with_raw_response.medical( - content="content", - response_type="Entities", - ) + with pytest.warns(DeprecationWarning): + response = await async_client.tools.comprehend.with_raw_response.medical( + content="content", + response_type="Entities", + ) assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -79,14 +88,15 @@ async def test_raw_response_medical(self, async_client: AsyncWriter) -> None: @parametrize async def test_streaming_response_medical(self, async_client: AsyncWriter) -> None: - async with async_client.tools.comprehend.with_streaming_response.medical( - content="content", - response_type="Entities", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - comprehend = await response.parse() - assert_matches_type(ComprehendMedicalResponse, comprehend, path=["response"]) + with pytest.warns(DeprecationWarning): + async with async_client.tools.comprehend.with_streaming_response.medical( + content="content", + response_type="Entities", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + comprehend = await response.parse() + assert_matches_type(ComprehendMedicalResponse, comprehend, path=["response"]) assert cast(Any, response.is_closed) is True diff --git a/tests/test_transform.py b/tests/test_transform.py index fe86aaaf..8fb16570 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -8,7 +8,7 @@ import pytest -from writerai._types import NOT_GIVEN, Base64FileInput +from writerai._types import Base64FileInput, omit, not_given from writerai._utils import ( PropertyInfo, transform as _transform, @@ -450,4 +450,11 @@ async def test_transform_skipping(use_async: bool) -> None: @pytest.mark.asyncio async def test_strips_notgiven(use_async: bool) -> None: assert await transform({"foo_bar": "bar"}, Foo1, use_async) == {"fooBar": "bar"} - assert await transform({"foo_bar": NOT_GIVEN}, Foo1, use_async) == {} + assert await transform({"foo_bar": not_given}, Foo1, use_async) == {} + + +@parametrize +@pytest.mark.asyncio +async def test_strips_omit(use_async: bool) -> None: + assert await transform({"foo_bar": "bar"}, Foo1, use_async) == {"fooBar": "bar"} + assert await transform({"foo_bar": omit}, Foo1, use_async) == {}