sarvamai 0.1.5a6__py3-none-any.whl → 0.1.5a7__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 (93) hide show
  1. sarvamai/__init__.py +45 -1
  2. sarvamai/chat/__init__.py +2 -0
  3. sarvamai/chat/client.py +9 -10
  4. sarvamai/chat/raw_client.py +48 -37
  5. sarvamai/client.py +13 -31
  6. sarvamai/core/__init__.py +5 -0
  7. sarvamai/core/api_error.py +13 -5
  8. sarvamai/core/client_wrapper.py +17 -20
  9. sarvamai/core/events.py +30 -0
  10. sarvamai/core/force_multipart.py +16 -0
  11. sarvamai/core/http_client.py +70 -24
  12. sarvamai/core/http_response.py +19 -11
  13. sarvamai/core/pydantic_utilities.py +69 -108
  14. sarvamai/environment.py +10 -3
  15. sarvamai/errors/__init__.py +2 -0
  16. sarvamai/errors/bad_request_error.py +4 -3
  17. sarvamai/errors/forbidden_error.py +4 -3
  18. sarvamai/errors/internal_server_error.py +4 -3
  19. sarvamai/errors/service_unavailable_error.py +4 -2
  20. sarvamai/errors/too_many_requests_error.py +4 -3
  21. sarvamai/errors/unprocessable_entity_error.py +4 -3
  22. sarvamai/requests/__init__.py +18 -0
  23. sarvamai/requests/audio_data.py +21 -0
  24. sarvamai/requests/audio_message.py +8 -0
  25. sarvamai/requests/chat_completion_request_message.py +3 -1
  26. sarvamai/requests/create_chat_completion_response.py +2 -2
  27. sarvamai/requests/diarized_transcript.py +2 -1
  28. sarvamai/requests/error_data.py +15 -0
  29. sarvamai/requests/error_details.py +0 -1
  30. sarvamai/requests/events_data.py +17 -0
  31. sarvamai/requests/language_identification_response.py +0 -1
  32. sarvamai/requests/speech_to_text_response.py +1 -2
  33. sarvamai/requests/speech_to_text_streaming_response.py +10 -0
  34. sarvamai/requests/speech_to_text_streaming_response_data.py +9 -0
  35. sarvamai/requests/speech_to_text_translate_response.py +0 -1
  36. sarvamai/requests/text_to_speech_response.py +2 -2
  37. sarvamai/requests/timestamps_model.py +2 -1
  38. sarvamai/requests/transcription_data.py +35 -0
  39. sarvamai/requests/transcription_metrics.py +15 -0
  40. sarvamai/requests/translation_response.py +0 -1
  41. sarvamai/requests/transliteration_response.py +0 -1
  42. sarvamai/speech_to_text/__init__.py +2 -0
  43. sarvamai/speech_to_text/client.py +13 -14
  44. sarvamai/speech_to_text/raw_client.py +99 -68
  45. sarvamai/speech_to_text_streaming/__init__.py +7 -0
  46. sarvamai/speech_to_text_streaming/client.py +189 -0
  47. sarvamai/speech_to_text_streaming/raw_client.py +166 -0
  48. sarvamai/speech_to_text_streaming/socket_client.py +129 -0
  49. sarvamai/speech_to_text_streaming/types/__init__.py +8 -0
  50. sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_language_code.py +8 -0
  51. sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_model.py +5 -0
  52. sarvamai/text/__init__.py +2 -0
  53. sarvamai/text/client.py +24 -25
  54. sarvamai/text/raw_client.py +126 -91
  55. sarvamai/text_to_speech/__init__.py +2 -0
  56. sarvamai/text_to_speech/client.py +10 -11
  57. sarvamai/text_to_speech/raw_client.py +49 -38
  58. sarvamai/types/__init__.py +24 -0
  59. sarvamai/types/audio_data.py +33 -0
  60. sarvamai/types/audio_data_encoding.py +5 -0
  61. sarvamai/types/audio_message.py +20 -0
  62. sarvamai/types/chat_completion_request_assistant_message.py +3 -3
  63. sarvamai/types/chat_completion_request_message.py +3 -2
  64. sarvamai/types/chat_completion_request_system_message.py +3 -3
  65. sarvamai/types/chat_completion_request_user_message.py +3 -3
  66. sarvamai/types/chat_completion_response_message.py +3 -3
  67. sarvamai/types/choice.py +4 -4
  68. sarvamai/types/completion_usage.py +3 -3
  69. sarvamai/types/create_chat_completion_response.py +3 -3
  70. sarvamai/types/diarized_entry.py +3 -3
  71. sarvamai/types/diarized_transcript.py +3 -3
  72. sarvamai/types/error_data.py +27 -0
  73. sarvamai/types/error_details.py +3 -3
  74. sarvamai/types/error_message.py +4 -4
  75. sarvamai/types/events_data.py +28 -0
  76. sarvamai/types/format.py +5 -0
  77. sarvamai/types/language_identification_response.py +2 -2
  78. sarvamai/types/speech_to_text_response.py +3 -3
  79. sarvamai/types/speech_to_text_streaming_response.py +22 -0
  80. sarvamai/types/speech_to_text_streaming_response_data.py +9 -0
  81. sarvamai/types/speech_to_text_streaming_response_type.py +5 -0
  82. sarvamai/types/speech_to_text_translate_response.py +3 -3
  83. sarvamai/types/text_to_speech_response.py +2 -2
  84. sarvamai/types/timestamps_model.py +2 -2
  85. sarvamai/types/transcription_data.py +45 -0
  86. sarvamai/types/transcription_metrics.py +27 -0
  87. sarvamai/types/translation_response.py +2 -2
  88. sarvamai/types/transliteration_response.py +2 -2
  89. sarvamai-0.1.5a7.dist-info/METADATA +28 -0
  90. sarvamai-0.1.5a7.dist-info/RECORD +134 -0
  91. sarvamai-0.1.5a6.dist-info/METADATA +0 -174
  92. sarvamai-0.1.5a6.dist-info/RECORD +0 -106
  93. {sarvamai-0.1.5a6.dist-info → sarvamai-0.1.5a7.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
@@ -1,2 +1,4 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
+ # isort: skip_file
4
+
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
- from ..core.client_wrapper import SyncClientWrapper
5
- from .raw_client import RawChatClient
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 ..core.client_wrapper import AsyncClientWrapper
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, ...)
@@ -117,7 +116,7 @@ class ChatClient:
117
116
  messages=[{"content": "content", "role": "assistant"}],
118
117
  )
119
118
  """
120
- response = self._raw_client.completions(
119
+ _response = self._raw_client.completions(
121
120
  messages=messages,
122
121
  temperature=temperature,
123
122
  top_p=top_p,
@@ -132,7 +131,7 @@ class ChatClient:
132
131
  wiki_grounding=wiki_grounding,
133
132
  request_options=request_options,
134
133
  )
135
- return response.data
134
+ return _response.data
136
135
 
137
136
 
138
137
  class AsyncChatClient:
@@ -245,7 +244,7 @@ class AsyncChatClient:
245
244
 
246
245
  asyncio.run(main())
247
246
  """
248
- response = await self._raw_client.completions(
247
+ _response = await self._raw_client.completions(
249
248
  messages=messages,
250
249
  temperature=temperature,
251
250
  top_p=top_p,
@@ -260,4 +259,4 @@ class AsyncChatClient:
260
259
  wiki_grounding=wiki_grounding,
261
260
  request_options=request_options,
262
261
  )
263
- return response.data
262
+ return _response.data
@@ -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 ..core.client_wrapper import SyncClientWrapper
5
- from ..requests.chat_completion_request_message import ChatCompletionRequestMessageParams
6
- from ..types.reasoning_effort import ReasoningEffort
7
- from ..requests.stop_configuration import StopConfigurationParams
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 json.decoder import JSONDecodeError
19
- from ..core.api_error import ApiError
20
- from ..core.client_wrapper import AsyncClientWrapper
21
- from ..core.http_response import AsyncHttpResponse
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, ...)
@@ -106,6 +105,7 @@ class RawChatClient:
106
105
  """
107
106
  _response = self._client_wrapper.httpx_client.request(
108
107
  "v1/chat/completions",
108
+ base_url=self._client_wrapper.get_environment().base,
109
109
  method="POST",
110
110
  json={
111
111
  "messages": convert_and_respect_annotation_metadata(
@@ -144,58 +144,63 @@ class RawChatClient:
144
144
  return HttpResponse(response=_response, data=_data)
145
145
  if _response.status_code == 400:
146
146
  raise BadRequestError(
147
- typing.cast(
147
+ headers=dict(_response.headers),
148
+ body=typing.cast(
148
149
  typing.Optional[typing.Any],
149
150
  parse_obj_as(
150
151
  type_=typing.Optional[typing.Any], # type: ignore
151
152
  object_=_response.json(),
152
153
  ),
153
- )
154
+ ),
154
155
  )
155
156
  if _response.status_code == 403:
156
157
  raise ForbiddenError(
157
- typing.cast(
158
+ headers=dict(_response.headers),
159
+ body=typing.cast(
158
160
  typing.Optional[typing.Any],
159
161
  parse_obj_as(
160
162
  type_=typing.Optional[typing.Any], # type: ignore
161
163
  object_=_response.json(),
162
164
  ),
163
- )
165
+ ),
164
166
  )
165
167
  if _response.status_code == 422:
166
168
  raise UnprocessableEntityError(
167
- typing.cast(
169
+ headers=dict(_response.headers),
170
+ body=typing.cast(
168
171
  typing.Optional[typing.Any],
169
172
  parse_obj_as(
170
173
  type_=typing.Optional[typing.Any], # type: ignore
171
174
  object_=_response.json(),
172
175
  ),
173
- )
176
+ ),
174
177
  )
175
178
  if _response.status_code == 429:
176
179
  raise TooManyRequestsError(
177
- typing.cast(
180
+ headers=dict(_response.headers),
181
+ body=typing.cast(
178
182
  typing.Optional[typing.Any],
179
183
  parse_obj_as(
180
184
  type_=typing.Optional[typing.Any], # type: ignore
181
185
  object_=_response.json(),
182
186
  ),
183
- )
187
+ ),
184
188
  )
185
189
  if _response.status_code == 500:
186
190
  raise InternalServerError(
187
- typing.cast(
191
+ headers=dict(_response.headers),
192
+ body=typing.cast(
188
193
  typing.Optional[typing.Any],
189
194
  parse_obj_as(
190
195
  type_=typing.Optional[typing.Any], # type: ignore
191
196
  object_=_response.json(),
192
197
  ),
193
- )
198
+ ),
194
199
  )
195
200
  _response_json = _response.json()
196
201
  except JSONDecodeError:
197
- raise ApiError(status_code=_response.status_code, body=_response.text)
198
- 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)
199
204
 
200
205
 
201
206
  class AsyncRawChatClient:
@@ -280,6 +285,7 @@ class AsyncRawChatClient:
280
285
  """
281
286
  _response = await self._client_wrapper.httpx_client.request(
282
287
  "v1/chat/completions",
288
+ base_url=self._client_wrapper.get_environment().base,
283
289
  method="POST",
284
290
  json={
285
291
  "messages": convert_and_respect_annotation_metadata(
@@ -318,55 +324,60 @@ class AsyncRawChatClient:
318
324
  return AsyncHttpResponse(response=_response, data=_data)
319
325
  if _response.status_code == 400:
320
326
  raise BadRequestError(
321
- typing.cast(
327
+ headers=dict(_response.headers),
328
+ body=typing.cast(
322
329
  typing.Optional[typing.Any],
323
330
  parse_obj_as(
324
331
  type_=typing.Optional[typing.Any], # type: ignore
325
332
  object_=_response.json(),
326
333
  ),
327
- )
334
+ ),
328
335
  )
329
336
  if _response.status_code == 403:
330
337
  raise ForbiddenError(
331
- typing.cast(
338
+ headers=dict(_response.headers),
339
+ body=typing.cast(
332
340
  typing.Optional[typing.Any],
333
341
  parse_obj_as(
334
342
  type_=typing.Optional[typing.Any], # type: ignore
335
343
  object_=_response.json(),
336
344
  ),
337
- )
345
+ ),
338
346
  )
339
347
  if _response.status_code == 422:
340
348
  raise UnprocessableEntityError(
341
- typing.cast(
349
+ headers=dict(_response.headers),
350
+ body=typing.cast(
342
351
  typing.Optional[typing.Any],
343
352
  parse_obj_as(
344
353
  type_=typing.Optional[typing.Any], # type: ignore
345
354
  object_=_response.json(),
346
355
  ),
347
- )
356
+ ),
348
357
  )
349
358
  if _response.status_code == 429:
350
359
  raise TooManyRequestsError(
351
- typing.cast(
360
+ headers=dict(_response.headers),
361
+ body=typing.cast(
352
362
  typing.Optional[typing.Any],
353
363
  parse_obj_as(
354
364
  type_=typing.Optional[typing.Any], # type: ignore
355
365
  object_=_response.json(),
356
366
  ),
357
- )
367
+ ),
358
368
  )
359
369
  if _response.status_code == 500:
360
370
  raise InternalServerError(
361
- typing.cast(
371
+ headers=dict(_response.headers),
372
+ body=typing.cast(
362
373
  typing.Optional[typing.Any],
363
374
  parse_obj_as(
364
375
  type_=typing.Optional[typing.Any], # type: ignore
365
376
  object_=_response.json(),
366
377
  ),
367
- )
378
+ ),
368
379
  )
369
380
  _response_json = _response.json()
370
381
  except JSONDecodeError:
371
- raise ApiError(status_code=_response.status_code, body=_response.text)
372
- 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 .text.client import TextClient
10
- from .speech_to_text.client import SpeechToTextClient
11
- from .text_to_speech.client import TextToSpeechClient
12
- from .chat.client import ChatClient
13
- from .core.client_wrapper import AsyncClientWrapper
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
- base_url=_get_base_url(base_url=base_url, environment=environment),
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
- base_url=_get_base_url(base_url=base_url, environment=environment),
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",
@@ -1,15 +1,23 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
- import typing
3
+ from typing import Any, Dict, Optional
4
4
 
5
5
 
6
6
  class ApiError(Exception):
7
- status_code: typing.Optional[int]
8
- body: typing.Any
7
+ headers: Optional[Dict[str, str]]
8
+ status_code: Optional[int]
9
+ body: Any
9
10
 
10
- def __init__(self, *, status_code: typing.Optional[int] = None, body: typing.Any = None):
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}"
@@ -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 .http_client import HttpClient
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__(self, *, api_subscription_key: str, base_url: str, timeout: typing.Optional[float] = None):
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._base_url = base_url
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.5a6",
20
+ "User-Agent": "sarvamai/0.1.5a7",
18
21
  "X-Fern-Language": "Python",
19
22
  "X-Fern-SDK-Name": "sarvamai",
20
- "X-Fern-SDK-Version": "0.1.5a6",
23
+ "X-Fern-SDK-Version": "0.1.5a7",
21
24
  }
22
25
  headers["api-subscription-key"] = self.api_subscription_key
23
26
  return headers
24
27
 
25
- def get_base_url(self) -> str:
26
- return self._base_url
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
- base_url: str,
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, base_url=base_url, timeout=timeout)
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
- base_url: str,
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, base_url=base_url, timeout=timeout)
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
  )
@@ -0,0 +1,30 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from enum import Enum
5
+
6
+
7
+ class EventType(str, Enum):
8
+ OPEN = "open"
9
+ MESSAGE = "message"
10
+ ERROR = "error"
11
+ CLOSE = "close"
12
+
13
+
14
+ class EventEmitterMixin:
15
+ """
16
+ Simple mixin for registering and emitting events.
17
+ """
18
+
19
+ def __init__(self) -> None:
20
+ self._callbacks: typing.Dict[EventType, typing.List[typing.Callable]] = {}
21
+
22
+ def on(self, event_name: EventType, callback: typing.Callable[[typing.Any], None]) -> None:
23
+ if event_name not in self._callbacks:
24
+ self._callbacks[event_name] = []
25
+ self._callbacks[event_name].append(callback)
26
+
27
+ def _emit(self, event_name: EventType, data: typing.Any) -> None:
28
+ if event_name in self._callbacks:
29
+ for cb in self._callbacks[event_name]:
30
+ cb(data)