sarvamai 0.1.22a3__py3-none-any.whl → 0.1.23a1__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.
Files changed (64) hide show
  1. sarvamai/__init__.py +405 -206
  2. sarvamai/chat/raw_client.py +20 -20
  3. sarvamai/client.py +186 -34
  4. sarvamai/core/__init__.py +76 -21
  5. sarvamai/core/client_wrapper.py +19 -3
  6. sarvamai/core/force_multipart.py +4 -2
  7. sarvamai/core/http_client.py +217 -97
  8. sarvamai/core/http_response.py +1 -1
  9. sarvamai/core/http_sse/__init__.py +42 -0
  10. sarvamai/core/http_sse/_api.py +112 -0
  11. sarvamai/core/http_sse/_decoders.py +61 -0
  12. sarvamai/core/http_sse/_exceptions.py +7 -0
  13. sarvamai/core/http_sse/_models.py +17 -0
  14. sarvamai/core/jsonable_encoder.py +8 -0
  15. sarvamai/core/pydantic_utilities.py +110 -4
  16. sarvamai/errors/__init__.py +40 -6
  17. sarvamai/errors/bad_request_error.py +1 -1
  18. sarvamai/errors/forbidden_error.py +1 -1
  19. sarvamai/errors/internal_server_error.py +1 -1
  20. sarvamai/errors/service_unavailable_error.py +1 -1
  21. sarvamai/errors/too_many_requests_error.py +1 -1
  22. sarvamai/errors/unprocessable_entity_error.py +1 -1
  23. sarvamai/requests/__init__.py +150 -62
  24. sarvamai/requests/audio_data.py +0 -6
  25. sarvamai/requests/error_response_data.py +1 -1
  26. sarvamai/requests/file_signed_url_details.py +1 -1
  27. sarvamai/requests/speech_to_text_transcription_data.py +2 -8
  28. sarvamai/requests/speech_to_text_translate_transcription_data.py +0 -6
  29. sarvamai/speech_to_text/raw_client.py +54 -52
  30. sarvamai/speech_to_text_job/job.py +100 -2
  31. sarvamai/speech_to_text_job/raw_client.py +134 -130
  32. sarvamai/speech_to_text_streaming/__init__.py +38 -10
  33. sarvamai/speech_to_text_streaming/client.py +0 -44
  34. sarvamai/speech_to_text_streaming/raw_client.py +0 -44
  35. sarvamai/speech_to_text_streaming/types/__init__.py +36 -8
  36. sarvamai/speech_to_text_translate_job/job.py +100 -2
  37. sarvamai/speech_to_text_translate_job/raw_client.py +134 -130
  38. sarvamai/speech_to_text_translate_streaming/__init__.py +36 -9
  39. sarvamai/speech_to_text_translate_streaming/client.py +0 -44
  40. sarvamai/speech_to_text_translate_streaming/raw_client.py +0 -44
  41. sarvamai/speech_to_text_translate_streaming/types/__init__.py +36 -9
  42. sarvamai/text/client.py +0 -12
  43. sarvamai/text/raw_client.py +60 -72
  44. sarvamai/text_to_speech/client.py +18 -0
  45. sarvamai/text_to_speech/raw_client.py +38 -20
  46. sarvamai/text_to_speech_streaming/__init__.py +28 -1
  47. sarvamai/text_to_speech_streaming/types/__init__.py +30 -1
  48. sarvamai/types/__init__.py +222 -102
  49. sarvamai/types/audio_data.py +0 -6
  50. sarvamai/types/chat_completion_request_message.py +6 -2
  51. sarvamai/types/completion_event_flag.py +3 -1
  52. sarvamai/types/error_response_data.py +1 -1
  53. sarvamai/types/file_signed_url_details.py +1 -1
  54. sarvamai/types/speech_to_text_transcription_data.py +2 -8
  55. sarvamai/types/speech_to_text_translate_transcription_data.py +0 -6
  56. {sarvamai-0.1.22a3.dist-info → sarvamai-0.1.23a1.dist-info}/METADATA +2 -1
  57. {sarvamai-0.1.22a3.dist-info → sarvamai-0.1.23a1.dist-info}/RECORD +58 -59
  58. sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_input_audio_codec.py +0 -33
  59. sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_stream_ongoing_speech_results.py +0 -5
  60. sarvamai/speech_to_text_translate_streaming/types/speech_to_text_translate_streaming_input_audio_codec.py +0 -33
  61. sarvamai/speech_to_text_translate_streaming/types/speech_to_text_translate_streaming_stream_ongoing_speech_results.py +0 -5
  62. sarvamai/types/audio_data_input_audio_codec.py +0 -33
  63. sarvamai/types/response_speech_state.py +0 -7
  64. {sarvamai-0.1.22a3.dist-info → sarvamai-0.1.23a1.dist-info}/WHEEL +0 -0
@@ -146,9 +146,9 @@ class RawChatClient:
146
146
  raise BadRequestError(
147
147
  headers=dict(_response.headers),
148
148
  body=typing.cast(
149
- typing.Optional[typing.Any],
149
+ typing.Any,
150
150
  parse_obj_as(
151
- type_=typing.Optional[typing.Any], # type: ignore
151
+ type_=typing.Any, # type: ignore
152
152
  object_=_response.json(),
153
153
  ),
154
154
  ),
@@ -157,9 +157,9 @@ class RawChatClient:
157
157
  raise ForbiddenError(
158
158
  headers=dict(_response.headers),
159
159
  body=typing.cast(
160
- typing.Optional[typing.Any],
160
+ typing.Any,
161
161
  parse_obj_as(
162
- type_=typing.Optional[typing.Any], # type: ignore
162
+ type_=typing.Any, # type: ignore
163
163
  object_=_response.json(),
164
164
  ),
165
165
  ),
@@ -168,9 +168,9 @@ class RawChatClient:
168
168
  raise UnprocessableEntityError(
169
169
  headers=dict(_response.headers),
170
170
  body=typing.cast(
171
- typing.Optional[typing.Any],
171
+ typing.Any,
172
172
  parse_obj_as(
173
- type_=typing.Optional[typing.Any], # type: ignore
173
+ type_=typing.Any, # type: ignore
174
174
  object_=_response.json(),
175
175
  ),
176
176
  ),
@@ -179,9 +179,9 @@ class RawChatClient:
179
179
  raise TooManyRequestsError(
180
180
  headers=dict(_response.headers),
181
181
  body=typing.cast(
182
- typing.Optional[typing.Any],
182
+ typing.Any,
183
183
  parse_obj_as(
184
- type_=typing.Optional[typing.Any], # type: ignore
184
+ type_=typing.Any, # type: ignore
185
185
  object_=_response.json(),
186
186
  ),
187
187
  ),
@@ -190,9 +190,9 @@ class RawChatClient:
190
190
  raise InternalServerError(
191
191
  headers=dict(_response.headers),
192
192
  body=typing.cast(
193
- typing.Optional[typing.Any],
193
+ typing.Any,
194
194
  parse_obj_as(
195
- type_=typing.Optional[typing.Any], # type: ignore
195
+ type_=typing.Any, # type: ignore
196
196
  object_=_response.json(),
197
197
  ),
198
198
  ),
@@ -326,9 +326,9 @@ class AsyncRawChatClient:
326
326
  raise BadRequestError(
327
327
  headers=dict(_response.headers),
328
328
  body=typing.cast(
329
- typing.Optional[typing.Any],
329
+ typing.Any,
330
330
  parse_obj_as(
331
- type_=typing.Optional[typing.Any], # type: ignore
331
+ type_=typing.Any, # type: ignore
332
332
  object_=_response.json(),
333
333
  ),
334
334
  ),
@@ -337,9 +337,9 @@ class AsyncRawChatClient:
337
337
  raise ForbiddenError(
338
338
  headers=dict(_response.headers),
339
339
  body=typing.cast(
340
- typing.Optional[typing.Any],
340
+ typing.Any,
341
341
  parse_obj_as(
342
- type_=typing.Optional[typing.Any], # type: ignore
342
+ type_=typing.Any, # type: ignore
343
343
  object_=_response.json(),
344
344
  ),
345
345
  ),
@@ -348,9 +348,9 @@ class AsyncRawChatClient:
348
348
  raise UnprocessableEntityError(
349
349
  headers=dict(_response.headers),
350
350
  body=typing.cast(
351
- typing.Optional[typing.Any],
351
+ typing.Any,
352
352
  parse_obj_as(
353
- type_=typing.Optional[typing.Any], # type: ignore
353
+ type_=typing.Any, # type: ignore
354
354
  object_=_response.json(),
355
355
  ),
356
356
  ),
@@ -359,9 +359,9 @@ class AsyncRawChatClient:
359
359
  raise TooManyRequestsError(
360
360
  headers=dict(_response.headers),
361
361
  body=typing.cast(
362
- typing.Optional[typing.Any],
362
+ typing.Any,
363
363
  parse_obj_as(
364
- type_=typing.Optional[typing.Any], # type: ignore
364
+ type_=typing.Any, # type: ignore
365
365
  object_=_response.json(),
366
366
  ),
367
367
  ),
@@ -370,9 +370,9 @@ class AsyncRawChatClient:
370
370
  raise InternalServerError(
371
371
  headers=dict(_response.headers),
372
372
  body=typing.cast(
373
- typing.Optional[typing.Any],
373
+ typing.Any,
374
374
  parse_obj_as(
375
- type_=typing.Optional[typing.Any], # type: ignore
375
+ type_=typing.Any, # type: ignore
376
376
  object_=_response.json(),
377
377
  ),
378
378
  ),
sarvamai/client.py CHANGED
@@ -1,24 +1,28 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
+ from __future__ import annotations
4
+
3
5
  import os
4
6
  import typing
5
7
 
6
8
  import httpx
7
- from .chat.client import AsyncChatClient, ChatClient
8
9
  from .core.api_error import ApiError
9
10
  from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
10
11
  from .environment import SarvamAIEnvironment
11
- from .speech_to_text.client import AsyncSpeechToTextClient, SpeechToTextClient
12
- from .speech_to_text_job.client import AsyncSpeechToTextJobClient, SpeechToTextJobClient
13
- from .speech_to_text_streaming.client import AsyncSpeechToTextStreamingClient, SpeechToTextStreamingClient
14
- from .speech_to_text_translate_job.client import AsyncSpeechToTextTranslateJobClient, SpeechToTextTranslateJobClient
15
- from .speech_to_text_translate_streaming.client import (
16
- AsyncSpeechToTextTranslateStreamingClient,
17
- SpeechToTextTranslateStreamingClient,
18
- )
19
- from .text.client import AsyncTextClient, TextClient
20
- from .text_to_speech.client import AsyncTextToSpeechClient, TextToSpeechClient
21
- from .text_to_speech_streaming.client import AsyncTextToSpeechStreamingClient, TextToSpeechStreamingClient
12
+
13
+ if typing.TYPE_CHECKING:
14
+ from .chat.client import AsyncChatClient, ChatClient
15
+ from .speech_to_text.client import AsyncSpeechToTextClient, SpeechToTextClient
16
+ from .speech_to_text_job.client import AsyncSpeechToTextJobClient, SpeechToTextJobClient
17
+ from .speech_to_text_streaming.client import AsyncSpeechToTextStreamingClient, SpeechToTextStreamingClient
18
+ from .speech_to_text_translate_job.client import AsyncSpeechToTextTranslateJobClient, SpeechToTextTranslateJobClient
19
+ from .speech_to_text_translate_streaming.client import (
20
+ AsyncSpeechToTextTranslateStreamingClient,
21
+ SpeechToTextTranslateStreamingClient,
22
+ )
23
+ from .text.client import AsyncTextClient, TextClient
24
+ from .text_to_speech.client import AsyncTextToSpeechClient, TextToSpeechClient
25
+ from .text_to_speech_streaming.client import AsyncTextToSpeechStreamingClient, TextToSpeechStreamingClient
22
26
 
23
27
 
24
28
  class SarvamAI:
@@ -86,17 +90,89 @@ class SarvamAI:
86
90
  else httpx.Client(timeout=_defaulted_timeout),
87
91
  timeout=_defaulted_timeout,
88
92
  )
89
- self.text = TextClient(client_wrapper=self._client_wrapper)
90
- self.speech_to_text = SpeechToTextClient(client_wrapper=self._client_wrapper)
91
- self.text_to_speech = TextToSpeechClient(client_wrapper=self._client_wrapper)
92
- self.chat = ChatClient(client_wrapper=self._client_wrapper)
93
- self.speech_to_text_job = SpeechToTextJobClient(client_wrapper=self._client_wrapper)
94
- self.speech_to_text_translate_job = SpeechToTextTranslateJobClient(client_wrapper=self._client_wrapper)
95
- self.speech_to_text_streaming = SpeechToTextStreamingClient(client_wrapper=self._client_wrapper)
96
- self.speech_to_text_translate_streaming = SpeechToTextTranslateStreamingClient(
97
- client_wrapper=self._client_wrapper
98
- )
99
- self.text_to_speech_streaming = TextToSpeechStreamingClient(client_wrapper=self._client_wrapper)
93
+ self._text: typing.Optional[TextClient] = None
94
+ self._speech_to_text: typing.Optional[SpeechToTextClient] = None
95
+ self._text_to_speech: typing.Optional[TextToSpeechClient] = None
96
+ self._chat: typing.Optional[ChatClient] = None
97
+ self._speech_to_text_job: typing.Optional[SpeechToTextJobClient] = None
98
+ self._speech_to_text_translate_job: typing.Optional[SpeechToTextTranslateJobClient] = None
99
+ self._speech_to_text_streaming: typing.Optional[SpeechToTextStreamingClient] = None
100
+ self._speech_to_text_translate_streaming: typing.Optional[SpeechToTextTranslateStreamingClient] = None
101
+ self._text_to_speech_streaming: typing.Optional[TextToSpeechStreamingClient] = None
102
+
103
+ @property
104
+ def text(self):
105
+ if self._text is None:
106
+ from .text.client import TextClient # noqa: E402
107
+
108
+ self._text = TextClient(client_wrapper=self._client_wrapper)
109
+ return self._text
110
+
111
+ @property
112
+ def speech_to_text(self):
113
+ if self._speech_to_text is None:
114
+ from .speech_to_text.client import SpeechToTextClient # noqa: E402
115
+
116
+ self._speech_to_text = SpeechToTextClient(client_wrapper=self._client_wrapper)
117
+ return self._speech_to_text
118
+
119
+ @property
120
+ def text_to_speech(self):
121
+ if self._text_to_speech is None:
122
+ from .text_to_speech.client import TextToSpeechClient # noqa: E402
123
+
124
+ self._text_to_speech = TextToSpeechClient(client_wrapper=self._client_wrapper)
125
+ return self._text_to_speech
126
+
127
+ @property
128
+ def chat(self):
129
+ if self._chat is None:
130
+ from .chat.client import ChatClient # noqa: E402
131
+
132
+ self._chat = ChatClient(client_wrapper=self._client_wrapper)
133
+ return self._chat
134
+
135
+ @property
136
+ def speech_to_text_job(self):
137
+ if self._speech_to_text_job is None:
138
+ from .speech_to_text_job.client import SpeechToTextJobClient # noqa: E402
139
+
140
+ self._speech_to_text_job = SpeechToTextJobClient(client_wrapper=self._client_wrapper)
141
+ return self._speech_to_text_job
142
+
143
+ @property
144
+ def speech_to_text_translate_job(self):
145
+ if self._speech_to_text_translate_job is None:
146
+ from .speech_to_text_translate_job.client import SpeechToTextTranslateJobClient # noqa: E402
147
+
148
+ self._speech_to_text_translate_job = SpeechToTextTranslateJobClient(client_wrapper=self._client_wrapper)
149
+ return self._speech_to_text_translate_job
150
+
151
+ @property
152
+ def speech_to_text_streaming(self):
153
+ if self._speech_to_text_streaming is None:
154
+ from .speech_to_text_streaming.client import SpeechToTextStreamingClient # noqa: E402
155
+
156
+ self._speech_to_text_streaming = SpeechToTextStreamingClient(client_wrapper=self._client_wrapper)
157
+ return self._speech_to_text_streaming
158
+
159
+ @property
160
+ def speech_to_text_translate_streaming(self):
161
+ if self._speech_to_text_translate_streaming is None:
162
+ from .speech_to_text_translate_streaming.client import SpeechToTextTranslateStreamingClient # noqa: E402
163
+
164
+ self._speech_to_text_translate_streaming = SpeechToTextTranslateStreamingClient(
165
+ client_wrapper=self._client_wrapper
166
+ )
167
+ return self._speech_to_text_translate_streaming
168
+
169
+ @property
170
+ def text_to_speech_streaming(self):
171
+ if self._text_to_speech_streaming is None:
172
+ from .text_to_speech_streaming.client import TextToSpeechStreamingClient # noqa: E402
173
+
174
+ self._text_to_speech_streaming = TextToSpeechStreamingClient(client_wrapper=self._client_wrapper)
175
+ return self._text_to_speech_streaming
100
176
 
101
177
 
102
178
  class AsyncSarvamAI:
@@ -164,14 +240,90 @@ class AsyncSarvamAI:
164
240
  else httpx.AsyncClient(timeout=_defaulted_timeout),
165
241
  timeout=_defaulted_timeout,
166
242
  )
167
- self.text = AsyncTextClient(client_wrapper=self._client_wrapper)
168
- self.speech_to_text = AsyncSpeechToTextClient(client_wrapper=self._client_wrapper)
169
- self.text_to_speech = AsyncTextToSpeechClient(client_wrapper=self._client_wrapper)
170
- self.chat = AsyncChatClient(client_wrapper=self._client_wrapper)
171
- self.speech_to_text_job = AsyncSpeechToTextJobClient(client_wrapper=self._client_wrapper)
172
- self.speech_to_text_translate_job = AsyncSpeechToTextTranslateJobClient(client_wrapper=self._client_wrapper)
173
- self.speech_to_text_streaming = AsyncSpeechToTextStreamingClient(client_wrapper=self._client_wrapper)
174
- self.speech_to_text_translate_streaming = AsyncSpeechToTextTranslateStreamingClient(
175
- client_wrapper=self._client_wrapper
176
- )
177
- self.text_to_speech_streaming = AsyncTextToSpeechStreamingClient(client_wrapper=self._client_wrapper)
243
+ self._text: typing.Optional[AsyncTextClient] = None
244
+ self._speech_to_text: typing.Optional[AsyncSpeechToTextClient] = None
245
+ self._text_to_speech: typing.Optional[AsyncTextToSpeechClient] = None
246
+ self._chat: typing.Optional[AsyncChatClient] = None
247
+ self._speech_to_text_job: typing.Optional[AsyncSpeechToTextJobClient] = None
248
+ self._speech_to_text_translate_job: typing.Optional[AsyncSpeechToTextTranslateJobClient] = None
249
+ self._speech_to_text_streaming: typing.Optional[AsyncSpeechToTextStreamingClient] = None
250
+ self._speech_to_text_translate_streaming: typing.Optional[AsyncSpeechToTextTranslateStreamingClient] = None
251
+ self._text_to_speech_streaming: typing.Optional[AsyncTextToSpeechStreamingClient] = None
252
+
253
+ @property
254
+ def text(self):
255
+ if self._text is None:
256
+ from .text.client import AsyncTextClient # noqa: E402
257
+
258
+ self._text = AsyncTextClient(client_wrapper=self._client_wrapper)
259
+ return self._text
260
+
261
+ @property
262
+ def speech_to_text(self):
263
+ if self._speech_to_text is None:
264
+ from .speech_to_text.client import AsyncSpeechToTextClient # noqa: E402
265
+
266
+ self._speech_to_text = AsyncSpeechToTextClient(client_wrapper=self._client_wrapper)
267
+ return self._speech_to_text
268
+
269
+ @property
270
+ def text_to_speech(self):
271
+ if self._text_to_speech is None:
272
+ from .text_to_speech.client import AsyncTextToSpeechClient # noqa: E402
273
+
274
+ self._text_to_speech = AsyncTextToSpeechClient(client_wrapper=self._client_wrapper)
275
+ return self._text_to_speech
276
+
277
+ @property
278
+ def chat(self):
279
+ if self._chat is None:
280
+ from .chat.client import AsyncChatClient # noqa: E402
281
+
282
+ self._chat = AsyncChatClient(client_wrapper=self._client_wrapper)
283
+ return self._chat
284
+
285
+ @property
286
+ def speech_to_text_job(self):
287
+ if self._speech_to_text_job is None:
288
+ from .speech_to_text_job.client import AsyncSpeechToTextJobClient # noqa: E402
289
+
290
+ self._speech_to_text_job = AsyncSpeechToTextJobClient(client_wrapper=self._client_wrapper)
291
+ return self._speech_to_text_job
292
+
293
+ @property
294
+ def speech_to_text_translate_job(self):
295
+ if self._speech_to_text_translate_job is None:
296
+ from .speech_to_text_translate_job.client import AsyncSpeechToTextTranslateJobClient # noqa: E402
297
+
298
+ self._speech_to_text_translate_job = AsyncSpeechToTextTranslateJobClient(
299
+ client_wrapper=self._client_wrapper
300
+ )
301
+ return self._speech_to_text_translate_job
302
+
303
+ @property
304
+ def speech_to_text_streaming(self):
305
+ if self._speech_to_text_streaming is None:
306
+ from .speech_to_text_streaming.client import AsyncSpeechToTextStreamingClient # noqa: E402
307
+
308
+ self._speech_to_text_streaming = AsyncSpeechToTextStreamingClient(client_wrapper=self._client_wrapper)
309
+ return self._speech_to_text_streaming
310
+
311
+ @property
312
+ def speech_to_text_translate_streaming(self):
313
+ if self._speech_to_text_translate_streaming is None:
314
+ from .speech_to_text_translate_streaming.client import (
315
+ AsyncSpeechToTextTranslateStreamingClient, # noqa: E402
316
+ )
317
+
318
+ self._speech_to_text_translate_streaming = AsyncSpeechToTextTranslateStreamingClient(
319
+ client_wrapper=self._client_wrapper
320
+ )
321
+ return self._speech_to_text_translate_streaming
322
+
323
+ @property
324
+ def text_to_speech_streaming(self):
325
+ if self._text_to_speech_streaming is None:
326
+ from .text_to_speech_streaming.client import AsyncTextToSpeechStreamingClient # noqa: E402
327
+
328
+ self._text_to_speech_streaming = AsyncTextToSpeechStreamingClient(client_wrapper=self._client_wrapper)
329
+ return self._text_to_speech_streaming
sarvamai/core/__init__.py CHANGED
@@ -2,27 +2,82 @@
2
2
 
3
3
  # isort: skip_file
4
4
 
5
- from .api_error import ApiError
6
- from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
7
- from .datetime_utils import serialize_datetime
8
- from .events import EventEmitterMixin, EventType
9
- from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
10
- from .http_client import AsyncHttpClient, HttpClient
11
- from .http_response import AsyncHttpResponse, HttpResponse
12
- from .jsonable_encoder import jsonable_encoder
13
- from .pydantic_utilities import (
14
- IS_PYDANTIC_V2,
15
- UniversalBaseModel,
16
- UniversalRootModel,
17
- parse_obj_as,
18
- universal_field_validator,
19
- universal_root_validator,
20
- update_forward_refs,
21
- )
22
- from .query_encoder import encode_query
23
- from .remove_none_from_dict import remove_none_from_dict
24
- from .request_options import RequestOptions
25
- from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
5
+ import typing
6
+ from importlib import import_module
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from .api_error import ApiError
10
+ from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
11
+ from .datetime_utils import serialize_datetime
12
+ from .events import EventEmitterMixin, EventType
13
+ from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
14
+ from .http_client import AsyncHttpClient, HttpClient
15
+ from .http_response import AsyncHttpResponse, HttpResponse
16
+ from .jsonable_encoder import jsonable_encoder
17
+ from .pydantic_utilities import (
18
+ IS_PYDANTIC_V2,
19
+ UniversalBaseModel,
20
+ UniversalRootModel,
21
+ parse_obj_as,
22
+ universal_field_validator,
23
+ universal_root_validator,
24
+ update_forward_refs,
25
+ )
26
+ from .query_encoder import encode_query
27
+ from .remove_none_from_dict import remove_none_from_dict
28
+ from .request_options import RequestOptions
29
+ from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
30
+ _dynamic_imports: typing.Dict[str, str] = {
31
+ "ApiError": ".api_error",
32
+ "AsyncClientWrapper": ".client_wrapper",
33
+ "AsyncHttpClient": ".http_client",
34
+ "AsyncHttpResponse": ".http_response",
35
+ "BaseClientWrapper": ".client_wrapper",
36
+ "EventEmitterMixin": ".events",
37
+ "EventType": ".events",
38
+ "FieldMetadata": ".serialization",
39
+ "File": ".file",
40
+ "HttpClient": ".http_client",
41
+ "HttpResponse": ".http_response",
42
+ "IS_PYDANTIC_V2": ".pydantic_utilities",
43
+ "RequestOptions": ".request_options",
44
+ "SyncClientWrapper": ".client_wrapper",
45
+ "UniversalBaseModel": ".pydantic_utilities",
46
+ "UniversalRootModel": ".pydantic_utilities",
47
+ "convert_and_respect_annotation_metadata": ".serialization",
48
+ "convert_file_dict_to_httpx_tuples": ".file",
49
+ "encode_query": ".query_encoder",
50
+ "jsonable_encoder": ".jsonable_encoder",
51
+ "parse_obj_as": ".pydantic_utilities",
52
+ "remove_none_from_dict": ".remove_none_from_dict",
53
+ "serialize_datetime": ".datetime_utils",
54
+ "universal_field_validator": ".pydantic_utilities",
55
+ "universal_root_validator": ".pydantic_utilities",
56
+ "update_forward_refs": ".pydantic_utilities",
57
+ "with_content_type": ".file",
58
+ }
59
+
60
+
61
+ def __getattr__(attr_name: str) -> typing.Any:
62
+ module_name = _dynamic_imports.get(attr_name)
63
+ if module_name is None:
64
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
65
+ try:
66
+ module = import_module(module_name, __package__)
67
+ if module_name == f".{attr_name}":
68
+ return module
69
+ else:
70
+ return getattr(module, attr_name)
71
+ except ImportError as e:
72
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
73
+ except AttributeError as e:
74
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
75
+
76
+
77
+ def __dir__():
78
+ lazy_attrs = list(_dynamic_imports.keys())
79
+ return sorted(lazy_attrs)
80
+
26
81
 
27
82
  __all__ = [
28
83
  "ApiError",
@@ -22,11 +22,15 @@ class BaseClientWrapper:
22
22
  self._timeout = timeout
23
23
 
24
24
  def get_headers(self) -> typing.Dict[str, str]:
25
+ import platform
26
+
25
27
  headers: typing.Dict[str, str] = {
26
- "User-Agent": "sarvamai/0.1.22a3",
28
+ "User-Agent": "sarvamai/0.1.23a1",
27
29
  "X-Fern-Language": "Python",
30
+ "X-Fern-Runtime": f"python/{platform.python_version()}",
31
+ "X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
28
32
  "X-Fern-SDK-Name": "sarvamai",
29
- "X-Fern-SDK-Version": "0.1.22a3",
33
+ "X-Fern-SDK-Version": "0.1.23a1",
30
34
  **(self.get_custom_headers() or {}),
31
35
  }
32
36
  headers["api-subscription-key"] = self.api_subscription_key
@@ -68,11 +72,23 @@ class AsyncClientWrapper(BaseClientWrapper):
68
72
  headers: typing.Optional[typing.Dict[str, str]] = None,
69
73
  environment: SarvamAIEnvironment,
70
74
  timeout: typing.Optional[float] = None,
75
+ async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
71
76
  httpx_client: httpx.AsyncClient,
72
77
  ):
73
78
  super().__init__(
74
79
  api_subscription_key=api_subscription_key, headers=headers, environment=environment, timeout=timeout
75
80
  )
81
+ self._async_token = async_token
76
82
  self.httpx_client = AsyncHttpClient(
77
- httpx_client=httpx_client, base_headers=self.get_headers, base_timeout=self.get_timeout
83
+ httpx_client=httpx_client,
84
+ base_headers=self.get_headers,
85
+ base_timeout=self.get_timeout,
86
+ async_base_headers=self.async_get_headers,
78
87
  )
88
+
89
+ async def async_get_headers(self) -> typing.Dict[str, str]:
90
+ headers = self.get_headers()
91
+ if self._async_token is not None:
92
+ token = await self._async_token()
93
+ headers["Authorization"] = f"Bearer {token}"
94
+ return headers
@@ -1,7 +1,9 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
+ from typing import Any, Dict
3
4
 
4
- class ForceMultipartDict(dict):
5
+
6
+ class ForceMultipartDict(Dict[str, Any]):
5
7
  """
6
8
  A dictionary subclass that always evaluates to True in boolean contexts.
7
9
 
@@ -9,7 +11,7 @@ class ForceMultipartDict(dict):
9
11
  the dictionary is empty, which would normally evaluate to False.
10
12
  """
11
13
 
12
- def __bool__(self):
14
+ def __bool__(self) -> bool:
13
15
  return True
14
16
 
15
17