sarvamai 0.1.5a3__py3-none-any.whl → 0.1.5a4__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 +2 -4
- sarvamai/chat/__init__.py +0 -2
- sarvamai/chat/client.py +10 -9
- sarvamai/chat/raw_client.py +37 -48
- sarvamai/client.py +31 -10
- sarvamai/core/__init__.py +0 -5
- sarvamai/core/api_error.py +5 -13
- sarvamai/core/client_wrapper.py +20 -17
- sarvamai/core/http_client.py +24 -70
- sarvamai/core/http_response.py +11 -19
- sarvamai/core/pydantic_utilities.py +108 -69
- sarvamai/environment.py +3 -10
- sarvamai/errors/__init__.py +0 -2
- sarvamai/errors/bad_request_error.py +3 -4
- sarvamai/errors/forbidden_error.py +3 -4
- sarvamai/errors/internal_server_error.py +3 -4
- sarvamai/errors/service_unavailable_error.py +2 -4
- sarvamai/errors/too_many_requests_error.py +3 -4
- sarvamai/errors/unprocessable_entity_error.py +3 -4
- sarvamai/requests/__init__.py +0 -2
- sarvamai/requests/chat_completion_request_message.py +1 -3
- sarvamai/requests/create_chat_completion_response.py +2 -2
- sarvamai/requests/diarized_transcript.py +1 -2
- sarvamai/requests/error_details.py +1 -0
- sarvamai/requests/language_identification_response.py +1 -0
- sarvamai/requests/speech_to_text_response.py +2 -1
- sarvamai/requests/speech_to_text_translate_response.py +1 -0
- sarvamai/requests/text_to_speech_response.py +2 -2
- sarvamai/requests/timestamps_model.py +1 -2
- sarvamai/requests/translation_response.py +1 -0
- sarvamai/requests/transliteration_response.py +1 -0
- sarvamai/speech_to_text/__init__.py +0 -2
- sarvamai/speech_to_text/client.py +14 -13
- sarvamai/speech_to_text/raw_client.py +68 -99
- sarvamai/text/__init__.py +0 -2
- sarvamai/text/client.py +113 -70
- sarvamai/text/raw_client.py +175 -168
- sarvamai/text_to_speech/__init__.py +0 -2
- sarvamai/text_to_speech/client.py +11 -10
- sarvamai/text_to_speech/raw_client.py +38 -49
- sarvamai/types/__init__.py +2 -4
- sarvamai/types/chat_completion_request_assistant_message.py +3 -3
- sarvamai/types/chat_completion_request_message.py +2 -3
- 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_details.py +3 -3
- sarvamai/types/error_message.py +4 -4
- sarvamai/types/language_identification_response.py +2 -2
- sarvamai/types/speech_to_text_model.py +3 -1
- sarvamai/types/speech_to_text_response.py +3 -3
- sarvamai/types/speech_to_text_translate_model.py +1 -1
- 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/translate_model.py +1 -1
- sarvamai/types/translate_source_language.py +24 -1
- sarvamai/types/translate_target_language.py +25 -1
- sarvamai/types/translation_response.py +2 -2
- sarvamai/types/translatiterate_target_language.py +1 -1
- sarvamai/types/transliterate_mode.py +5 -0
- sarvamai/types/transliterate_source_language.py +1 -1
- sarvamai/types/transliteration_response.py +2 -2
- sarvamai-0.1.5a4.dist-info/METADATA +174 -0
- sarvamai-0.1.5a4.dist-info/RECORD +106 -0
- sarvamai/core/events.py +0 -30
- sarvamai/core/force_multipart.py +0 -16
- sarvamai/types/translate_postprocessing.py +0 -5
- sarvamai-0.1.5a3.dist-info/METADATA +0 -27
- sarvamai-0.1.5a3.dist-info/RECORD +0 -108
- {sarvamai-0.1.5a3.dist-info → sarvamai-0.1.5a4.dist-info}/WHEEL +0 -0
sarvamai/__init__.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
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
4
|
ChatCompletionRequestAssistantMessage,
|
|
7
5
|
ChatCompletionRequestMessage,
|
|
@@ -41,12 +39,12 @@ from .types import (
|
|
|
41
39
|
TimestampsModel,
|
|
42
40
|
TranslateMode,
|
|
43
41
|
TranslateModel,
|
|
44
|
-
TranslatePostprocessing,
|
|
45
42
|
TranslateSourceLanguage,
|
|
46
43
|
TranslateSpeakerGender,
|
|
47
44
|
TranslateTargetLanguage,
|
|
48
45
|
TranslationResponse,
|
|
49
46
|
TranslatiterateTargetLanguage,
|
|
47
|
+
TransliterateMode,
|
|
50
48
|
TransliterateSourceLanguage,
|
|
51
49
|
TransliterationResponse,
|
|
52
50
|
)
|
|
@@ -156,13 +154,13 @@ __all__ = [
|
|
|
156
154
|
"TooManyRequestsError",
|
|
157
155
|
"TranslateMode",
|
|
158
156
|
"TranslateModel",
|
|
159
|
-
"TranslatePostprocessing",
|
|
160
157
|
"TranslateSourceLanguage",
|
|
161
158
|
"TranslateSpeakerGender",
|
|
162
159
|
"TranslateTargetLanguage",
|
|
163
160
|
"TranslationResponse",
|
|
164
161
|
"TranslationResponseParams",
|
|
165
162
|
"TranslatiterateTargetLanguage",
|
|
163
|
+
"TransliterateMode",
|
|
166
164
|
"TransliterateSourceLanguage",
|
|
167
165
|
"TransliterationResponse",
|
|
168
166
|
"TransliterationResponseParams",
|
sarvamai/chat/__init__.py
CHANGED
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
|
|
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 ..
|
|
11
|
-
from .raw_client import AsyncRawChatClient
|
|
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, ...)
|
|
@@ -117,7 +118,7 @@ class ChatClient:
|
|
|
117
118
|
messages=[{"content": "content", "role": "assistant"}],
|
|
118
119
|
)
|
|
119
120
|
"""
|
|
120
|
-
|
|
121
|
+
response = self._raw_client.completions(
|
|
121
122
|
messages=messages,
|
|
122
123
|
temperature=temperature,
|
|
123
124
|
top_p=top_p,
|
|
@@ -132,7 +133,7 @@ class ChatClient:
|
|
|
132
133
|
wiki_grounding=wiki_grounding,
|
|
133
134
|
request_options=request_options,
|
|
134
135
|
)
|
|
135
|
-
return
|
|
136
|
+
return response.data
|
|
136
137
|
|
|
137
138
|
|
|
138
139
|
class AsyncChatClient:
|
|
@@ -246,7 +247,7 @@ class AsyncChatClient:
|
|
|
246
247
|
|
|
247
248
|
asyncio.run(main())
|
|
248
249
|
"""
|
|
249
|
-
|
|
250
|
+
response = await self._raw_client.completions(
|
|
250
251
|
messages=messages,
|
|
251
252
|
temperature=temperature,
|
|
252
253
|
top_p=top_p,
|
|
@@ -261,4 +262,4 @@ class AsyncChatClient:
|
|
|
261
262
|
wiki_grounding=wiki_grounding,
|
|
262
263
|
request_options=request_options,
|
|
263
264
|
)
|
|
264
|
-
return
|
|
265
|
+
return response.data
|
sarvamai/chat/raw_client.py
CHANGED
|
@@ -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
|
|
5
|
-
|
|
6
|
-
from ..
|
|
7
|
-
from ..
|
|
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 ..
|
|
18
|
-
from ..
|
|
19
|
-
from
|
|
20
|
-
from ..
|
|
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, ...)
|
|
@@ -106,7 +107,6 @@ class RawChatClient:
|
|
|
106
107
|
"""
|
|
107
108
|
_response = self._client_wrapper.httpx_client.request(
|
|
108
109
|
"v1/chat/completions",
|
|
109
|
-
base_url=self._client_wrapper.get_environment().base,
|
|
110
110
|
method="POST",
|
|
111
111
|
json={
|
|
112
112
|
"messages": convert_and_respect_annotation_metadata(
|
|
@@ -145,63 +145,58 @@ class RawChatClient:
|
|
|
145
145
|
return HttpResponse(response=_response, data=_data)
|
|
146
146
|
if _response.status_code == 400:
|
|
147
147
|
raise BadRequestError(
|
|
148
|
-
|
|
149
|
-
body=typing.cast(
|
|
148
|
+
typing.cast(
|
|
150
149
|
typing.Optional[typing.Any],
|
|
151
150
|
parse_obj_as(
|
|
152
151
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
153
152
|
object_=_response.json(),
|
|
154
153
|
),
|
|
155
|
-
)
|
|
154
|
+
)
|
|
156
155
|
)
|
|
157
156
|
if _response.status_code == 403:
|
|
158
157
|
raise ForbiddenError(
|
|
159
|
-
|
|
160
|
-
body=typing.cast(
|
|
158
|
+
typing.cast(
|
|
161
159
|
typing.Optional[typing.Any],
|
|
162
160
|
parse_obj_as(
|
|
163
161
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
164
162
|
object_=_response.json(),
|
|
165
163
|
),
|
|
166
|
-
)
|
|
164
|
+
)
|
|
167
165
|
)
|
|
168
166
|
if _response.status_code == 422:
|
|
169
167
|
raise UnprocessableEntityError(
|
|
170
|
-
|
|
171
|
-
body=typing.cast(
|
|
168
|
+
typing.cast(
|
|
172
169
|
typing.Optional[typing.Any],
|
|
173
170
|
parse_obj_as(
|
|
174
171
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
175
172
|
object_=_response.json(),
|
|
176
173
|
),
|
|
177
|
-
)
|
|
174
|
+
)
|
|
178
175
|
)
|
|
179
176
|
if _response.status_code == 429:
|
|
180
177
|
raise TooManyRequestsError(
|
|
181
|
-
|
|
182
|
-
body=typing.cast(
|
|
178
|
+
typing.cast(
|
|
183
179
|
typing.Optional[typing.Any],
|
|
184
180
|
parse_obj_as(
|
|
185
181
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
186
182
|
object_=_response.json(),
|
|
187
183
|
),
|
|
188
|
-
)
|
|
184
|
+
)
|
|
189
185
|
)
|
|
190
186
|
if _response.status_code == 500:
|
|
191
187
|
raise InternalServerError(
|
|
192
|
-
|
|
193
|
-
body=typing.cast(
|
|
188
|
+
typing.cast(
|
|
194
189
|
typing.Optional[typing.Any],
|
|
195
190
|
parse_obj_as(
|
|
196
191
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
197
192
|
object_=_response.json(),
|
|
198
193
|
),
|
|
199
|
-
)
|
|
194
|
+
)
|
|
200
195
|
)
|
|
201
196
|
_response_json = _response.json()
|
|
202
197
|
except JSONDecodeError:
|
|
203
|
-
raise ApiError(status_code=_response.status_code,
|
|
204
|
-
raise ApiError(status_code=_response.status_code,
|
|
198
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
199
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
205
200
|
|
|
206
201
|
|
|
207
202
|
class AsyncRawChatClient:
|
|
@@ -287,7 +282,6 @@ class AsyncRawChatClient:
|
|
|
287
282
|
"""
|
|
288
283
|
_response = await self._client_wrapper.httpx_client.request(
|
|
289
284
|
"v1/chat/completions",
|
|
290
|
-
base_url=self._client_wrapper.get_environment().base,
|
|
291
285
|
method="POST",
|
|
292
286
|
json={
|
|
293
287
|
"messages": convert_and_respect_annotation_metadata(
|
|
@@ -326,60 +320,55 @@ class AsyncRawChatClient:
|
|
|
326
320
|
return AsyncHttpResponse(response=_response, data=_data)
|
|
327
321
|
if _response.status_code == 400:
|
|
328
322
|
raise BadRequestError(
|
|
329
|
-
|
|
330
|
-
body=typing.cast(
|
|
323
|
+
typing.cast(
|
|
331
324
|
typing.Optional[typing.Any],
|
|
332
325
|
parse_obj_as(
|
|
333
326
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
334
327
|
object_=_response.json(),
|
|
335
328
|
),
|
|
336
|
-
)
|
|
329
|
+
)
|
|
337
330
|
)
|
|
338
331
|
if _response.status_code == 403:
|
|
339
332
|
raise ForbiddenError(
|
|
340
|
-
|
|
341
|
-
body=typing.cast(
|
|
333
|
+
typing.cast(
|
|
342
334
|
typing.Optional[typing.Any],
|
|
343
335
|
parse_obj_as(
|
|
344
336
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
345
337
|
object_=_response.json(),
|
|
346
338
|
),
|
|
347
|
-
)
|
|
339
|
+
)
|
|
348
340
|
)
|
|
349
341
|
if _response.status_code == 422:
|
|
350
342
|
raise UnprocessableEntityError(
|
|
351
|
-
|
|
352
|
-
body=typing.cast(
|
|
343
|
+
typing.cast(
|
|
353
344
|
typing.Optional[typing.Any],
|
|
354
345
|
parse_obj_as(
|
|
355
346
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
356
347
|
object_=_response.json(),
|
|
357
348
|
),
|
|
358
|
-
)
|
|
349
|
+
)
|
|
359
350
|
)
|
|
360
351
|
if _response.status_code == 429:
|
|
361
352
|
raise TooManyRequestsError(
|
|
362
|
-
|
|
363
|
-
body=typing.cast(
|
|
353
|
+
typing.cast(
|
|
364
354
|
typing.Optional[typing.Any],
|
|
365
355
|
parse_obj_as(
|
|
366
356
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
367
357
|
object_=_response.json(),
|
|
368
358
|
),
|
|
369
|
-
)
|
|
359
|
+
)
|
|
370
360
|
)
|
|
371
361
|
if _response.status_code == 500:
|
|
372
362
|
raise InternalServerError(
|
|
373
|
-
|
|
374
|
-
body=typing.cast(
|
|
363
|
+
typing.cast(
|
|
375
364
|
typing.Optional[typing.Any],
|
|
376
365
|
parse_obj_as(
|
|
377
366
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
378
367
|
object_=_response.json(),
|
|
379
368
|
),
|
|
380
|
-
)
|
|
369
|
+
)
|
|
381
370
|
)
|
|
382
371
|
_response_json = _response.json()
|
|
383
372
|
except JSONDecodeError:
|
|
384
|
-
raise ApiError(status_code=_response.status_code,
|
|
385
|
-
raise ApiError(status_code=_response.status_code,
|
|
373
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
374
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
sarvamai/client.py
CHANGED
|
@@ -1,16 +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
|
|
10
|
-
from .
|
|
11
|
-
from .speech_to_text.client import
|
|
12
|
-
from .
|
|
13
|
-
from .
|
|
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
|
|
14
18
|
|
|
15
19
|
|
|
16
20
|
class SarvamAI:
|
|
@@ -19,6 +23,9 @@ class SarvamAI:
|
|
|
19
23
|
|
|
20
24
|
Parameters
|
|
21
25
|
----------
|
|
26
|
+
base_url : typing.Optional[str]
|
|
27
|
+
The base url to use for requests from the client.
|
|
28
|
+
|
|
22
29
|
environment : SarvamAIEnvironment
|
|
23
30
|
The environment to use for requests from the client. from .environment import SarvamAIEnvironment
|
|
24
31
|
|
|
@@ -50,6 +57,7 @@ class SarvamAI:
|
|
|
50
57
|
def __init__(
|
|
51
58
|
self,
|
|
52
59
|
*,
|
|
60
|
+
base_url: typing.Optional[str] = None,
|
|
53
61
|
environment: SarvamAIEnvironment = SarvamAIEnvironment.PRODUCTION,
|
|
54
62
|
api_subscription_key: typing.Optional[str] = os.getenv("SARVAM_API_KEY"),
|
|
55
63
|
timeout: typing.Optional[float] = None,
|
|
@@ -64,7 +72,7 @@ class SarvamAI:
|
|
|
64
72
|
body="The client must be instantiated be either passing in api_subscription_key or setting SARVAM_API_KEY"
|
|
65
73
|
)
|
|
66
74
|
self._client_wrapper = SyncClientWrapper(
|
|
67
|
-
environment=environment,
|
|
75
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
|
68
76
|
api_subscription_key=api_subscription_key,
|
|
69
77
|
httpx_client=httpx_client
|
|
70
78
|
if httpx_client is not None
|
|
@@ -85,6 +93,9 @@ class AsyncSarvamAI:
|
|
|
85
93
|
|
|
86
94
|
Parameters
|
|
87
95
|
----------
|
|
96
|
+
base_url : typing.Optional[str]
|
|
97
|
+
The base url to use for requests from the client.
|
|
98
|
+
|
|
88
99
|
environment : SarvamAIEnvironment
|
|
89
100
|
The environment to use for requests from the client. from .environment import SarvamAIEnvironment
|
|
90
101
|
|
|
@@ -116,6 +127,7 @@ class AsyncSarvamAI:
|
|
|
116
127
|
def __init__(
|
|
117
128
|
self,
|
|
118
129
|
*,
|
|
130
|
+
base_url: typing.Optional[str] = None,
|
|
119
131
|
environment: SarvamAIEnvironment = SarvamAIEnvironment.PRODUCTION,
|
|
120
132
|
api_subscription_key: typing.Optional[str] = os.getenv("SARVAM_API_KEY"),
|
|
121
133
|
timeout: typing.Optional[float] = None,
|
|
@@ -130,7 +142,7 @@ class AsyncSarvamAI:
|
|
|
130
142
|
body="The client must be instantiated be either passing in api_subscription_key or setting SARVAM_API_KEY"
|
|
131
143
|
)
|
|
132
144
|
self._client_wrapper = AsyncClientWrapper(
|
|
133
|
-
environment=environment,
|
|
145
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
|
134
146
|
api_subscription_key=api_subscription_key,
|
|
135
147
|
httpx_client=httpx_client
|
|
136
148
|
if httpx_client is not None
|
|
@@ -143,3 +155,12 @@ class AsyncSarvamAI:
|
|
|
143
155
|
self.speech_to_text = AsyncSpeechToTextClient(client_wrapper=self._client_wrapper)
|
|
144
156
|
self.text_to_speech = AsyncTextToSpeechClient(client_wrapper=self._client_wrapper)
|
|
145
157
|
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")
|
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",
|
sarvamai/core/api_error.py
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import typing
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class ApiError(Exception):
|
|
7
|
-
|
|
8
|
-
|
|
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"
|
|
15
|
+
return f"status_code: {self.status_code}, body: {self.body}"
|
sarvamai/core/client_wrapper.py
CHANGED
|
@@ -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
|
|
7
|
-
from .http_client import AsyncHttpClient
|
|
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.
|
|
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.
|
|
17
|
+
"User-Agent": "sarvamai/0.1.5a4",
|
|
21
18
|
"X-Fern-Language": "Python",
|
|
22
19
|
"X-Fern-SDK-Name": "sarvamai",
|
|
23
|
-
"X-Fern-SDK-Version": "0.1.
|
|
20
|
+
"X-Fern-SDK-Version": "0.1.5a4",
|
|
24
21
|
}
|
|
25
22
|
headers["api-subscription-key"] = self.api_subscription_key
|
|
26
23
|
return headers
|
|
27
24
|
|
|
28
|
-
def
|
|
29
|
-
return self.
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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
|
)
|