sarvamai 0.1.5a4__py3-none-any.whl → 0.1.5a5__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 +45 -1
- sarvamai/chat/__init__.py +2 -0
- sarvamai/chat/client.py +9 -12
- sarvamai/chat/raw_client.py +48 -39
- sarvamai/client.py +13 -31
- sarvamai/core/__init__.py +5 -0
- sarvamai/core/api_error.py +13 -5
- sarvamai/core/client_wrapper.py +17 -20
- sarvamai/core/events.py +30 -0
- sarvamai/core/force_multipart.py +16 -0
- sarvamai/core/http_client.py +70 -24
- sarvamai/core/http_response.py +19 -11
- sarvamai/core/pydantic_utilities.py +69 -108
- sarvamai/environment.py +10 -3
- sarvamai/errors/__init__.py +2 -0
- sarvamai/errors/bad_request_error.py +4 -3
- sarvamai/errors/forbidden_error.py +4 -3
- sarvamai/errors/internal_server_error.py +4 -3
- sarvamai/errors/service_unavailable_error.py +4 -2
- sarvamai/errors/too_many_requests_error.py +4 -3
- sarvamai/errors/unprocessable_entity_error.py +4 -3
- sarvamai/requests/__init__.py +18 -0
- sarvamai/requests/audio_data.py +21 -0
- sarvamai/requests/audio_message.py +8 -0
- sarvamai/requests/chat_completion_request_message.py +3 -1
- sarvamai/requests/create_chat_completion_response.py +2 -2
- sarvamai/requests/diarized_transcript.py +2 -1
- sarvamai/requests/error_data.py +15 -0
- sarvamai/requests/error_details.py +0 -1
- sarvamai/requests/events_data.py +17 -0
- sarvamai/requests/language_identification_response.py +0 -1
- sarvamai/requests/speech_to_text_response.py +1 -2
- sarvamai/requests/speech_to_text_streaming_response.py +10 -0
- sarvamai/requests/speech_to_text_streaming_response_data.py +9 -0
- sarvamai/requests/speech_to_text_translate_response.py +0 -1
- sarvamai/requests/text_to_speech_response.py +2 -2
- sarvamai/requests/timestamps_model.py +2 -1
- sarvamai/requests/transcription_data.py +35 -0
- sarvamai/requests/transcription_metrics.py +15 -0
- sarvamai/requests/translation_response.py +0 -1
- sarvamai/requests/transliteration_response.py +0 -1
- sarvamai/speech_to_text/__init__.py +2 -0
- sarvamai/speech_to_text/client.py +13 -14
- sarvamai/speech_to_text/raw_client.py +99 -68
- sarvamai/speech_to_text_streaming/__init__.py +7 -0
- sarvamai/speech_to_text_streaming/client.py +189 -0
- sarvamai/speech_to_text_streaming/raw_client.py +166 -0
- sarvamai/speech_to_text_streaming/socket_client.py +129 -0
- sarvamai/speech_to_text_streaming/types/__init__.py +8 -0
- sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_language_code.py +8 -0
- sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_model.py +5 -0
- sarvamai/text/__init__.py +2 -0
- sarvamai/text/client.py +24 -25
- sarvamai/text/raw_client.py +126 -91
- sarvamai/text_to_speech/__init__.py +2 -0
- sarvamai/text_to_speech/client.py +10 -11
- sarvamai/text_to_speech/raw_client.py +49 -38
- sarvamai/types/__init__.py +24 -0
- sarvamai/types/audio_data.py +33 -0
- sarvamai/types/audio_data_encoding.py +5 -0
- sarvamai/types/audio_message.py +20 -0
- sarvamai/types/chat_completion_request_assistant_message.py +3 -3
- sarvamai/types/chat_completion_request_message.py +3 -2
- sarvamai/types/chat_completion_request_system_message.py +3 -3
- sarvamai/types/chat_completion_request_user_message.py +3 -3
- sarvamai/types/chat_completion_response_message.py +3 -3
- sarvamai/types/choice.py +4 -4
- sarvamai/types/completion_usage.py +3 -3
- sarvamai/types/create_chat_completion_response.py +3 -3
- sarvamai/types/diarized_entry.py +3 -3
- sarvamai/types/diarized_transcript.py +3 -3
- sarvamai/types/error_data.py +27 -0
- sarvamai/types/error_details.py +3 -3
- sarvamai/types/error_message.py +4 -4
- sarvamai/types/events_data.py +28 -0
- sarvamai/types/format.py +5 -0
- sarvamai/types/language_identification_response.py +2 -2
- sarvamai/types/speech_to_text_response.py +3 -3
- sarvamai/types/speech_to_text_streaming_response.py +22 -0
- sarvamai/types/speech_to_text_streaming_response_data.py +9 -0
- sarvamai/types/speech_to_text_streaming_response_type.py +5 -0
- sarvamai/types/speech_to_text_translate_response.py +3 -3
- sarvamai/types/text_to_speech_response.py +2 -2
- sarvamai/types/timestamps_model.py +2 -2
- sarvamai/types/transcription_data.py +45 -0
- sarvamai/types/transcription_metrics.py +27 -0
- sarvamai/types/translation_response.py +2 -2
- sarvamai/types/transliteration_response.py +2 -2
- sarvamai-0.1.5a5.dist-info/METADATA +28 -0
- sarvamai-0.1.5a5.dist-info/RECORD +134 -0
- sarvamai-0.1.5a4.dist-info/METADATA +0 -174
- sarvamai-0.1.5a4.dist-info/RECORD +0 -106
- {sarvamai-0.1.5a4.dist-info → sarvamai-0.1.5a5.dist-info}/WHEEL +0 -0
sarvamai/__init__.py
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
|
+
# isort: skip_file
|
|
4
|
+
|
|
3
5
|
from .types import (
|
|
6
|
+
AudioData,
|
|
7
|
+
AudioDataEncoding,
|
|
8
|
+
AudioMessage,
|
|
4
9
|
ChatCompletionRequestAssistantMessage,
|
|
5
10
|
ChatCompletionRequestMessage,
|
|
6
11
|
ChatCompletionRequestMessage_Assistant,
|
|
@@ -15,9 +20,12 @@ from .types import (
|
|
|
15
20
|
DiarizedEntry,
|
|
16
21
|
DiarizedTranscript,
|
|
17
22
|
ErrorCode,
|
|
23
|
+
ErrorData,
|
|
18
24
|
ErrorDetails,
|
|
19
25
|
ErrorMessage,
|
|
26
|
+
EventsData,
|
|
20
27
|
FinishReason,
|
|
28
|
+
Format,
|
|
21
29
|
LanguageIdentificationResponse,
|
|
22
30
|
NumeralsFormat,
|
|
23
31
|
ReasoningEffort,
|
|
@@ -27,6 +35,9 @@ from .types import (
|
|
|
27
35
|
SpeechToTextLanguage,
|
|
28
36
|
SpeechToTextModel,
|
|
29
37
|
SpeechToTextResponse,
|
|
38
|
+
SpeechToTextStreamingResponse,
|
|
39
|
+
SpeechToTextStreamingResponseData,
|
|
40
|
+
SpeechToTextStreamingResponseType,
|
|
30
41
|
SpeechToTextTranslateLanguage,
|
|
31
42
|
SpeechToTextTranslateModel,
|
|
32
43
|
SpeechToTextTranslateResponse,
|
|
@@ -37,6 +48,8 @@ from .types import (
|
|
|
37
48
|
TextToSpeechResponse,
|
|
38
49
|
TextToSpeechSpeaker,
|
|
39
50
|
TimestampsModel,
|
|
51
|
+
TranscriptionData,
|
|
52
|
+
TranscriptionMetrics,
|
|
40
53
|
TranslateMode,
|
|
41
54
|
TranslateModel,
|
|
42
55
|
TranslateSourceLanguage,
|
|
@@ -56,10 +69,12 @@ from .errors import (
|
|
|
56
69
|
TooManyRequestsError,
|
|
57
70
|
UnprocessableEntityError,
|
|
58
71
|
)
|
|
59
|
-
from . import chat, speech_to_text, text, text_to_speech
|
|
72
|
+
from . import chat, speech_to_text, speech_to_text_streaming, text, text_to_speech
|
|
60
73
|
from .client import AsyncSarvamAI, SarvamAI
|
|
61
74
|
from .environment import SarvamAIEnvironment
|
|
62
75
|
from .requests import (
|
|
76
|
+
AudioDataParams,
|
|
77
|
+
AudioMessageParams,
|
|
63
78
|
ChatCompletionRequestAssistantMessageParams,
|
|
64
79
|
ChatCompletionRequestMessageParams,
|
|
65
80
|
ChatCompletionRequestMessage_AssistantParams,
|
|
@@ -73,21 +88,33 @@ from .requests import (
|
|
|
73
88
|
CreateChatCompletionResponseParams,
|
|
74
89
|
DiarizedEntryParams,
|
|
75
90
|
DiarizedTranscriptParams,
|
|
91
|
+
ErrorDataParams,
|
|
76
92
|
ErrorDetailsParams,
|
|
77
93
|
ErrorMessageParams,
|
|
94
|
+
EventsDataParams,
|
|
78
95
|
LanguageIdentificationResponseParams,
|
|
79
96
|
SpeechToTextResponseParams,
|
|
97
|
+
SpeechToTextStreamingResponseDataParams,
|
|
98
|
+
SpeechToTextStreamingResponseParams,
|
|
80
99
|
SpeechToTextTranslateResponseParams,
|
|
81
100
|
StopConfigurationParams,
|
|
82
101
|
TextToSpeechResponseParams,
|
|
83
102
|
TimestampsModelParams,
|
|
103
|
+
TranscriptionDataParams,
|
|
104
|
+
TranscriptionMetricsParams,
|
|
84
105
|
TranslationResponseParams,
|
|
85
106
|
TransliterationResponseParams,
|
|
86
107
|
)
|
|
108
|
+
from .speech_to_text_streaming import SpeechToTextStreamingLanguageCode, SpeechToTextStreamingModel
|
|
87
109
|
from .version import __version__
|
|
88
110
|
|
|
89
111
|
__all__ = [
|
|
90
112
|
"AsyncSarvamAI",
|
|
113
|
+
"AudioData",
|
|
114
|
+
"AudioDataEncoding",
|
|
115
|
+
"AudioDataParams",
|
|
116
|
+
"AudioMessage",
|
|
117
|
+
"AudioMessageParams",
|
|
91
118
|
"BadRequestError",
|
|
92
119
|
"ChatCompletionRequestAssistantMessage",
|
|
93
120
|
"ChatCompletionRequestAssistantMessageParams",
|
|
@@ -116,12 +143,17 @@ __all__ = [
|
|
|
116
143
|
"DiarizedTranscript",
|
|
117
144
|
"DiarizedTranscriptParams",
|
|
118
145
|
"ErrorCode",
|
|
146
|
+
"ErrorData",
|
|
147
|
+
"ErrorDataParams",
|
|
119
148
|
"ErrorDetails",
|
|
120
149
|
"ErrorDetailsParams",
|
|
121
150
|
"ErrorMessage",
|
|
122
151
|
"ErrorMessageParams",
|
|
152
|
+
"EventsData",
|
|
153
|
+
"EventsDataParams",
|
|
123
154
|
"FinishReason",
|
|
124
155
|
"ForbiddenError",
|
|
156
|
+
"Format",
|
|
125
157
|
"InternalServerError",
|
|
126
158
|
"LanguageIdentificationResponse",
|
|
127
159
|
"LanguageIdentificationResponseParams",
|
|
@@ -137,6 +169,13 @@ __all__ = [
|
|
|
137
169
|
"SpeechToTextModel",
|
|
138
170
|
"SpeechToTextResponse",
|
|
139
171
|
"SpeechToTextResponseParams",
|
|
172
|
+
"SpeechToTextStreamingLanguageCode",
|
|
173
|
+
"SpeechToTextStreamingModel",
|
|
174
|
+
"SpeechToTextStreamingResponse",
|
|
175
|
+
"SpeechToTextStreamingResponseData",
|
|
176
|
+
"SpeechToTextStreamingResponseDataParams",
|
|
177
|
+
"SpeechToTextStreamingResponseParams",
|
|
178
|
+
"SpeechToTextStreamingResponseType",
|
|
140
179
|
"SpeechToTextTranslateLanguage",
|
|
141
180
|
"SpeechToTextTranslateModel",
|
|
142
181
|
"SpeechToTextTranslateResponse",
|
|
@@ -152,6 +191,10 @@ __all__ = [
|
|
|
152
191
|
"TimestampsModel",
|
|
153
192
|
"TimestampsModelParams",
|
|
154
193
|
"TooManyRequestsError",
|
|
194
|
+
"TranscriptionData",
|
|
195
|
+
"TranscriptionDataParams",
|
|
196
|
+
"TranscriptionMetrics",
|
|
197
|
+
"TranscriptionMetricsParams",
|
|
155
198
|
"TranslateMode",
|
|
156
199
|
"TranslateModel",
|
|
157
200
|
"TranslateSourceLanguage",
|
|
@@ -168,6 +211,7 @@ __all__ = [
|
|
|
168
211
|
"__version__",
|
|
169
212
|
"chat",
|
|
170
213
|
"speech_to_text",
|
|
214
|
+
"speech_to_text_streaming",
|
|
171
215
|
"text",
|
|
172
216
|
"text_to_speech",
|
|
173
217
|
]
|
sarvamai/chat/__init__.py
CHANGED
sarvamai/chat/client.py
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
|
-
|
|
5
|
-
from .
|
|
4
|
+
|
|
5
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
6
|
+
from ..core.request_options import RequestOptions
|
|
6
7
|
from ..requests.chat_completion_request_message import ChatCompletionRequestMessageParams
|
|
7
|
-
from ..types.reasoning_effort import ReasoningEffort
|
|
8
8
|
from ..requests.stop_configuration import StopConfigurationParams
|
|
9
|
-
from ..core.request_options import RequestOptions
|
|
10
9
|
from ..types.create_chat_completion_response import CreateChatCompletionResponse
|
|
11
|
-
from ..
|
|
12
|
-
from .raw_client import AsyncRawChatClient
|
|
10
|
+
from ..types.reasoning_effort import ReasoningEffort
|
|
11
|
+
from .raw_client import AsyncRawChatClient, RawChatClient
|
|
13
12
|
|
|
14
13
|
# this is used as the default value for optional parameters
|
|
15
14
|
OMIT = typing.cast(typing.Any, ...)
|
|
@@ -84,7 +83,6 @@ class ChatClient:
|
|
|
84
83
|
seed : typing.Optional[int]
|
|
85
84
|
This feature is in Beta.
|
|
86
85
|
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
|
|
87
|
-
Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
|
|
88
86
|
|
|
89
87
|
frequency_penalty : typing.Optional[float]
|
|
90
88
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on
|
|
@@ -118,7 +116,7 @@ class ChatClient:
|
|
|
118
116
|
messages=[{"content": "content", "role": "assistant"}],
|
|
119
117
|
)
|
|
120
118
|
"""
|
|
121
|
-
|
|
119
|
+
_response = self._raw_client.completions(
|
|
122
120
|
messages=messages,
|
|
123
121
|
temperature=temperature,
|
|
124
122
|
top_p=top_p,
|
|
@@ -133,7 +131,7 @@ class ChatClient:
|
|
|
133
131
|
wiki_grounding=wiki_grounding,
|
|
134
132
|
request_options=request_options,
|
|
135
133
|
)
|
|
136
|
-
return
|
|
134
|
+
return _response.data
|
|
137
135
|
|
|
138
136
|
|
|
139
137
|
class AsyncChatClient:
|
|
@@ -205,7 +203,6 @@ class AsyncChatClient:
|
|
|
205
203
|
seed : typing.Optional[int]
|
|
206
204
|
This feature is in Beta.
|
|
207
205
|
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
|
|
208
|
-
Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
|
|
209
206
|
|
|
210
207
|
frequency_penalty : typing.Optional[float]
|
|
211
208
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on
|
|
@@ -247,7 +244,7 @@ class AsyncChatClient:
|
|
|
247
244
|
|
|
248
245
|
asyncio.run(main())
|
|
249
246
|
"""
|
|
250
|
-
|
|
247
|
+
_response = await self._raw_client.completions(
|
|
251
248
|
messages=messages,
|
|
252
249
|
temperature=temperature,
|
|
253
250
|
top_p=top_p,
|
|
@@ -262,4 +259,4 @@ class AsyncChatClient:
|
|
|
262
259
|
wiki_grounding=wiki_grounding,
|
|
263
260
|
request_options=request_options,
|
|
264
261
|
)
|
|
265
|
-
return
|
|
262
|
+
return _response.data
|
sarvamai/chat/raw_client.py
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
from ..
|
|
7
|
-
from ..
|
|
4
|
+
from json.decoder import JSONDecodeError
|
|
5
|
+
|
|
6
|
+
from ..core.api_error import ApiError
|
|
7
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
8
|
+
from ..core.http_response import AsyncHttpResponse, HttpResponse
|
|
9
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
8
10
|
from ..core.request_options import RequestOptions
|
|
9
|
-
from ..core.http_response import HttpResponse
|
|
10
|
-
from ..types.create_chat_completion_response import CreateChatCompletionResponse
|
|
11
11
|
from ..core.serialization import convert_and_respect_annotation_metadata
|
|
12
|
-
from ..core.pydantic_utilities import parse_obj_as
|
|
13
12
|
from ..errors.bad_request_error import BadRequestError
|
|
14
13
|
from ..errors.forbidden_error import ForbiddenError
|
|
15
|
-
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
|
16
|
-
from ..errors.too_many_requests_error import TooManyRequestsError
|
|
17
14
|
from ..errors.internal_server_error import InternalServerError
|
|
18
|
-
from
|
|
19
|
-
from ..
|
|
20
|
-
from ..
|
|
21
|
-
from ..
|
|
15
|
+
from ..errors.too_many_requests_error import TooManyRequestsError
|
|
16
|
+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
|
17
|
+
from ..requests.chat_completion_request_message import ChatCompletionRequestMessageParams
|
|
18
|
+
from ..requests.stop_configuration import StopConfigurationParams
|
|
19
|
+
from ..types.create_chat_completion_response import CreateChatCompletionResponse
|
|
20
|
+
from ..types.reasoning_effort import ReasoningEffort
|
|
22
21
|
|
|
23
22
|
# this is used as the default value for optional parameters
|
|
24
23
|
OMIT = typing.cast(typing.Any, ...)
|
|
@@ -82,7 +81,6 @@ class RawChatClient:
|
|
|
82
81
|
seed : typing.Optional[int]
|
|
83
82
|
This feature is in Beta.
|
|
84
83
|
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
|
|
85
|
-
Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
|
|
86
84
|
|
|
87
85
|
frequency_penalty : typing.Optional[float]
|
|
88
86
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on
|
|
@@ -107,6 +105,7 @@ class RawChatClient:
|
|
|
107
105
|
"""
|
|
108
106
|
_response = self._client_wrapper.httpx_client.request(
|
|
109
107
|
"v1/chat/completions",
|
|
108
|
+
base_url=self._client_wrapper.get_environment().base,
|
|
110
109
|
method="POST",
|
|
111
110
|
json={
|
|
112
111
|
"messages": convert_and_respect_annotation_metadata(
|
|
@@ -145,58 +144,63 @@ class RawChatClient:
|
|
|
145
144
|
return HttpResponse(response=_response, data=_data)
|
|
146
145
|
if _response.status_code == 400:
|
|
147
146
|
raise BadRequestError(
|
|
148
|
-
|
|
147
|
+
headers=dict(_response.headers),
|
|
148
|
+
body=typing.cast(
|
|
149
149
|
typing.Optional[typing.Any],
|
|
150
150
|
parse_obj_as(
|
|
151
151
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
152
152
|
object_=_response.json(),
|
|
153
153
|
),
|
|
154
|
-
)
|
|
154
|
+
),
|
|
155
155
|
)
|
|
156
156
|
if _response.status_code == 403:
|
|
157
157
|
raise ForbiddenError(
|
|
158
|
-
|
|
158
|
+
headers=dict(_response.headers),
|
|
159
|
+
body=typing.cast(
|
|
159
160
|
typing.Optional[typing.Any],
|
|
160
161
|
parse_obj_as(
|
|
161
162
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
162
163
|
object_=_response.json(),
|
|
163
164
|
),
|
|
164
|
-
)
|
|
165
|
+
),
|
|
165
166
|
)
|
|
166
167
|
if _response.status_code == 422:
|
|
167
168
|
raise UnprocessableEntityError(
|
|
168
|
-
|
|
169
|
+
headers=dict(_response.headers),
|
|
170
|
+
body=typing.cast(
|
|
169
171
|
typing.Optional[typing.Any],
|
|
170
172
|
parse_obj_as(
|
|
171
173
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
172
174
|
object_=_response.json(),
|
|
173
175
|
),
|
|
174
|
-
)
|
|
176
|
+
),
|
|
175
177
|
)
|
|
176
178
|
if _response.status_code == 429:
|
|
177
179
|
raise TooManyRequestsError(
|
|
178
|
-
|
|
180
|
+
headers=dict(_response.headers),
|
|
181
|
+
body=typing.cast(
|
|
179
182
|
typing.Optional[typing.Any],
|
|
180
183
|
parse_obj_as(
|
|
181
184
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
182
185
|
object_=_response.json(),
|
|
183
186
|
),
|
|
184
|
-
)
|
|
187
|
+
),
|
|
185
188
|
)
|
|
186
189
|
if _response.status_code == 500:
|
|
187
190
|
raise InternalServerError(
|
|
188
|
-
|
|
191
|
+
headers=dict(_response.headers),
|
|
192
|
+
body=typing.cast(
|
|
189
193
|
typing.Optional[typing.Any],
|
|
190
194
|
parse_obj_as(
|
|
191
195
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
192
196
|
object_=_response.json(),
|
|
193
197
|
),
|
|
194
|
-
)
|
|
198
|
+
),
|
|
195
199
|
)
|
|
196
200
|
_response_json = _response.json()
|
|
197
201
|
except JSONDecodeError:
|
|
198
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
199
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
202
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
203
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
200
204
|
|
|
201
205
|
|
|
202
206
|
class AsyncRawChatClient:
|
|
@@ -257,7 +261,6 @@ class AsyncRawChatClient:
|
|
|
257
261
|
seed : typing.Optional[int]
|
|
258
262
|
This feature is in Beta.
|
|
259
263
|
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
|
|
260
|
-
Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
|
|
261
264
|
|
|
262
265
|
frequency_penalty : typing.Optional[float]
|
|
263
266
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on
|
|
@@ -282,6 +285,7 @@ class AsyncRawChatClient:
|
|
|
282
285
|
"""
|
|
283
286
|
_response = await self._client_wrapper.httpx_client.request(
|
|
284
287
|
"v1/chat/completions",
|
|
288
|
+
base_url=self._client_wrapper.get_environment().base,
|
|
285
289
|
method="POST",
|
|
286
290
|
json={
|
|
287
291
|
"messages": convert_and_respect_annotation_metadata(
|
|
@@ -320,55 +324,60 @@ class AsyncRawChatClient:
|
|
|
320
324
|
return AsyncHttpResponse(response=_response, data=_data)
|
|
321
325
|
if _response.status_code == 400:
|
|
322
326
|
raise BadRequestError(
|
|
323
|
-
|
|
327
|
+
headers=dict(_response.headers),
|
|
328
|
+
body=typing.cast(
|
|
324
329
|
typing.Optional[typing.Any],
|
|
325
330
|
parse_obj_as(
|
|
326
331
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
327
332
|
object_=_response.json(),
|
|
328
333
|
),
|
|
329
|
-
)
|
|
334
|
+
),
|
|
330
335
|
)
|
|
331
336
|
if _response.status_code == 403:
|
|
332
337
|
raise ForbiddenError(
|
|
333
|
-
|
|
338
|
+
headers=dict(_response.headers),
|
|
339
|
+
body=typing.cast(
|
|
334
340
|
typing.Optional[typing.Any],
|
|
335
341
|
parse_obj_as(
|
|
336
342
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
337
343
|
object_=_response.json(),
|
|
338
344
|
),
|
|
339
|
-
)
|
|
345
|
+
),
|
|
340
346
|
)
|
|
341
347
|
if _response.status_code == 422:
|
|
342
348
|
raise UnprocessableEntityError(
|
|
343
|
-
|
|
349
|
+
headers=dict(_response.headers),
|
|
350
|
+
body=typing.cast(
|
|
344
351
|
typing.Optional[typing.Any],
|
|
345
352
|
parse_obj_as(
|
|
346
353
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
347
354
|
object_=_response.json(),
|
|
348
355
|
),
|
|
349
|
-
)
|
|
356
|
+
),
|
|
350
357
|
)
|
|
351
358
|
if _response.status_code == 429:
|
|
352
359
|
raise TooManyRequestsError(
|
|
353
|
-
|
|
360
|
+
headers=dict(_response.headers),
|
|
361
|
+
body=typing.cast(
|
|
354
362
|
typing.Optional[typing.Any],
|
|
355
363
|
parse_obj_as(
|
|
356
364
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
357
365
|
object_=_response.json(),
|
|
358
366
|
),
|
|
359
|
-
)
|
|
367
|
+
),
|
|
360
368
|
)
|
|
361
369
|
if _response.status_code == 500:
|
|
362
370
|
raise InternalServerError(
|
|
363
|
-
|
|
371
|
+
headers=dict(_response.headers),
|
|
372
|
+
body=typing.cast(
|
|
364
373
|
typing.Optional[typing.Any],
|
|
365
374
|
parse_obj_as(
|
|
366
375
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
367
376
|
object_=_response.json(),
|
|
368
377
|
),
|
|
369
|
-
)
|
|
378
|
+
),
|
|
370
379
|
)
|
|
371
380
|
_response_json = _response.json()
|
|
372
381
|
except JSONDecodeError:
|
|
373
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
374
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
382
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
383
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
sarvamai/client.py
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
|
-
import typing
|
|
4
|
-
from .environment import SarvamAIEnvironment
|
|
5
3
|
import os
|
|
4
|
+
import typing
|
|
5
|
+
|
|
6
6
|
import httpx
|
|
7
|
+
from .chat.client import AsyncChatClient, ChatClient
|
|
7
8
|
from .core.api_error import ApiError
|
|
8
|
-
from .core.client_wrapper import SyncClientWrapper
|
|
9
|
-
from .
|
|
10
|
-
from .speech_to_text.client import SpeechToTextClient
|
|
11
|
-
from .
|
|
12
|
-
from .
|
|
13
|
-
from .
|
|
14
|
-
from .text.client import AsyncTextClient
|
|
15
|
-
from .speech_to_text.client import AsyncSpeechToTextClient
|
|
16
|
-
from .text_to_speech.client import AsyncTextToSpeechClient
|
|
17
|
-
from .chat.client import AsyncChatClient
|
|
9
|
+
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
10
|
+
from .environment import SarvamAIEnvironment
|
|
11
|
+
from .speech_to_text.client import AsyncSpeechToTextClient, SpeechToTextClient
|
|
12
|
+
from .speech_to_text_streaming.client import AsyncSpeechToTextStreamingClient, SpeechToTextStreamingClient
|
|
13
|
+
from .text.client import AsyncTextClient, TextClient
|
|
14
|
+
from .text_to_speech.client import AsyncTextToSpeechClient, TextToSpeechClient
|
|
18
15
|
|
|
19
16
|
|
|
20
17
|
class SarvamAI:
|
|
@@ -23,9 +20,6 @@ class SarvamAI:
|
|
|
23
20
|
|
|
24
21
|
Parameters
|
|
25
22
|
----------
|
|
26
|
-
base_url : typing.Optional[str]
|
|
27
|
-
The base url to use for requests from the client.
|
|
28
|
-
|
|
29
23
|
environment : SarvamAIEnvironment
|
|
30
24
|
The environment to use for requests from the client. from .environment import SarvamAIEnvironment
|
|
31
25
|
|
|
@@ -57,7 +51,6 @@ class SarvamAI:
|
|
|
57
51
|
def __init__(
|
|
58
52
|
self,
|
|
59
53
|
*,
|
|
60
|
-
base_url: typing.Optional[str] = None,
|
|
61
54
|
environment: SarvamAIEnvironment = SarvamAIEnvironment.PRODUCTION,
|
|
62
55
|
api_subscription_key: typing.Optional[str] = os.getenv("SARVAM_API_KEY"),
|
|
63
56
|
timeout: typing.Optional[float] = None,
|
|
@@ -72,7 +65,7 @@ class SarvamAI:
|
|
|
72
65
|
body="The client must be instantiated be either passing in api_subscription_key or setting SARVAM_API_KEY"
|
|
73
66
|
)
|
|
74
67
|
self._client_wrapper = SyncClientWrapper(
|
|
75
|
-
|
|
68
|
+
environment=environment,
|
|
76
69
|
api_subscription_key=api_subscription_key,
|
|
77
70
|
httpx_client=httpx_client
|
|
78
71
|
if httpx_client is not None
|
|
@@ -85,6 +78,7 @@ class SarvamAI:
|
|
|
85
78
|
self.speech_to_text = SpeechToTextClient(client_wrapper=self._client_wrapper)
|
|
86
79
|
self.text_to_speech = TextToSpeechClient(client_wrapper=self._client_wrapper)
|
|
87
80
|
self.chat = ChatClient(client_wrapper=self._client_wrapper)
|
|
81
|
+
self.speech_to_text_streaming = SpeechToTextStreamingClient(client_wrapper=self._client_wrapper)
|
|
88
82
|
|
|
89
83
|
|
|
90
84
|
class AsyncSarvamAI:
|
|
@@ -93,9 +87,6 @@ class AsyncSarvamAI:
|
|
|
93
87
|
|
|
94
88
|
Parameters
|
|
95
89
|
----------
|
|
96
|
-
base_url : typing.Optional[str]
|
|
97
|
-
The base url to use for requests from the client.
|
|
98
|
-
|
|
99
90
|
environment : SarvamAIEnvironment
|
|
100
91
|
The environment to use for requests from the client. from .environment import SarvamAIEnvironment
|
|
101
92
|
|
|
@@ -127,7 +118,6 @@ class AsyncSarvamAI:
|
|
|
127
118
|
def __init__(
|
|
128
119
|
self,
|
|
129
120
|
*,
|
|
130
|
-
base_url: typing.Optional[str] = None,
|
|
131
121
|
environment: SarvamAIEnvironment = SarvamAIEnvironment.PRODUCTION,
|
|
132
122
|
api_subscription_key: typing.Optional[str] = os.getenv("SARVAM_API_KEY"),
|
|
133
123
|
timeout: typing.Optional[float] = None,
|
|
@@ -142,7 +132,7 @@ class AsyncSarvamAI:
|
|
|
142
132
|
body="The client must be instantiated be either passing in api_subscription_key or setting SARVAM_API_KEY"
|
|
143
133
|
)
|
|
144
134
|
self._client_wrapper = AsyncClientWrapper(
|
|
145
|
-
|
|
135
|
+
environment=environment,
|
|
146
136
|
api_subscription_key=api_subscription_key,
|
|
147
137
|
httpx_client=httpx_client
|
|
148
138
|
if httpx_client is not None
|
|
@@ -155,12 +145,4 @@ class AsyncSarvamAI:
|
|
|
155
145
|
self.speech_to_text = AsyncSpeechToTextClient(client_wrapper=self._client_wrapper)
|
|
156
146
|
self.text_to_speech = AsyncTextToSpeechClient(client_wrapper=self._client_wrapper)
|
|
157
147
|
self.chat = AsyncChatClient(client_wrapper=self._client_wrapper)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
def _get_base_url(*, base_url: typing.Optional[str] = None, environment: SarvamAIEnvironment) -> str:
|
|
161
|
-
if base_url is not None:
|
|
162
|
-
return base_url
|
|
163
|
-
elif environment is not None:
|
|
164
|
-
return environment.value
|
|
165
|
-
else:
|
|
166
|
-
raise Exception("Please pass in either base_url or environment to construct the client")
|
|
148
|
+
self.speech_to_text_streaming = AsyncSpeechToTextStreamingClient(client_wrapper=self._client_wrapper)
|
sarvamai/core/__init__.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
|
+
# isort: skip_file
|
|
4
|
+
|
|
3
5
|
from .api_error import ApiError
|
|
4
6
|
from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
|
|
5
7
|
from .datetime_utils import serialize_datetime
|
|
8
|
+
from .events import EventEmitterMixin, EventType
|
|
6
9
|
from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
|
|
7
10
|
from .http_client import AsyncHttpClient, HttpClient
|
|
8
11
|
from .http_response import AsyncHttpResponse, HttpResponse
|
|
@@ -27,6 +30,8 @@ __all__ = [
|
|
|
27
30
|
"AsyncHttpClient",
|
|
28
31
|
"AsyncHttpResponse",
|
|
29
32
|
"BaseClientWrapper",
|
|
33
|
+
"EventEmitterMixin",
|
|
34
|
+
"EventType",
|
|
30
35
|
"FieldMetadata",
|
|
31
36
|
"File",
|
|
32
37
|
"HttpClient",
|
sarvamai/core/api_error.py
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class ApiError(Exception):
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
headers: Optional[Dict[str, str]]
|
|
8
|
+
status_code: Optional[int]
|
|
9
|
+
body: Any
|
|
9
10
|
|
|
10
|
-
def __init__(
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
*,
|
|
14
|
+
headers: Optional[Dict[str, str]] = None,
|
|
15
|
+
status_code: Optional[int] = None,
|
|
16
|
+
body: Any = None,
|
|
17
|
+
) -> None:
|
|
18
|
+
self.headers = headers
|
|
11
19
|
self.status_code = status_code
|
|
12
20
|
self.body = body
|
|
13
21
|
|
|
14
22
|
def __str__(self) -> str:
|
|
15
|
-
return f"status_code: {self.status_code}, body: {self.body}"
|
|
23
|
+
return f"headers: {self.headers}, status_code: {self.status_code}, body: {self.body}"
|
sarvamai/core/client_wrapper.py
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
|
+
|
|
4
5
|
import httpx
|
|
5
|
-
from
|
|
6
|
-
from .http_client import AsyncHttpClient
|
|
6
|
+
from ..environment import SarvamAIEnvironment
|
|
7
|
+
from .http_client import AsyncHttpClient, HttpClient
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
class BaseClientWrapper:
|
|
10
|
-
def __init__(
|
|
11
|
+
def __init__(
|
|
12
|
+
self, *, api_subscription_key: str, environment: SarvamAIEnvironment, timeout: typing.Optional[float] = None
|
|
13
|
+
):
|
|
11
14
|
self.api_subscription_key = api_subscription_key
|
|
12
|
-
self.
|
|
15
|
+
self._environment = environment
|
|
13
16
|
self._timeout = timeout
|
|
14
17
|
|
|
15
18
|
def get_headers(self) -> typing.Dict[str, str]:
|
|
16
19
|
headers: typing.Dict[str, str] = {
|
|
17
|
-
"User-Agent": "sarvamai/0.1.
|
|
20
|
+
"User-Agent": "sarvamai/0.1.5a5",
|
|
18
21
|
"X-Fern-Language": "Python",
|
|
19
22
|
"X-Fern-SDK-Name": "sarvamai",
|
|
20
|
-
"X-Fern-SDK-Version": "0.1.
|
|
23
|
+
"X-Fern-SDK-Version": "0.1.5a5",
|
|
21
24
|
}
|
|
22
25
|
headers["api-subscription-key"] = self.api_subscription_key
|
|
23
26
|
return headers
|
|
24
27
|
|
|
25
|
-
def
|
|
26
|
-
return self.
|
|
28
|
+
def get_environment(self) -> SarvamAIEnvironment:
|
|
29
|
+
return self._environment
|
|
27
30
|
|
|
28
31
|
def get_timeout(self) -> typing.Optional[float]:
|
|
29
32
|
return self._timeout
|
|
@@ -34,16 +37,13 @@ class SyncClientWrapper(BaseClientWrapper):
|
|
|
34
37
|
self,
|
|
35
38
|
*,
|
|
36
39
|
api_subscription_key: str,
|
|
37
|
-
|
|
40
|
+
environment: SarvamAIEnvironment,
|
|
38
41
|
timeout: typing.Optional[float] = None,
|
|
39
42
|
httpx_client: httpx.Client,
|
|
40
43
|
):
|
|
41
|
-
super().__init__(api_subscription_key=api_subscription_key,
|
|
44
|
+
super().__init__(api_subscription_key=api_subscription_key, environment=environment, timeout=timeout)
|
|
42
45
|
self.httpx_client = HttpClient(
|
|
43
|
-
httpx_client=httpx_client,
|
|
44
|
-
base_headers=self.get_headers,
|
|
45
|
-
base_timeout=self.get_timeout,
|
|
46
|
-
base_url=self.get_base_url,
|
|
46
|
+
httpx_client=httpx_client, base_headers=self.get_headers, base_timeout=self.get_timeout
|
|
47
47
|
)
|
|
48
48
|
|
|
49
49
|
|
|
@@ -52,14 +52,11 @@ class AsyncClientWrapper(BaseClientWrapper):
|
|
|
52
52
|
self,
|
|
53
53
|
*,
|
|
54
54
|
api_subscription_key: str,
|
|
55
|
-
|
|
55
|
+
environment: SarvamAIEnvironment,
|
|
56
56
|
timeout: typing.Optional[float] = None,
|
|
57
57
|
httpx_client: httpx.AsyncClient,
|
|
58
58
|
):
|
|
59
|
-
super().__init__(api_subscription_key=api_subscription_key,
|
|
59
|
+
super().__init__(api_subscription_key=api_subscription_key, environment=environment, timeout=timeout)
|
|
60
60
|
self.httpx_client = AsyncHttpClient(
|
|
61
|
-
httpx_client=httpx_client,
|
|
62
|
-
base_headers=self.get_headers,
|
|
63
|
-
base_timeout=self.get_timeout,
|
|
64
|
-
base_url=self.get_base_url,
|
|
61
|
+
httpx_client=httpx_client, base_headers=self.get_headers, base_timeout=self.get_timeout
|
|
65
62
|
)
|