Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@

from spitch import Spitch

client = Spitch(api_key=os.getenv('SPITCH_API_KEY'))
client = Spitch(api_key=os.getenv("SPITCH_API_KEY"))
speech_file_path = Path(__file__).parent / "audio.mp3"


def main() -> None:
start_time = time.time()
with client.speech.with_streaming_response.generate(
language="yo",
text="Bawo ni ololufe?",
voice="funmi"
language="yo", text="Bawo ni ololufe?", voice="funmi"
) as speech:
print(f"Time to first byte: {int((time.time() - start_time) * 1000)}ms")
speech.stream_to_file(speech_file_path)
Expand Down
4 changes: 3 additions & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.28.1
httpx==0.27.2
# via respx
# via spitch
idna==3.4
Expand Down Expand Up @@ -90,6 +90,7 @@ six==1.16.0
# via python-dateutil
sniffio==1.3.0
# via anyio
# via httpx
# via spitch
time-machine==2.9.0
tomli==2.0.2
Expand All @@ -100,6 +101,7 @@ typing-extensions==4.12.2
# via mypy
# via pydantic
# via pydantic-core
# via pyright
# via spitch
virtualenv==20.24.5
# via nox
Expand Down
3 changes: 2 additions & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.28.1
httpx==0.27.2
# via spitch
idna==3.4
# via anyio
Expand All @@ -37,6 +37,7 @@ pydantic-core==2.23.4
# via pydantic
sniffio==1.3.0
# via anyio
# via httpx
# via spitch
typing-extensions==4.12.2
# via anyio
Expand Down
2 changes: 1 addition & 1 deletion src/spitch/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ def __init__(
self._client = http_client or SyncHttpxClientWrapper(
base_url=base_url,
# cast to a valid type because mypy doesn't understand our type narrowing
timeout=cast(Timeout, timeout)
timeout=cast(Timeout, timeout),
)

def is_closed(self) -> bool:
Expand Down
5 changes: 2 additions & 3 deletions src/spitch/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
raise ValueError(f"Subclasses of httpx.Response cannot be passed to `cast_to`")
return cast(R, response)

if inspect.isclass(origin) and not issubclass(origin, BaseModel) and issubclass(origin, pydantic.BaseModel):
raise TypeError("Pydantic models must subclass our base model type, e.g. `from openai import BaseModel`")
if inspect.isclass(origin) and not issubclass(origin, BaseModel) and issubclass(origin, pydantic.BaseModel): # type: ignore
raise TypeError("Pydantic models must subclass our base model type, e.g. `from spitch import BaseModel`")

if (
cast_to is not object
Expand Down Expand Up @@ -261,7 +261,6 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
)



class APIResponse(BaseAPIResponse[R]):
@overload
def parse(self, *, to: type[_T]) -> _T: ...
Expand Down
10 changes: 2 additions & 8 deletions src/spitch/resources/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,7 @@ class SpeechResourceWithStreamingResponse:
def __init__(self, speech: SpeechResource) -> None:
self._speech = speech

self.generate = to_custom_streamed_response_wrapper(
speech.generate,
StreamedBinaryAPIResponse
)
self.generate = to_custom_streamed_response_wrapper(speech.generate, StreamedBinaryAPIResponse)
self.transcribe = to_streamed_response_wrapper(
speech.transcribe,
)
Expand All @@ -359,10 +356,7 @@ class AsyncSpeechResourceWithStreamingResponse:
def __init__(self, speech: AsyncSpeechResource) -> None:
self._speech = speech

self.generate = async_to_custom_streamed_response_wrapper(
speech.generate,
AsyncStreamedBinaryAPIResponse
)
self.generate = async_to_custom_streamed_response_wrapper(speech.generate, AsyncStreamedBinaryAPIResponse)
self.transcribe = async_to_streamed_response_wrapper(
speech.transcribe,
)
3 changes: 2 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from typing import Any, Dict, List, Union, Optional, cast
from datetime import datetime, timezone
from typing_extensions import Literal, Annotated
from typing_extensions import Literal, Annotated, TypeAliasType

import pytest
import pydantic
Expand Down Expand Up @@ -824,6 +824,7 @@ class B(BaseModel):
# we hit the cache
assert UnionType.__discriminator__ is discriminator


@pytest.mark.skipif(not PYDANTIC_V2, reason="TypeAliasType is not supported in Pydantic v1")
def test_type_alias_type() -> None:
Alias = TypeAliasType("Alias", str) # pyright: ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ async def test_transform_skipping(use_async: bool) -> None:
assert await transform(data, List[int], use_async) is data

# iterables of ints are converted to a list
data = iter([1, 2, 3])
data = iter([1, 2, 3]) # type: ignore
assert await transform(data, Iterable[int], use_async) == [1, 2, 3]


Expand Down