sarvamai 0.1.23a2__py3-none-any.whl → 0.1.23a4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sarvamai/__init__.py +203 -405
- sarvamai/chat/raw_client.py +20 -20
- sarvamai/client.py +34 -186
- sarvamai/core/__init__.py +21 -76
- sarvamai/core/client_wrapper.py +3 -19
- sarvamai/core/force_multipart.py +2 -4
- sarvamai/core/http_client.py +97 -217
- sarvamai/core/http_response.py +1 -1
- sarvamai/core/jsonable_encoder.py +0 -8
- sarvamai/core/pydantic_utilities.py +4 -110
- sarvamai/errors/__init__.py +6 -40
- sarvamai/errors/bad_request_error.py +1 -1
- sarvamai/errors/forbidden_error.py +1 -1
- sarvamai/errors/internal_server_error.py +1 -1
- sarvamai/errors/service_unavailable_error.py +1 -1
- sarvamai/errors/too_many_requests_error.py +1 -1
- sarvamai/errors/unprocessable_entity_error.py +1 -1
- sarvamai/requests/__init__.py +62 -150
- sarvamai/requests/configure_connection.py +4 -0
- sarvamai/requests/configure_connection_data.py +40 -11
- sarvamai/requests/error_response_data.py +1 -1
- sarvamai/requests/file_signed_url_details.py +1 -1
- sarvamai/requests/speech_to_text_job_parameters.py +10 -1
- sarvamai/requests/speech_to_text_transcription_data.py +2 -2
- sarvamai/speech_to_text/client.py +29 -2
- sarvamai/speech_to_text/raw_client.py +81 -56
- sarvamai/speech_to_text_job/client.py +60 -15
- sarvamai/speech_to_text_job/raw_client.py +120 -120
- sarvamai/speech_to_text_streaming/__init__.py +10 -38
- sarvamai/speech_to_text_streaming/client.py +32 -6
- sarvamai/speech_to_text_streaming/raw_client.py +32 -6
- sarvamai/speech_to_text_streaming/types/__init__.py +8 -36
- sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_mode.py +7 -0
- sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_model.py +5 -0
- sarvamai/speech_to_text_translate_job/raw_client.py +120 -120
- sarvamai/speech_to_text_translate_streaming/__init__.py +5 -36
- sarvamai/speech_to_text_translate_streaming/types/__init__.py +3 -36
- sarvamai/text/raw_client.py +60 -60
- sarvamai/text_to_speech/client.py +100 -16
- sarvamai/text_to_speech/raw_client.py +120 -36
- sarvamai/text_to_speech_streaming/__init__.py +2 -29
- sarvamai/text_to_speech_streaming/client.py +19 -6
- sarvamai/text_to_speech_streaming/raw_client.py +19 -6
- sarvamai/text_to_speech_streaming/types/__init__.py +3 -31
- sarvamai/text_to_speech_streaming/types/text_to_speech_streaming_model.py +5 -0
- sarvamai/types/__init__.py +102 -222
- sarvamai/types/chat_completion_request_message.py +2 -6
- sarvamai/types/configure_connection.py +4 -0
- sarvamai/types/configure_connection_data.py +40 -11
- sarvamai/types/configure_connection_data_model.py +5 -0
- sarvamai/types/configure_connection_data_speaker.py +35 -1
- sarvamai/types/error_response_data.py +1 -1
- sarvamai/types/file_signed_url_details.py +1 -1
- sarvamai/types/mode.py +7 -0
- sarvamai/types/speech_to_text_job_parameters.py +10 -1
- sarvamai/types/speech_to_text_model.py +3 -1
- sarvamai/types/speech_to_text_transcription_data.py +2 -2
- sarvamai/types/speech_to_text_translate_model.py +1 -1
- sarvamai/types/text_to_speech_model.py +1 -1
- sarvamai/types/text_to_speech_speaker.py +35 -1
- {sarvamai-0.1.23a2.dist-info → sarvamai-0.1.23a4.dist-info}/METADATA +1 -2
- {sarvamai-0.1.23a2.dist-info → sarvamai-0.1.23a4.dist-info}/RECORD +63 -63
- sarvamai/core/http_sse/__init__.py +0 -42
- sarvamai/core/http_sse/_api.py +0 -112
- sarvamai/core/http_sse/_decoders.py +0 -61
- sarvamai/core/http_sse/_exceptions.py +0 -7
- sarvamai/core/http_sse/_models.py +0 -17
- {sarvamai-0.1.23a2.dist-info → sarvamai-0.1.23a4.dist-info}/WHEEL +0 -0
sarvamai/core/http_sse/_api.py
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import re
|
|
4
|
-
from contextlib import asynccontextmanager, contextmanager
|
|
5
|
-
from typing import Any, AsyncGenerator, AsyncIterator, Iterator, cast
|
|
6
|
-
|
|
7
|
-
import httpx
|
|
8
|
-
from ._decoders import SSEDecoder
|
|
9
|
-
from ._exceptions import SSEError
|
|
10
|
-
from ._models import ServerSentEvent
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class EventSource:
|
|
14
|
-
def __init__(self, response: httpx.Response) -> None:
|
|
15
|
-
self._response = response
|
|
16
|
-
|
|
17
|
-
def _check_content_type(self) -> None:
|
|
18
|
-
content_type = self._response.headers.get("content-type", "").partition(";")[0]
|
|
19
|
-
if "text/event-stream" not in content_type:
|
|
20
|
-
raise SSEError(
|
|
21
|
-
f"Expected response header Content-Type to contain 'text/event-stream', got {content_type!r}"
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
def _get_charset(self) -> str:
|
|
25
|
-
"""Extract charset from Content-Type header, fallback to UTF-8."""
|
|
26
|
-
content_type = self._response.headers.get("content-type", "")
|
|
27
|
-
|
|
28
|
-
# Parse charset parameter using regex
|
|
29
|
-
charset_match = re.search(r"charset=([^;\s]+)", content_type, re.IGNORECASE)
|
|
30
|
-
if charset_match:
|
|
31
|
-
charset = charset_match.group(1).strip("\"'")
|
|
32
|
-
# Validate that it's a known encoding
|
|
33
|
-
try:
|
|
34
|
-
# Test if the charset is valid by trying to encode/decode
|
|
35
|
-
"test".encode(charset).decode(charset)
|
|
36
|
-
return charset
|
|
37
|
-
except (LookupError, UnicodeError):
|
|
38
|
-
# If charset is invalid, fall back to UTF-8
|
|
39
|
-
pass
|
|
40
|
-
|
|
41
|
-
# Default to UTF-8 if no charset specified or invalid charset
|
|
42
|
-
return "utf-8"
|
|
43
|
-
|
|
44
|
-
@property
|
|
45
|
-
def response(self) -> httpx.Response:
|
|
46
|
-
return self._response
|
|
47
|
-
|
|
48
|
-
def iter_sse(self) -> Iterator[ServerSentEvent]:
|
|
49
|
-
self._check_content_type()
|
|
50
|
-
decoder = SSEDecoder()
|
|
51
|
-
charset = self._get_charset()
|
|
52
|
-
|
|
53
|
-
buffer = ""
|
|
54
|
-
for chunk in self._response.iter_bytes():
|
|
55
|
-
# Decode chunk using detected charset
|
|
56
|
-
text_chunk = chunk.decode(charset, errors="replace")
|
|
57
|
-
buffer += text_chunk
|
|
58
|
-
|
|
59
|
-
# Process complete lines
|
|
60
|
-
while "\n" in buffer:
|
|
61
|
-
line, buffer = buffer.split("\n", 1)
|
|
62
|
-
line = line.rstrip("\r")
|
|
63
|
-
sse = decoder.decode(line)
|
|
64
|
-
# when we reach a "\n\n" => line = ''
|
|
65
|
-
# => decoder will attempt to return an SSE Event
|
|
66
|
-
if sse is not None:
|
|
67
|
-
yield sse
|
|
68
|
-
|
|
69
|
-
# Process any remaining data in buffer
|
|
70
|
-
if buffer.strip():
|
|
71
|
-
line = buffer.rstrip("\r")
|
|
72
|
-
sse = decoder.decode(line)
|
|
73
|
-
if sse is not None:
|
|
74
|
-
yield sse
|
|
75
|
-
|
|
76
|
-
async def aiter_sse(self) -> AsyncGenerator[ServerSentEvent, None]:
|
|
77
|
-
self._check_content_type()
|
|
78
|
-
decoder = SSEDecoder()
|
|
79
|
-
lines = cast(AsyncGenerator[str, None], self._response.aiter_lines())
|
|
80
|
-
try:
|
|
81
|
-
async for line in lines:
|
|
82
|
-
line = line.rstrip("\n")
|
|
83
|
-
sse = decoder.decode(line)
|
|
84
|
-
if sse is not None:
|
|
85
|
-
yield sse
|
|
86
|
-
finally:
|
|
87
|
-
await lines.aclose()
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
@contextmanager
|
|
91
|
-
def connect_sse(client: httpx.Client, method: str, url: str, **kwargs: Any) -> Iterator[EventSource]:
|
|
92
|
-
headers = kwargs.pop("headers", {})
|
|
93
|
-
headers["Accept"] = "text/event-stream"
|
|
94
|
-
headers["Cache-Control"] = "no-store"
|
|
95
|
-
|
|
96
|
-
with client.stream(method, url, headers=headers, **kwargs) as response:
|
|
97
|
-
yield EventSource(response)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
@asynccontextmanager
|
|
101
|
-
async def aconnect_sse(
|
|
102
|
-
client: httpx.AsyncClient,
|
|
103
|
-
method: str,
|
|
104
|
-
url: str,
|
|
105
|
-
**kwargs: Any,
|
|
106
|
-
) -> AsyncIterator[EventSource]:
|
|
107
|
-
headers = kwargs.pop("headers", {})
|
|
108
|
-
headers["Accept"] = "text/event-stream"
|
|
109
|
-
headers["Cache-Control"] = "no-store"
|
|
110
|
-
|
|
111
|
-
async with client.stream(method, url, headers=headers, **kwargs) as response:
|
|
112
|
-
yield EventSource(response)
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
from typing import List, Optional
|
|
4
|
-
|
|
5
|
-
from ._models import ServerSentEvent
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class SSEDecoder:
|
|
9
|
-
def __init__(self) -> None:
|
|
10
|
-
self._event = ""
|
|
11
|
-
self._data: List[str] = []
|
|
12
|
-
self._last_event_id = ""
|
|
13
|
-
self._retry: Optional[int] = None
|
|
14
|
-
|
|
15
|
-
def decode(self, line: str) -> Optional[ServerSentEvent]:
|
|
16
|
-
# See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501
|
|
17
|
-
|
|
18
|
-
if not line:
|
|
19
|
-
if not self._event and not self._data and not self._last_event_id and self._retry is None:
|
|
20
|
-
return None
|
|
21
|
-
|
|
22
|
-
sse = ServerSentEvent(
|
|
23
|
-
event=self._event,
|
|
24
|
-
data="\n".join(self._data),
|
|
25
|
-
id=self._last_event_id,
|
|
26
|
-
retry=self._retry,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
# NOTE: as per the SSE spec, do not reset last_event_id.
|
|
30
|
-
self._event = ""
|
|
31
|
-
self._data = []
|
|
32
|
-
self._retry = None
|
|
33
|
-
|
|
34
|
-
return sse
|
|
35
|
-
|
|
36
|
-
if line.startswith(":"):
|
|
37
|
-
return None
|
|
38
|
-
|
|
39
|
-
fieldname, _, value = line.partition(":")
|
|
40
|
-
|
|
41
|
-
if value.startswith(" "):
|
|
42
|
-
value = value[1:]
|
|
43
|
-
|
|
44
|
-
if fieldname == "event":
|
|
45
|
-
self._event = value
|
|
46
|
-
elif fieldname == "data":
|
|
47
|
-
self._data.append(value)
|
|
48
|
-
elif fieldname == "id":
|
|
49
|
-
if "\0" in value:
|
|
50
|
-
pass
|
|
51
|
-
else:
|
|
52
|
-
self._last_event_id = value
|
|
53
|
-
elif fieldname == "retry":
|
|
54
|
-
try:
|
|
55
|
-
self._retry = int(value)
|
|
56
|
-
except (TypeError, ValueError):
|
|
57
|
-
pass
|
|
58
|
-
else:
|
|
59
|
-
pass # Field is ignored.
|
|
60
|
-
|
|
61
|
-
return None
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
from dataclasses import dataclass
|
|
5
|
-
from typing import Any, Optional
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@dataclass(frozen=True)
|
|
9
|
-
class ServerSentEvent:
|
|
10
|
-
event: str = "message"
|
|
11
|
-
data: str = ""
|
|
12
|
-
id: str = ""
|
|
13
|
-
retry: Optional[int] = None
|
|
14
|
-
|
|
15
|
-
def json(self) -> Any:
|
|
16
|
-
"""Parse the data field as JSON."""
|
|
17
|
-
return json.loads(self.data)
|
|
File without changes
|