diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ac2a7df..4335d76 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,13 +31,13 @@ $ pip install -r requirements-dev.lock ## Modifying/Adding code -Most of the SDK is generated code, and any modified code will be overridden on the next generation. The -`src/writerai/lib/` and `examples/` directories are exceptions and will never be overridden. +Most of the SDK is generated code. Modifications to code will be persisted between generations, but may +result in merge conflicts between manual patches and changes from the generator. The generator will never +modify the contents of the `src/writerai/lib/` and `examples/` directories. ## Adding and running examples -All files in the `examples/` directory are not modified by the Stainless generator and can be freely edited or -added to. +All files in the `examples/` directory are not modified by the generator and can be freely edited or added to. ```bash # add an example to examples/.py diff --git a/README.md b/README.md index a1dcf0c..edd04b3 100644 --- a/README.md +++ b/README.md @@ -391,6 +391,17 @@ We take backwards-compatibility seriously and work hard to ensure you can rely o We are keen for your feedback; please open an [issue](https://www.github.com/writer/writer-python/issues) with questions, bugs, or suggestions. +### Determining the installed version + +If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version. + +You can determine the version that is being used at runtime with: + +```py +import writerai +print(writerai.__version__) +``` + ## Requirements Python 3.7 or higher. diff --git a/requirements-dev.lock b/requirements-dev.lock index baa25f2..d3ee1e6 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -49,7 +49,7 @@ markdown-it-py==3.0.0 # via rich mdurl==0.1.2 # via markdown-it-py -mypy==1.10.1 +mypy==1.11.2 mypy-extensions==1.0.0 # via mypy nodeenv==1.8.0 @@ -70,7 +70,7 @@ pydantic-core==2.18.2 # via pydantic pygments==2.18.0 # via rich -pyright==1.1.374 +pyright==1.1.380 pytest==7.1.1 # via pytest-asyncio pytest-asyncio==0.21.1 @@ -80,7 +80,7 @@ pytz==2023.3.post1 # via dirty-equals respx==0.20.2 rich==13.7.1 -ruff==0.5.6 +ruff==0.6.5 setuptools==68.2.2 # via nodeenv six==1.16.0 diff --git a/src/writerai/_utils/_utils.py b/src/writerai/_utils/_utils.py index 2fc5a1c..0bba17c 100644 --- a/src/writerai/_utils/_utils.py +++ b/src/writerai/_utils/_utils.py @@ -363,12 +363,13 @@ def file_from_path(path: str) -> FileTypes: def get_required_header(headers: HeadersLike, header: str) -> str: lower_header = header.lower() - if isinstance(headers, Mapping): - for k, v in headers.items(): + if is_mapping_t(headers): + # mypy doesn't understand the type narrowing here + for k, v in headers.items(): # type: ignore if k.lower() == lower_header and isinstance(v, str): return v - """ to deal with the case where the header looks like Stainless-Event-Id """ + # to deal with the case where the header looks like Stainless-Event-Id intercaps_header = re.sub(r"([^\w])(\w)", lambda pat: pat.group(1) + pat.group(2).upper(), header.capitalize()) for normalized_header in [header, lower_header, header.upper(), intercaps_header]: diff --git a/src/writerai/resources/applications.py b/src/writerai/resources/applications.py index e32d740..a9f031f 100644 --- a/src/writerai/resources/applications.py +++ b/src/writerai/resources/applications.py @@ -29,10 +29,21 @@ class ApplicationsResource(SyncAPIResource): @cached_property def with_raw_response(self) -> ApplicationsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return ApplicationsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> ApplicationsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return ApplicationsResourceWithStreamingResponse(self) def generate_content( @@ -76,10 +87,21 @@ def generate_content( class AsyncApplicationsResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncApplicationsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return AsyncApplicationsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncApplicationsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return AsyncApplicationsResourceWithStreamingResponse(self) async def generate_content( diff --git a/src/writerai/resources/chat.py b/src/writerai/resources/chat.py index 4d13ab8..3ccead3 100644 --- a/src/writerai/resources/chat.py +++ b/src/writerai/resources/chat.py @@ -33,10 +33,21 @@ class ChatResource(SyncAPIResource): @cached_property def with_raw_response(self) -> ChatResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return ChatResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> ChatResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return ChatResourceWithStreamingResponse(self) @overload @@ -308,10 +319,21 @@ def chat( class AsyncChatResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncChatResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return AsyncChatResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncChatResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return AsyncChatResourceWithStreamingResponse(self) @overload diff --git a/src/writerai/resources/completions.py b/src/writerai/resources/completions.py index 6962f7b..addef7f 100644 --- a/src/writerai/resources/completions.py +++ b/src/writerai/resources/completions.py @@ -33,10 +33,21 @@ class CompletionsResource(SyncAPIResource): @cached_property def with_raw_response(self) -> CompletionsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return CompletionsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> CompletionsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return CompletionsResourceWithStreamingResponse(self) @overload @@ -270,10 +281,21 @@ def create( class AsyncCompletionsResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncCompletionsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return AsyncCompletionsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncCompletionsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return AsyncCompletionsResourceWithStreamingResponse(self) @overload diff --git a/src/writerai/resources/files.py b/src/writerai/resources/files.py index 49a758a..8ce6c78 100644 --- a/src/writerai/resources/files.py +++ b/src/writerai/resources/files.py @@ -36,10 +36,21 @@ class FilesResource(SyncAPIResource): @cached_property def with_raw_response(self) -> FilesResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return FilesResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> FilesResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return FilesResourceWithStreamingResponse(self) def retrieve( @@ -254,10 +265,21 @@ def upload( class AsyncFilesResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncFilesResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return AsyncFilesResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncFilesResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return AsyncFilesResourceWithStreamingResponse(self) async def retrieve( diff --git a/src/writerai/resources/graphs.py b/src/writerai/resources/graphs.py index 7c8b069..d43b6bc 100644 --- a/src/writerai/resources/graphs.py +++ b/src/writerai/resources/graphs.py @@ -40,10 +40,21 @@ class GraphsResource(SyncAPIResource): @cached_property def with_raw_response(self) -> GraphsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return GraphsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> GraphsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return GraphsResourceWithStreamingResponse(self) def create( @@ -374,10 +385,21 @@ def remove_file_from_graph( class AsyncGraphsResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncGraphsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return AsyncGraphsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncGraphsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return AsyncGraphsResourceWithStreamingResponse(self) async def create( diff --git a/src/writerai/resources/models.py b/src/writerai/resources/models.py index 14028e9..6841015 100644 --- a/src/writerai/resources/models.py +++ b/src/writerai/resources/models.py @@ -22,10 +22,21 @@ class ModelsResource(SyncAPIResource): @cached_property def with_raw_response(self) -> ModelsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return ModelsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> ModelsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return ModelsResourceWithStreamingResponse(self) def list( @@ -51,10 +62,21 @@ def list( class AsyncModelsResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncModelsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers + """ return AsyncModelsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncModelsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/writer/writer-python#with_streaming_response + """ return AsyncModelsResourceWithStreamingResponse(self) async def list( diff --git a/src/writerai/types/chat_chat_params.py b/src/writerai/types/chat_chat_params.py index 113ed71..96d27aa 100644 --- a/src/writerai/types/chat_chat_params.py +++ b/src/writerai/types/chat_chat_params.py @@ -114,7 +114,7 @@ class Tool(TypedDict, total=False): type: Required[str] -class ChatChatParamsNonStreaming(ChatChatParamsBase): +class ChatChatParamsNonStreaming(ChatChatParamsBase, total=False): stream: Literal[False] """ Indicates whether the response should be streamed incrementally as it is diff --git a/src/writerai/types/completion_create_params.py b/src/writerai/types/completion_create_params.py index 6436f60..20ad406 100644 --- a/src/writerai/types/completion_create_params.py +++ b/src/writerai/types/completion_create_params.py @@ -53,7 +53,7 @@ class CompletionCreateParamsBase(TypedDict, total=False): """ -class CompletionCreateParamsNonStreaming(CompletionCreateParamsBase): +class CompletionCreateParamsNonStreaming(CompletionCreateParamsBase, total=False): stream: Literal[False] """Determines whether the model's output should be streamed.