sarvamai 0.1.5a3__tar.gz → 0.1.5a4__tar.gz

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 (122) hide show
  1. sarvamai-0.1.5a4/PKG-INFO +174 -0
  2. sarvamai-0.1.5a4/README.md +147 -0
  3. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/pyproject.toml +4 -24
  4. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/__init__.py +2 -4
  5. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/chat/__init__.py +0 -2
  6. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/chat/client.py +10 -9
  7. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/chat/raw_client.py +37 -48
  8. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/client.py +31 -10
  9. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/__init__.py +0 -5
  10. sarvamai-0.1.5a4/src/sarvamai/core/api_error.py +15 -0
  11. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/client_wrapper.py +20 -17
  12. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/http_client.py +24 -70
  13. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/http_response.py +11 -19
  14. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/pydantic_utilities.py +108 -69
  15. sarvamai-0.1.5a4/src/sarvamai/environment.py +7 -0
  16. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/errors/__init__.py +0 -2
  17. sarvamai-0.1.5a4/src/sarvamai/errors/bad_request_error.py +9 -0
  18. sarvamai-0.1.5a4/src/sarvamai/errors/forbidden_error.py +9 -0
  19. sarvamai-0.1.5a4/src/sarvamai/errors/internal_server_error.py +9 -0
  20. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/errors/service_unavailable_error.py +2 -4
  21. sarvamai-0.1.5a4/src/sarvamai/errors/too_many_requests_error.py +9 -0
  22. sarvamai-0.1.5a4/src/sarvamai/errors/unprocessable_entity_error.py +9 -0
  23. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/__init__.py +0 -2
  24. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/chat_completion_request_message.py +1 -3
  25. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/create_chat_completion_response.py +2 -2
  26. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/diarized_transcript.py +1 -2
  27. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/error_details.py +1 -0
  28. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/language_identification_response.py +1 -0
  29. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/speech_to_text_response.py +2 -1
  30. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/speech_to_text_translate_response.py +1 -0
  31. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/text_to_speech_response.py +2 -2
  32. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/timestamps_model.py +1 -2
  33. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/translation_response.py +1 -0
  34. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/transliteration_response.py +1 -0
  35. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/speech_to_text/__init__.py +0 -2
  36. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/speech_to_text/client.py +14 -13
  37. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/speech_to_text/raw_client.py +68 -99
  38. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/text/__init__.py +0 -2
  39. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/text/client.py +113 -70
  40. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/text/raw_client.py +175 -168
  41. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/text_to_speech/__init__.py +0 -2
  42. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/text_to_speech/client.py +11 -10
  43. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/text_to_speech/raw_client.py +38 -49
  44. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/__init__.py +2 -4
  45. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/chat_completion_request_assistant_message.py +3 -3
  46. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/chat_completion_request_message.py +2 -3
  47. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/chat_completion_request_system_message.py +3 -3
  48. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/chat_completion_request_user_message.py +3 -3
  49. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/chat_completion_response_message.py +3 -3
  50. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/choice.py +4 -4
  51. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/completion_usage.py +3 -3
  52. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/create_chat_completion_response.py +3 -3
  53. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/diarized_entry.py +3 -3
  54. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/diarized_transcript.py +3 -3
  55. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/error_details.py +3 -3
  56. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/error_message.py +4 -4
  57. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/language_identification_response.py +2 -2
  58. sarvamai-0.1.5a4/src/sarvamai/types/speech_to_text_model.py +7 -0
  59. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/speech_to_text_response.py +3 -3
  60. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/speech_to_text_translate_model.py +1 -1
  61. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/speech_to_text_translate_response.py +3 -3
  62. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/text_to_speech_response.py +2 -2
  63. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/timestamps_model.py +2 -2
  64. sarvamai-0.1.5a4/src/sarvamai/types/translate_model.py +5 -0
  65. sarvamai-0.1.5a4/src/sarvamai/types/translate_source_language.py +33 -0
  66. sarvamai-0.1.5a4/src/sarvamai/types/translate_target_language.py +32 -0
  67. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/translation_response.py +2 -2
  68. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/translatiterate_target_language.py +1 -1
  69. sarvamai-0.1.5a4/src/sarvamai/types/transliterate_mode.py +5 -0
  70. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/transliterate_source_language.py +1 -1
  71. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/transliteration_response.py +2 -2
  72. sarvamai-0.1.5a3/PKG-INFO +0 -27
  73. sarvamai-0.1.5a3/README.md +0 -0
  74. sarvamai-0.1.5a3/src/sarvamai/core/api_error.py +0 -23
  75. sarvamai-0.1.5a3/src/sarvamai/core/events.py +0 -30
  76. sarvamai-0.1.5a3/src/sarvamai/core/force_multipart.py +0 -16
  77. sarvamai-0.1.5a3/src/sarvamai/environment.py +0 -14
  78. sarvamai-0.1.5a3/src/sarvamai/errors/bad_request_error.py +0 -10
  79. sarvamai-0.1.5a3/src/sarvamai/errors/forbidden_error.py +0 -10
  80. sarvamai-0.1.5a3/src/sarvamai/errors/internal_server_error.py +0 -10
  81. sarvamai-0.1.5a3/src/sarvamai/errors/too_many_requests_error.py +0 -10
  82. sarvamai-0.1.5a3/src/sarvamai/errors/unprocessable_entity_error.py +0 -10
  83. sarvamai-0.1.5a3/src/sarvamai/types/speech_to_text_model.py +0 -5
  84. sarvamai-0.1.5a3/src/sarvamai/types/translate_model.py +0 -5
  85. sarvamai-0.1.5a3/src/sarvamai/types/translate_postprocessing.py +0 -5
  86. sarvamai-0.1.5a3/src/sarvamai/types/translate_source_language.py +0 -10
  87. sarvamai-0.1.5a3/src/sarvamai/types/translate_target_language.py +0 -8
  88. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/datetime_utils.py +0 -0
  89. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/file.py +0 -0
  90. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/jsonable_encoder.py +0 -0
  91. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/query_encoder.py +0 -0
  92. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/remove_none_from_dict.py +0 -0
  93. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/request_options.py +0 -0
  94. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/core/serialization.py +0 -0
  95. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/play.py +0 -0
  96. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/py.typed +0 -0
  97. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/chat_completion_request_assistant_message.py +0 -0
  98. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/chat_completion_request_system_message.py +0 -0
  99. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/chat_completion_request_user_message.py +0 -0
  100. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/chat_completion_response_message.py +0 -0
  101. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/choice.py +0 -0
  102. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/completion_usage.py +0 -0
  103. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/diarized_entry.py +0 -0
  104. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/error_message.py +0 -0
  105. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/requests/stop_configuration.py +0 -0
  106. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/error_code.py +0 -0
  107. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/finish_reason.py +0 -0
  108. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/numerals_format.py +0 -0
  109. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/reasoning_effort.py +0 -0
  110. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/role.py +0 -0
  111. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/sarvam_model_ids.py +0 -0
  112. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/speech_sample_rate.py +0 -0
  113. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/speech_to_text_language.py +0 -0
  114. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/speech_to_text_translate_language.py +0 -0
  115. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/spoken_form_numerals_format.py +0 -0
  116. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/stop_configuration.py +0 -0
  117. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/text_to_speech_language.py +0 -0
  118. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/text_to_speech_model.py +0 -0
  119. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/text_to_speech_speaker.py +0 -0
  120. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/translate_mode.py +0 -0
  121. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/types/translate_speaker_gender.py +0 -0
  122. {sarvamai-0.1.5a3 → sarvamai-0.1.5a4}/src/sarvamai/version.py +0 -0
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.1
2
+ Name: sarvamai
3
+ Version: 0.1.5a4
4
+ Summary:
5
+ Requires-Python: >=3.8,<4.0
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Operating System :: MacOS
8
+ Classifier: Operating System :: Microsoft :: Windows
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Operating System :: POSIX
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Dist: httpx (>=0.21.2)
22
+ Requires-Dist: pydantic (>=1.9.2)
23
+ Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
24
+ Requires-Dist: typing_extensions (>=4.0.0)
25
+ Description-Content-Type: text/markdown
26
+
27
+ # Sarvam Python Library
28
+
29
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fsarvamai%2Fsarvam-python-sdk)
30
+ [![pypi](https://img.shields.io/pypi/v/sarvamai)](https://pypi.python.org/pypi/sarvamai)
31
+
32
+ The Sarvam Python library provides convenient access to the Sarvam API from Python.
33
+
34
+ ## Documentation
35
+
36
+ API reference documentation is available [here](https://www.sarvam.ai/).
37
+
38
+ ## Installation
39
+
40
+ ```sh
41
+ pip install sarvamai
42
+ ```
43
+
44
+ ## Reference
45
+
46
+ A full reference for this library is available [here](https://github.com/sarvamai/sarvam-python-sdk/blob/HEAD/./reference.md).
47
+
48
+ ## Usage
49
+
50
+ Instantiate and use the client with the following:
51
+
52
+ ```python
53
+ from sarvamai import SarvamAI
54
+
55
+ client = SarvamAI(
56
+ api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
57
+ )
58
+ client.text.translate(
59
+ input="input",
60
+ source_language_code="auto",
61
+ target_language_code="bn-IN",
62
+ )
63
+ ```
64
+
65
+ ## Async Client
66
+
67
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
68
+
69
+ ```python
70
+ import asyncio
71
+
72
+ from sarvamai import AsyncSarvamAI
73
+
74
+ client = AsyncSarvamAI(
75
+ api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
76
+ )
77
+
78
+
79
+ async def main() -> None:
80
+ await client.text.translate(
81
+ input="input",
82
+ source_language_code="auto",
83
+ target_language_code="bn-IN",
84
+ )
85
+
86
+
87
+ asyncio.run(main())
88
+ ```
89
+
90
+ ## Exception Handling
91
+
92
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
93
+ will be thrown.
94
+
95
+ ```python
96
+ from sarvamai.core.api_error import ApiError
97
+
98
+ try:
99
+ client.text.translate(...)
100
+ except ApiError as e:
101
+ print(e.status_code)
102
+ print(e.body)
103
+ ```
104
+
105
+ ## Advanced
106
+
107
+ ### Retries
108
+
109
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
110
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
111
+ retry limit (default: 2).
112
+
113
+ A request is deemed retryable when any of the following HTTP status codes is returned:
114
+
115
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
116
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
117
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
118
+
119
+ Use the `max_retries` request option to configure this behavior.
120
+
121
+ ```python
122
+ client.text.translate(..., request_options={
123
+ "max_retries": 1
124
+ })
125
+ ```
126
+
127
+ ### Timeouts
128
+
129
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
130
+
131
+ ```python
132
+
133
+ from sarvamai import SarvamAI
134
+
135
+ client = SarvamAI(
136
+ ...,
137
+ timeout=20.0,
138
+ )
139
+
140
+
141
+ # Override timeout for a specific method
142
+ client.text.translate(..., request_options={
143
+ "timeout_in_seconds": 1
144
+ })
145
+ ```
146
+
147
+ ### Custom Client
148
+
149
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
150
+ and transports.
151
+
152
+ ```python
153
+ import httpx
154
+ from sarvamai import SarvamAI
155
+
156
+ client = SarvamAI(
157
+ ...,
158
+ httpx_client=httpx.Client(
159
+ proxies="http://my.test.proxy.example.com",
160
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
161
+ ),
162
+ )
163
+ ```
164
+
165
+ ## Contributing
166
+
167
+ While we value open-source contributions to this SDK, this library is generated programmatically.
168
+ Additions made directly to this library would have to be moved over to our generation code,
169
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
170
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
171
+ an issue first to discuss with us!
172
+
173
+ On the other hand, contributions to the README are always very welcome!
174
+
@@ -0,0 +1,147 @@
1
+ # Sarvam Python Library
2
+
3
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fsarvamai%2Fsarvam-python-sdk)
4
+ [![pypi](https://img.shields.io/pypi/v/sarvamai)](https://pypi.python.org/pypi/sarvamai)
5
+
6
+ The Sarvam Python library provides convenient access to the Sarvam API from Python.
7
+
8
+ ## Documentation
9
+
10
+ API reference documentation is available [here](https://www.sarvam.ai/).
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ pip install sarvamai
16
+ ```
17
+
18
+ ## Reference
19
+
20
+ A full reference for this library is available [here](https://github.com/sarvamai/sarvam-python-sdk/blob/HEAD/./reference.md).
21
+
22
+ ## Usage
23
+
24
+ Instantiate and use the client with the following:
25
+
26
+ ```python
27
+ from sarvamai import SarvamAI
28
+
29
+ client = SarvamAI(
30
+ api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
31
+ )
32
+ client.text.translate(
33
+ input="input",
34
+ source_language_code="auto",
35
+ target_language_code="bn-IN",
36
+ )
37
+ ```
38
+
39
+ ## Async Client
40
+
41
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
42
+
43
+ ```python
44
+ import asyncio
45
+
46
+ from sarvamai import AsyncSarvamAI
47
+
48
+ client = AsyncSarvamAI(
49
+ api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
50
+ )
51
+
52
+
53
+ async def main() -> None:
54
+ await client.text.translate(
55
+ input="input",
56
+ source_language_code="auto",
57
+ target_language_code="bn-IN",
58
+ )
59
+
60
+
61
+ asyncio.run(main())
62
+ ```
63
+
64
+ ## Exception Handling
65
+
66
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
67
+ will be thrown.
68
+
69
+ ```python
70
+ from sarvamai.core.api_error import ApiError
71
+
72
+ try:
73
+ client.text.translate(...)
74
+ except ApiError as e:
75
+ print(e.status_code)
76
+ print(e.body)
77
+ ```
78
+
79
+ ## Advanced
80
+
81
+ ### Retries
82
+
83
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
84
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
85
+ retry limit (default: 2).
86
+
87
+ A request is deemed retryable when any of the following HTTP status codes is returned:
88
+
89
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
90
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
91
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
92
+
93
+ Use the `max_retries` request option to configure this behavior.
94
+
95
+ ```python
96
+ client.text.translate(..., request_options={
97
+ "max_retries": 1
98
+ })
99
+ ```
100
+
101
+ ### Timeouts
102
+
103
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
104
+
105
+ ```python
106
+
107
+ from sarvamai import SarvamAI
108
+
109
+ client = SarvamAI(
110
+ ...,
111
+ timeout=20.0,
112
+ )
113
+
114
+
115
+ # Override timeout for a specific method
116
+ client.text.translate(..., request_options={
117
+ "timeout_in_seconds": 1
118
+ })
119
+ ```
120
+
121
+ ### Custom Client
122
+
123
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
124
+ and transports.
125
+
126
+ ```python
127
+ import httpx
128
+ from sarvamai import SarvamAI
129
+
130
+ client = SarvamAI(
131
+ ...,
132
+ httpx_client=httpx.Client(
133
+ proxies="http://my.test.proxy.example.com",
134
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
135
+ ),
136
+ )
137
+ ```
138
+
139
+ ## Contributing
140
+
141
+ While we value open-source contributions to this SDK, this library is generated programmatically.
142
+ Additions made directly to this library would have to be moved over to our generation code,
143
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
144
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
145
+ an issue first to discuss with us!
146
+
147
+ On the other hand, contributions to the README are always very welcome!
@@ -3,7 +3,7 @@ name = "sarvamai"
3
3
 
4
4
  [tool.poetry]
5
5
  name = "sarvamai"
6
- version = "0.1.5a3"
6
+ version = "0.1.5a4"
7
7
  description = ""
8
8
  readme = "README.md"
9
9
  authors = []
@@ -40,13 +40,13 @@ pydantic = ">= 1.9.2"
40
40
  pydantic-core = "^2.18.2"
41
41
  typing_extensions = ">= 4.0.0"
42
42
 
43
- [tool.poetry.group.dev.dependencies]
44
- mypy = "==1.13.0"
43
+ [tool.poetry.dev-dependencies]
44
+ mypy = "1.0.1"
45
45
  pytest = "^7.4.0"
46
46
  pytest-asyncio = "^0.23.5"
47
47
  python-dateutil = "^2.9.0"
48
48
  types-python-dateutil = "^2.9.0.20240316"
49
- ruff = "==0.11.5"
49
+ ruff = "^0.5.6"
50
50
 
51
51
  [tool.pytest.ini_options]
52
52
  testpaths = [ "tests" ]
@@ -58,26 +58,6 @@ plugins = ["pydantic.mypy"]
58
58
  [tool.ruff]
59
59
  line-length = 120
60
60
 
61
- [tool.ruff.lint]
62
- select = [
63
- "E", # pycodestyle errors
64
- "F", # pyflakes
65
- "I", # isort
66
- ]
67
- ignore = [
68
- "E402", # Module level import not at top of file
69
- "E501", # Line too long
70
- "E711", # Comparison to `None` should be `cond is not None`
71
- "E712", # Avoid equality comparisons to `True`; use `if ...:` checks
72
- "E721", # Use `is` and `is not` for type comparisons, or `isinstance()` for insinstance checks
73
- "E722", # Do not use bare `except`
74
- "E731", # Do not assign a `lambda` expression, use a `def`
75
- "F821", # Undefined name
76
- "F841" # Local variable ... is assigned to but never used
77
- ]
78
-
79
- [tool.ruff.lint.isort]
80
- section-order = ["future", "standard-library", "third-party", "first-party"]
81
61
 
82
62
  [build-system]
83
63
  requires = ["poetry-core"]
@@ -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",
@@ -1,4 +1,2 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
- # isort: skip_file
4
-
@@ -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, ...)
@@ -117,7 +118,7 @@ class ChatClient:
117
118
  messages=[{"content": "content", "role": "assistant"}],
118
119
  )
119
120
  """
120
- _response = self._raw_client.completions(
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 _response.data
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
- _response = await self._raw_client.completions(
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 _response.data
265
+ 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, ...)
@@ -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
- headers=dict(_response.headers),
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
- headers=dict(_response.headers),
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
- headers=dict(_response.headers),
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
- headers=dict(_response.headers),
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
- headers=dict(_response.headers),
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, headers=dict(_response.headers), body=_response.text)
204
- raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
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
- headers=dict(_response.headers),
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
- headers=dict(_response.headers),
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
- headers=dict(_response.headers),
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
- headers=dict(_response.headers),
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
- headers=dict(_response.headers),
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, headers=dict(_response.headers), body=_response.text)
385
- raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
373
+ raise ApiError(status_code=_response.status_code, body=_response.text)
374
+ raise ApiError(status_code=_response.status_code, body=_response_json)