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