Skip to content

Commit

Permalink
chore(internal): codegen related update (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Sep 20, 2024
1 parent a86b730 commit 8ecc8f5
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 12 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<your-example>.py
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 3 additions & 3 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/writerai/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
22 changes: 22 additions & 0 deletions src/writerai/resources/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 22 additions & 0 deletions src/writerai/resources/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/writerai/resources/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/writerai/resources/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 22 additions & 0 deletions src/writerai/resources/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 22 additions & 0 deletions src/writerai/resources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/writerai/types/chat_chat_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/writerai/types/completion_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8ecc8f5

Please sign in to comment.