arbi 0.18.0__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 (165) hide show
  1. arbi/__init__.py +92 -0
  2. arbi/_base_client.py +2124 -0
  3. arbi/_client.py +442 -0
  4. arbi/_compat.py +219 -0
  5. arbi/_constants.py +14 -0
  6. arbi/_exceptions.py +108 -0
  7. arbi/_files.py +123 -0
  8. arbi/_models.py +872 -0
  9. arbi/_qs.py +150 -0
  10. arbi/_resource.py +43 -0
  11. arbi/_response.py +830 -0
  12. arbi/_streaming.py +333 -0
  13. arbi/_types.py +270 -0
  14. arbi/_utils/__init__.py +64 -0
  15. arbi/_utils/_compat.py +45 -0
  16. arbi/_utils/_datetime_parse.py +136 -0
  17. arbi/_utils/_logs.py +25 -0
  18. arbi/_utils/_proxy.py +65 -0
  19. arbi/_utils/_reflection.py +42 -0
  20. arbi/_utils/_resources_proxy.py +24 -0
  21. arbi/_utils/_streams.py +12 -0
  22. arbi/_utils/_sync.py +58 -0
  23. arbi/_utils/_transform.py +457 -0
  24. arbi/_utils/_typing.py +156 -0
  25. arbi/_utils/_utils.py +421 -0
  26. arbi/_version.py +4 -0
  27. arbi/lib/.keep +4 -0
  28. arbi/py.typed +0 -0
  29. arbi/resources/__init__.py +19 -0
  30. arbi/resources/api/__init__.py +145 -0
  31. arbi/resources/api/api.py +422 -0
  32. arbi/resources/api/assistant.py +312 -0
  33. arbi/resources/api/configs.py +533 -0
  34. arbi/resources/api/conversation/__init__.py +33 -0
  35. arbi/resources/api/conversation/conversation.py +648 -0
  36. arbi/resources/api/conversation/user.py +270 -0
  37. arbi/resources/api/document/__init__.py +33 -0
  38. arbi/resources/api/document/doctag.py +516 -0
  39. arbi/resources/api/document/document.py +929 -0
  40. arbi/resources/api/health.py +253 -0
  41. arbi/resources/api/notifications.py +478 -0
  42. arbi/resources/api/tag.py +409 -0
  43. arbi/resources/api/user/__init__.py +61 -0
  44. arbi/resources/api/user/contacts.py +322 -0
  45. arbi/resources/api/user/settings.py +283 -0
  46. arbi/resources/api/user/subscription.py +230 -0
  47. arbi/resources/api/user/user.py +943 -0
  48. arbi/resources/api/workspace.py +1198 -0
  49. arbi/types/__init__.py +8 -0
  50. arbi/types/api/__init__.py +94 -0
  51. arbi/types/api/assistant_query_params.py +95 -0
  52. arbi/types/api/assistant_retrieve_params.py +95 -0
  53. arbi/types/api/chunker_config_param.py +9 -0
  54. arbi/types/api/config_create_params.py +227 -0
  55. arbi/types/api/config_create_response.py +17 -0
  56. arbi/types/api/config_delete_response.py +11 -0
  57. arbi/types/api/config_get_versions_response.py +19 -0
  58. arbi/types/api/config_retrieve_response.py +234 -0
  59. arbi/types/api/conversation/__init__.py +8 -0
  60. arbi/types/api/conversation/user_add_params.py +11 -0
  61. arbi/types/api/conversation/user_add_response.py +11 -0
  62. arbi/types/api/conversation/user_remove_params.py +11 -0
  63. arbi/types/api/conversation/user_remove_response.py +11 -0
  64. arbi/types/api/conversation_delete_message_response.py +11 -0
  65. arbi/types/api/conversation_delete_response.py +11 -0
  66. arbi/types/api/conversation_retrieve_message_response.py +105 -0
  67. arbi/types/api/conversation_retrieve_threads_response.py +124 -0
  68. arbi/types/api/conversation_share_response.py +11 -0
  69. arbi/types/api/conversation_update_title_params.py +16 -0
  70. arbi/types/api/conversation_update_title_response.py +13 -0
  71. arbi/types/api/doc_response.py +66 -0
  72. arbi/types/api/document/__init__.py +11 -0
  73. arbi/types/api/document/doc_tag_response.py +40 -0
  74. arbi/types/api/document/doctag_create_params.py +35 -0
  75. arbi/types/api/document/doctag_create_response.py +10 -0
  76. arbi/types/api/document/doctag_delete_params.py +15 -0
  77. arbi/types/api/document/doctag_generate_params.py +22 -0
  78. arbi/types/api/document/doctag_generate_response.py +20 -0
  79. arbi/types/api/document/doctag_update_params.py +35 -0
  80. arbi/types/api/document_date_extractor_llm_config.py +29 -0
  81. arbi/types/api/document_date_extractor_llm_config_param.py +28 -0
  82. arbi/types/api/document_delete_params.py +13 -0
  83. arbi/types/api/document_get_parsed_response.py +26 -0
  84. arbi/types/api/document_retrieve_params.py +16 -0
  85. arbi/types/api/document_retrieve_response.py +10 -0
  86. arbi/types/api/document_update_params.py +42 -0
  87. arbi/types/api/document_update_response.py +10 -0
  88. arbi/types/api/document_upload_from_url_params.py +26 -0
  89. arbi/types/api/document_upload_from_url_response.py +16 -0
  90. arbi/types/api/document_upload_params.py +26 -0
  91. arbi/types/api/document_upload_response.py +16 -0
  92. arbi/types/api/embedder_config.py +30 -0
  93. arbi/types/api/embedder_config_param.py +29 -0
  94. arbi/types/api/health_check_models_response.py +21 -0
  95. arbi/types/api/health_get_models_response.py +19 -0
  96. arbi/types/api/health_retrieve_status_response.py +49 -0
  97. arbi/types/api/model_citation_config.py +20 -0
  98. arbi/types/api/model_citation_config_param.py +20 -0
  99. arbi/types/api/notification_create_params.py +20 -0
  100. arbi/types/api/notification_create_response.py +47 -0
  101. arbi/types/api/notification_delete_params.py +13 -0
  102. arbi/types/api/notification_get_schemas_response.py +197 -0
  103. arbi/types/api/notification_list_response.py +47 -0
  104. arbi/types/api/notification_update_params.py +27 -0
  105. arbi/types/api/notification_update_response.py +47 -0
  106. arbi/types/api/parser_config_param.py +9 -0
  107. arbi/types/api/query_llm_config.py +30 -0
  108. arbi/types/api/query_llm_config_param.py +29 -0
  109. arbi/types/api/reranker_config.py +21 -0
  110. arbi/types/api/reranker_config_param.py +20 -0
  111. arbi/types/api/retriever_config.py +39 -0
  112. arbi/types/api/retriever_config_param.py +38 -0
  113. arbi/types/api/tag_create_params.py +49 -0
  114. arbi/types/api/tag_create_response.py +57 -0
  115. arbi/types/api/tag_delete_response.py +9 -0
  116. arbi/types/api/tag_update_params.py +22 -0
  117. arbi/types/api/tag_update_response.py +57 -0
  118. arbi/types/api/title_llm_config.py +29 -0
  119. arbi/types/api/title_llm_config_param.py +28 -0
  120. arbi/types/api/user/__init__.py +13 -0
  121. arbi/types/api/user/contact_create_params.py +13 -0
  122. arbi/types/api/user/contact_create_response.py +30 -0
  123. arbi/types/api/user/contact_delete_params.py +13 -0
  124. arbi/types/api/user/contact_list_response.py +30 -0
  125. arbi/types/api/user/setting_retrieve_response.py +89 -0
  126. arbi/types/api/user/setting_update_params.py +60 -0
  127. arbi/types/api/user/subscription_create_params.py +13 -0
  128. arbi/types/api/user/subscription_create_response.py +11 -0
  129. arbi/types/api/user/subscription_retrieve_response.py +48 -0
  130. arbi/types/api/user_change_password_params.py +18 -0
  131. arbi/types/api/user_change_password_response.py +11 -0
  132. arbi/types/api/user_check_sso_status_params.py +20 -0
  133. arbi/types/api/user_check_sso_status_response.py +25 -0
  134. arbi/types/api/user_list_products_response.py +37 -0
  135. arbi/types/api/user_list_workspaces_response.py +10 -0
  136. arbi/types/api/user_login_params.py +18 -0
  137. arbi/types/api/user_login_response.py +23 -0
  138. arbi/types/api/user_logout_response.py +9 -0
  139. arbi/types/api/user_register_params.py +22 -0
  140. arbi/types/api/user_response.py +26 -0
  141. arbi/types/api/user_verify_email_params.py +11 -0
  142. arbi/types/api/user_verify_email_response.py +9 -0
  143. arbi/types/api/workspace_copy_params.py +21 -0
  144. arbi/types/api/workspace_copy_response.py +25 -0
  145. arbi/types/api/workspace_create_protected_params.py +16 -0
  146. arbi/types/api/workspace_delete_response.py +9 -0
  147. arbi/types/api/workspace_get_conversations_response.py +30 -0
  148. arbi/types/api/workspace_get_documents_response.py +10 -0
  149. arbi/types/api/workspace_get_stats_response.py +17 -0
  150. arbi/types/api/workspace_get_tags_response.py +60 -0
  151. arbi/types/api/workspace_get_users_response.py +10 -0
  152. arbi/types/api/workspace_remove_user_params.py +11 -0
  153. arbi/types/api/workspace_remove_user_response.py +11 -0
  154. arbi/types/api/workspace_response.py +41 -0
  155. arbi/types/api/workspace_share_params.py +15 -0
  156. arbi/types/api/workspace_share_response.py +13 -0
  157. arbi/types/api/workspace_update_params.py +20 -0
  158. arbi/types/chunk.py +12 -0
  159. arbi/types/chunk_metadata.py +31 -0
  160. arbi/types/chunk_metadata_param.py +32 -0
  161. arbi/types/chunk_param.py +15 -0
  162. arbi-0.18.0.dist-info/METADATA +410 -0
  163. arbi-0.18.0.dist-info/RECORD +165 -0
  164. arbi-0.18.0.dist-info/WHEEL +4 -0
  165. arbi-0.18.0.dist-info/licenses/LICENSE +201 -0
arbi/_client.py ADDED
@@ -0,0 +1,442 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from typing import TYPE_CHECKING, Any, Mapping
7
+ from typing_extensions import Self, override
8
+
9
+ import httpx
10
+
11
+ from . import _exceptions
12
+ from ._qs import Querystring
13
+ from ._types import (
14
+ Omit,
15
+ Timeout,
16
+ NotGiven,
17
+ Transport,
18
+ ProxiesTypes,
19
+ RequestOptions,
20
+ not_given,
21
+ )
22
+ from ._utils import is_given, get_async_library
23
+ from ._compat import cached_property
24
+ from ._version import __version__
25
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
26
+ from ._exceptions import ArbiError, APIStatusError
27
+ from ._base_client import (
28
+ DEFAULT_MAX_RETRIES,
29
+ SyncAPIClient,
30
+ AsyncAPIClient,
31
+ )
32
+
33
+ if TYPE_CHECKING:
34
+ from .resources import api
35
+ from .resources.api.api import APIResource, AsyncAPIResource
36
+
37
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Arbi", "AsyncArbi", "Client", "AsyncClient"]
38
+
39
+
40
+ class Arbi(SyncAPIClient):
41
+ # client options
42
+ api_key: str
43
+
44
+ def __init__(
45
+ self,
46
+ *,
47
+ api_key: str | None = None,
48
+ base_url: str | httpx.URL | None = None,
49
+ timeout: float | Timeout | None | NotGiven = not_given,
50
+ max_retries: int = DEFAULT_MAX_RETRIES,
51
+ default_headers: Mapping[str, str] | None = None,
52
+ default_query: Mapping[str, object] | None = None,
53
+ # Configure a custom httpx client.
54
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
55
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
56
+ http_client: httpx.Client | None = None,
57
+ # Enable or disable schema validation for data returned by the API.
58
+ # When enabled an error APIResponseValidationError is raised
59
+ # if the API responds with invalid data for the expected schema.
60
+ #
61
+ # This parameter may be removed or changed in the future.
62
+ # If you rely on this feature, please open a GitHub issue
63
+ # outlining your use-case to help us decide if it should be
64
+ # part of our public interface in the future.
65
+ _strict_response_validation: bool = False,
66
+ ) -> None:
67
+ """Construct a new synchronous Arbi client instance.
68
+
69
+ This automatically infers the `api_key` argument from the `ARBI_API_KEY` environment variable if it is not provided.
70
+ """
71
+ if api_key is None:
72
+ api_key = os.environ.get("ARBI_API_KEY")
73
+ if api_key is None:
74
+ raise ArbiError(
75
+ "The api_key client option must be set either by passing api_key to the client or by setting the ARBI_API_KEY environment variable"
76
+ )
77
+ self.api_key = api_key
78
+
79
+ if base_url is None:
80
+ base_url = os.environ.get("ARBI_BASE_URL")
81
+ if base_url is None:
82
+ base_url = f"https://api.example.com"
83
+
84
+ super().__init__(
85
+ version=__version__,
86
+ base_url=base_url,
87
+ max_retries=max_retries,
88
+ timeout=timeout,
89
+ http_client=http_client,
90
+ custom_headers=default_headers,
91
+ custom_query=default_query,
92
+ _strict_response_validation=_strict_response_validation,
93
+ )
94
+
95
+ @cached_property
96
+ def api(self) -> APIResource:
97
+ from .resources.api import APIResource
98
+
99
+ return APIResource(self)
100
+
101
+ @cached_property
102
+ def with_raw_response(self) -> ArbiWithRawResponse:
103
+ return ArbiWithRawResponse(self)
104
+
105
+ @cached_property
106
+ def with_streaming_response(self) -> ArbiWithStreamedResponse:
107
+ return ArbiWithStreamedResponse(self)
108
+
109
+ @property
110
+ @override
111
+ def qs(self) -> Querystring:
112
+ return Querystring(array_format="comma")
113
+
114
+ @property
115
+ @override
116
+ def auth_headers(self) -> dict[str, str]:
117
+ api_key = self.api_key
118
+ return {"Authorization": f"Bearer {api_key}"}
119
+
120
+ @property
121
+ @override
122
+ def default_headers(self) -> dict[str, str | Omit]:
123
+ return {
124
+ **super().default_headers,
125
+ "X-Stainless-Async": "false",
126
+ **self._custom_headers,
127
+ }
128
+
129
+ def copy(
130
+ self,
131
+ *,
132
+ api_key: str | None = None,
133
+ base_url: str | httpx.URL | None = None,
134
+ timeout: float | Timeout | None | NotGiven = not_given,
135
+ http_client: httpx.Client | None = None,
136
+ max_retries: int | NotGiven = not_given,
137
+ default_headers: Mapping[str, str] | None = None,
138
+ set_default_headers: Mapping[str, str] | None = None,
139
+ default_query: Mapping[str, object] | None = None,
140
+ set_default_query: Mapping[str, object] | None = None,
141
+ _extra_kwargs: Mapping[str, Any] = {},
142
+ ) -> Self:
143
+ """
144
+ Create a new client instance re-using the same options given to the current client with optional overriding.
145
+ """
146
+ if default_headers is not None and set_default_headers is not None:
147
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
148
+
149
+ if default_query is not None and set_default_query is not None:
150
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
151
+
152
+ headers = self._custom_headers
153
+ if default_headers is not None:
154
+ headers = {**headers, **default_headers}
155
+ elif set_default_headers is not None:
156
+ headers = set_default_headers
157
+
158
+ params = self._custom_query
159
+ if default_query is not None:
160
+ params = {**params, **default_query}
161
+ elif set_default_query is not None:
162
+ params = set_default_query
163
+
164
+ http_client = http_client or self._client
165
+ return self.__class__(
166
+ api_key=api_key or self.api_key,
167
+ base_url=base_url or self.base_url,
168
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
169
+ http_client=http_client,
170
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
171
+ default_headers=headers,
172
+ default_query=params,
173
+ **_extra_kwargs,
174
+ )
175
+
176
+ # Alias for `copy` for nicer inline usage, e.g.
177
+ # client.with_options(timeout=10).foo.create(...)
178
+ with_options = copy
179
+
180
+ @override
181
+ def _make_status_error(
182
+ self,
183
+ err_msg: str,
184
+ *,
185
+ body: object,
186
+ response: httpx.Response,
187
+ ) -> APIStatusError:
188
+ if response.status_code == 400:
189
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
190
+
191
+ if response.status_code == 401:
192
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
193
+
194
+ if response.status_code == 403:
195
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
196
+
197
+ if response.status_code == 404:
198
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
199
+
200
+ if response.status_code == 409:
201
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
202
+
203
+ if response.status_code == 422:
204
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
205
+
206
+ if response.status_code == 429:
207
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
208
+
209
+ if response.status_code >= 500:
210
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
211
+ return APIStatusError(err_msg, response=response, body=body)
212
+
213
+
214
+ class AsyncArbi(AsyncAPIClient):
215
+ # client options
216
+ api_key: str
217
+
218
+ def __init__(
219
+ self,
220
+ *,
221
+ api_key: str | None = None,
222
+ base_url: str | httpx.URL | None = None,
223
+ timeout: float | Timeout | None | NotGiven = not_given,
224
+ max_retries: int = DEFAULT_MAX_RETRIES,
225
+ default_headers: Mapping[str, str] | None = None,
226
+ default_query: Mapping[str, object] | None = None,
227
+ # Configure a custom httpx client.
228
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
229
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
230
+ http_client: httpx.AsyncClient | None = None,
231
+ # Enable or disable schema validation for data returned by the API.
232
+ # When enabled an error APIResponseValidationError is raised
233
+ # if the API responds with invalid data for the expected schema.
234
+ #
235
+ # This parameter may be removed or changed in the future.
236
+ # If you rely on this feature, please open a GitHub issue
237
+ # outlining your use-case to help us decide if it should be
238
+ # part of our public interface in the future.
239
+ _strict_response_validation: bool = False,
240
+ ) -> None:
241
+ """Construct a new async AsyncArbi client instance.
242
+
243
+ This automatically infers the `api_key` argument from the `ARBI_API_KEY` environment variable if it is not provided.
244
+ """
245
+ if api_key is None:
246
+ api_key = os.environ.get("ARBI_API_KEY")
247
+ if api_key is None:
248
+ raise ArbiError(
249
+ "The api_key client option must be set either by passing api_key to the client or by setting the ARBI_API_KEY environment variable"
250
+ )
251
+ self.api_key = api_key
252
+
253
+ if base_url is None:
254
+ base_url = os.environ.get("ARBI_BASE_URL")
255
+ if base_url is None:
256
+ base_url = f"https://api.example.com"
257
+
258
+ super().__init__(
259
+ version=__version__,
260
+ base_url=base_url,
261
+ max_retries=max_retries,
262
+ timeout=timeout,
263
+ http_client=http_client,
264
+ custom_headers=default_headers,
265
+ custom_query=default_query,
266
+ _strict_response_validation=_strict_response_validation,
267
+ )
268
+
269
+ @cached_property
270
+ def api(self) -> AsyncAPIResource:
271
+ from .resources.api import AsyncAPIResource
272
+
273
+ return AsyncAPIResource(self)
274
+
275
+ @cached_property
276
+ def with_raw_response(self) -> AsyncArbiWithRawResponse:
277
+ return AsyncArbiWithRawResponse(self)
278
+
279
+ @cached_property
280
+ def with_streaming_response(self) -> AsyncArbiWithStreamedResponse:
281
+ return AsyncArbiWithStreamedResponse(self)
282
+
283
+ @property
284
+ @override
285
+ def qs(self) -> Querystring:
286
+ return Querystring(array_format="comma")
287
+
288
+ @property
289
+ @override
290
+ def auth_headers(self) -> dict[str, str]:
291
+ api_key = self.api_key
292
+ return {"Authorization": f"Bearer {api_key}"}
293
+
294
+ @property
295
+ @override
296
+ def default_headers(self) -> dict[str, str | Omit]:
297
+ return {
298
+ **super().default_headers,
299
+ "X-Stainless-Async": f"async:{get_async_library()}",
300
+ **self._custom_headers,
301
+ }
302
+
303
+ def copy(
304
+ self,
305
+ *,
306
+ api_key: str | None = None,
307
+ base_url: str | httpx.URL | None = None,
308
+ timeout: float | Timeout | None | NotGiven = not_given,
309
+ http_client: httpx.AsyncClient | None = None,
310
+ max_retries: int | NotGiven = not_given,
311
+ default_headers: Mapping[str, str] | None = None,
312
+ set_default_headers: Mapping[str, str] | None = None,
313
+ default_query: Mapping[str, object] | None = None,
314
+ set_default_query: Mapping[str, object] | None = None,
315
+ _extra_kwargs: Mapping[str, Any] = {},
316
+ ) -> Self:
317
+ """
318
+ Create a new client instance re-using the same options given to the current client with optional overriding.
319
+ """
320
+ if default_headers is not None and set_default_headers is not None:
321
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
322
+
323
+ if default_query is not None and set_default_query is not None:
324
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
325
+
326
+ headers = self._custom_headers
327
+ if default_headers is not None:
328
+ headers = {**headers, **default_headers}
329
+ elif set_default_headers is not None:
330
+ headers = set_default_headers
331
+
332
+ params = self._custom_query
333
+ if default_query is not None:
334
+ params = {**params, **default_query}
335
+ elif set_default_query is not None:
336
+ params = set_default_query
337
+
338
+ http_client = http_client or self._client
339
+ return self.__class__(
340
+ api_key=api_key or self.api_key,
341
+ base_url=base_url or self.base_url,
342
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
343
+ http_client=http_client,
344
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
345
+ default_headers=headers,
346
+ default_query=params,
347
+ **_extra_kwargs,
348
+ )
349
+
350
+ # Alias for `copy` for nicer inline usage, e.g.
351
+ # client.with_options(timeout=10).foo.create(...)
352
+ with_options = copy
353
+
354
+ @override
355
+ def _make_status_error(
356
+ self,
357
+ err_msg: str,
358
+ *,
359
+ body: object,
360
+ response: httpx.Response,
361
+ ) -> APIStatusError:
362
+ if response.status_code == 400:
363
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
364
+
365
+ if response.status_code == 401:
366
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
367
+
368
+ if response.status_code == 403:
369
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
370
+
371
+ if response.status_code == 404:
372
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
373
+
374
+ if response.status_code == 409:
375
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
376
+
377
+ if response.status_code == 422:
378
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
379
+
380
+ if response.status_code == 429:
381
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
382
+
383
+ if response.status_code >= 500:
384
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
385
+ return APIStatusError(err_msg, response=response, body=body)
386
+
387
+
388
+ class ArbiWithRawResponse:
389
+ _client: Arbi
390
+
391
+ def __init__(self, client: Arbi) -> None:
392
+ self._client = client
393
+
394
+ @cached_property
395
+ def api(self) -> api.APIResourceWithRawResponse:
396
+ from .resources.api import APIResourceWithRawResponse
397
+
398
+ return APIResourceWithRawResponse(self._client.api)
399
+
400
+
401
+ class AsyncArbiWithRawResponse:
402
+ _client: AsyncArbi
403
+
404
+ def __init__(self, client: AsyncArbi) -> None:
405
+ self._client = client
406
+
407
+ @cached_property
408
+ def api(self) -> api.AsyncAPIResourceWithRawResponse:
409
+ from .resources.api import AsyncAPIResourceWithRawResponse
410
+
411
+ return AsyncAPIResourceWithRawResponse(self._client.api)
412
+
413
+
414
+ class ArbiWithStreamedResponse:
415
+ _client: Arbi
416
+
417
+ def __init__(self, client: Arbi) -> None:
418
+ self._client = client
419
+
420
+ @cached_property
421
+ def api(self) -> api.APIResourceWithStreamingResponse:
422
+ from .resources.api import APIResourceWithStreamingResponse
423
+
424
+ return APIResourceWithStreamingResponse(self._client.api)
425
+
426
+
427
+ class AsyncArbiWithStreamedResponse:
428
+ _client: AsyncArbi
429
+
430
+ def __init__(self, client: AsyncArbi) -> None:
431
+ self._client = client
432
+
433
+ @cached_property
434
+ def api(self) -> api.AsyncAPIResourceWithStreamingResponse:
435
+ from .resources.api import AsyncAPIResourceWithStreamingResponse
436
+
437
+ return AsyncAPIResourceWithStreamingResponse(self._client.api)
438
+
439
+
440
+ Client = Arbi
441
+
442
+ AsyncClient = AsyncArbi
arbi/_compat.py ADDED
@@ -0,0 +1,219 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
4
+ from datetime import date, datetime
5
+ from typing_extensions import Self, Literal
6
+
7
+ import pydantic
8
+ from pydantic.fields import FieldInfo
9
+
10
+ from ._types import IncEx, StrBytesIntFloat
11
+
12
+ _T = TypeVar("_T")
13
+ _ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
14
+
15
+ # --------------- Pydantic v2, v3 compatibility ---------------
16
+
17
+ # Pyright incorrectly reports some of our functions as overriding a method when they don't
18
+ # pyright: reportIncompatibleMethodOverride=false
19
+
20
+ PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
21
+
22
+ if TYPE_CHECKING:
23
+
24
+ def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
25
+ ...
26
+
27
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime: # noqa: ARG001
28
+ ...
29
+
30
+ def get_args(t: type[Any]) -> tuple[Any, ...]: # noqa: ARG001
31
+ ...
32
+
33
+ def is_union(tp: type[Any] | None) -> bool: # noqa: ARG001
34
+ ...
35
+
36
+ def get_origin(t: type[Any]) -> type[Any] | None: # noqa: ARG001
37
+ ...
38
+
39
+ def is_literal_type(type_: type[Any]) -> bool: # noqa: ARG001
40
+ ...
41
+
42
+ def is_typeddict(type_: type[Any]) -> bool: # noqa: ARG001
43
+ ...
44
+
45
+ else:
46
+ # v1 re-exports
47
+ if PYDANTIC_V1:
48
+ from pydantic.typing import (
49
+ get_args as get_args,
50
+ is_union as is_union,
51
+ get_origin as get_origin,
52
+ is_typeddict as is_typeddict,
53
+ is_literal_type as is_literal_type,
54
+ )
55
+ from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
56
+ else:
57
+ from ._utils import (
58
+ get_args as get_args,
59
+ is_union as is_union,
60
+ get_origin as get_origin,
61
+ parse_date as parse_date,
62
+ is_typeddict as is_typeddict,
63
+ parse_datetime as parse_datetime,
64
+ is_literal_type as is_literal_type,
65
+ )
66
+
67
+
68
+ # refactored config
69
+ if TYPE_CHECKING:
70
+ from pydantic import ConfigDict as ConfigDict
71
+ else:
72
+ if PYDANTIC_V1:
73
+ # TODO: provide an error message here?
74
+ ConfigDict = None
75
+ else:
76
+ from pydantic import ConfigDict as ConfigDict
77
+
78
+
79
+ # renamed methods / properties
80
+ def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
81
+ if PYDANTIC_V1:
82
+ return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
83
+ else:
84
+ return model.model_validate(value)
85
+
86
+
87
+ def field_is_required(field: FieldInfo) -> bool:
88
+ if PYDANTIC_V1:
89
+ return field.required # type: ignore
90
+ return field.is_required()
91
+
92
+
93
+ def field_get_default(field: FieldInfo) -> Any:
94
+ value = field.get_default()
95
+ if PYDANTIC_V1:
96
+ return value
97
+ from pydantic_core import PydanticUndefined
98
+
99
+ if value == PydanticUndefined:
100
+ return None
101
+ return value
102
+
103
+
104
+ def field_outer_type(field: FieldInfo) -> Any:
105
+ if PYDANTIC_V1:
106
+ return field.outer_type_ # type: ignore
107
+ return field.annotation
108
+
109
+
110
+ def get_model_config(model: type[pydantic.BaseModel]) -> Any:
111
+ if PYDANTIC_V1:
112
+ return model.__config__ # type: ignore
113
+ return model.model_config
114
+
115
+
116
+ def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
117
+ if PYDANTIC_V1:
118
+ return model.__fields__ # type: ignore
119
+ return model.model_fields
120
+
121
+
122
+ def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
123
+ if PYDANTIC_V1:
124
+ return model.copy(deep=deep) # type: ignore
125
+ return model.model_copy(deep=deep)
126
+
127
+
128
+ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
129
+ if PYDANTIC_V1:
130
+ return model.json(indent=indent) # type: ignore
131
+ return model.model_dump_json(indent=indent)
132
+
133
+
134
+ def model_dump(
135
+ model: pydantic.BaseModel,
136
+ *,
137
+ exclude: IncEx | None = None,
138
+ exclude_unset: bool = False,
139
+ exclude_defaults: bool = False,
140
+ warnings: bool = True,
141
+ mode: Literal["json", "python"] = "python",
142
+ ) -> dict[str, Any]:
143
+ if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
144
+ return model.model_dump(
145
+ mode=mode,
146
+ exclude=exclude,
147
+ exclude_unset=exclude_unset,
148
+ exclude_defaults=exclude_defaults,
149
+ # warnings are not supported in Pydantic v1
150
+ warnings=True if PYDANTIC_V1 else warnings,
151
+ )
152
+ return cast(
153
+ "dict[str, Any]",
154
+ model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
155
+ exclude=exclude,
156
+ exclude_unset=exclude_unset,
157
+ exclude_defaults=exclude_defaults,
158
+ ),
159
+ )
160
+
161
+
162
+ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
163
+ if PYDANTIC_V1:
164
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
165
+ return model.model_validate(data)
166
+
167
+
168
+ # generic models
169
+ if TYPE_CHECKING:
170
+
171
+ class GenericModel(pydantic.BaseModel): ...
172
+
173
+ else:
174
+ if PYDANTIC_V1:
175
+ import pydantic.generics
176
+
177
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
178
+ else:
179
+ # there no longer needs to be a distinction in v2 but
180
+ # we still have to create our own subclass to avoid
181
+ # inconsistent MRO ordering errors
182
+ class GenericModel(pydantic.BaseModel): ...
183
+
184
+
185
+ # cached properties
186
+ if TYPE_CHECKING:
187
+ cached_property = property
188
+
189
+ # we define a separate type (copied from typeshed)
190
+ # that represents that `cached_property` is `set`able
191
+ # at runtime, which differs from `@property`.
192
+ #
193
+ # this is a separate type as editors likely special case
194
+ # `@property` and we don't want to cause issues just to have
195
+ # more helpful internal types.
196
+
197
+ class typed_cached_property(Generic[_T]):
198
+ func: Callable[[Any], _T]
199
+ attrname: str | None
200
+
201
+ def __init__(self, func: Callable[[Any], _T]) -> None: ...
202
+
203
+ @overload
204
+ def __get__(self, instance: None, owner: type[Any] | None = None) -> Self: ...
205
+
206
+ @overload
207
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T: ...
208
+
209
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T | Self:
210
+ raise NotImplementedError()
211
+
212
+ def __set_name__(self, owner: type[Any], name: str) -> None: ...
213
+
214
+ # __set__ is not defined at runtime, but @cached_property is designed to be settable
215
+ def __set__(self, instance: object, value: _T) -> None: ...
216
+ else:
217
+ from functools import cached_property as cached_property
218
+
219
+ typed_cached_property = cached_property
arbi/_constants.py ADDED
@@ -0,0 +1,14 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import httpx
4
+
5
+ RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
6
+ OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"
7
+
8
+ # default timeout is 1 minute
9
+ DEFAULT_TIMEOUT = httpx.Timeout(timeout=60, connect=5.0)
10
+ DEFAULT_MAX_RETRIES = 2
11
+ DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
12
+
13
+ INITIAL_RETRY_DELAY = 0.5
14
+ MAX_RETRY_DELAY = 8.0