arbi 0.1.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.

Potentially problematic release.


This version of arbi might be problematic. Click here for more details.

Files changed (143) hide show
  1. arbi/__init__.py +90 -0
  2. arbi/_base_client.py +1995 -0
  3. arbi/_client.py +394 -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 +829 -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 +219 -0
  14. arbi/_utils/__init__.py +57 -0
  15. arbi/_utils/_logs.py +25 -0
  16. arbi/_utils/_proxy.py +65 -0
  17. arbi/_utils/_reflection.py +42 -0
  18. arbi/_utils/_resources_proxy.py +24 -0
  19. arbi/_utils/_streams.py +12 -0
  20. arbi/_utils/_sync.py +86 -0
  21. arbi/_utils/_transform.py +447 -0
  22. arbi/_utils/_typing.py +151 -0
  23. arbi/_utils/_utils.py +422 -0
  24. arbi/_version.py +4 -0
  25. arbi/lib/.keep +4 -0
  26. arbi/py.typed +0 -0
  27. arbi/resources/__init__.py +19 -0
  28. arbi/resources/api/__init__.py +145 -0
  29. arbi/resources/api/api.py +422 -0
  30. arbi/resources/api/assistant.py +300 -0
  31. arbi/resources/api/configs.py +499 -0
  32. arbi/resources/api/conversation/__init__.py +33 -0
  33. arbi/resources/api/conversation/conversation.py +555 -0
  34. arbi/resources/api/conversation/user.py +270 -0
  35. arbi/resources/api/document/__init__.py +33 -0
  36. arbi/resources/api/document/annotation.py +384 -0
  37. arbi/resources/api/document/document.py +873 -0
  38. arbi/resources/api/health.py +304 -0
  39. arbi/resources/api/sso.py +333 -0
  40. arbi/resources/api/tag.py +614 -0
  41. arbi/resources/api/user/__init__.py +33 -0
  42. arbi/resources/api/user/settings.py +251 -0
  43. arbi/resources/api/user/user.py +532 -0
  44. arbi/resources/api/workspace.py +1061 -0
  45. arbi/types/__init__.py +8 -0
  46. arbi/types/api/__init__.py +84 -0
  47. arbi/types/api/assistant_query_params.py +59 -0
  48. arbi/types/api/assistant_retrieve_params.py +59 -0
  49. arbi/types/api/chunker_config_param.py +9 -0
  50. arbi/types/api/config_create_params.py +45 -0
  51. arbi/types/api/config_create_response.py +15 -0
  52. arbi/types/api/config_delete_response.py +11 -0
  53. arbi/types/api/config_get_versions_response.py +19 -0
  54. arbi/types/api/config_retrieve_response.py +46 -0
  55. arbi/types/api/conversation/__init__.py +8 -0
  56. arbi/types/api/conversation/user_add_params.py +11 -0
  57. arbi/types/api/conversation/user_add_response.py +11 -0
  58. arbi/types/api/conversation/user_remove_params.py +11 -0
  59. arbi/types/api/conversation/user_remove_response.py +11 -0
  60. arbi/types/api/conversation_delete_message_response.py +11 -0
  61. arbi/types/api/conversation_delete_response.py +11 -0
  62. arbi/types/api/conversation_retrieve_threads_response.py +91 -0
  63. arbi/types/api/conversation_share_response.py +11 -0
  64. arbi/types/api/conversation_update_title_params.py +12 -0
  65. arbi/types/api/conversation_update_title_response.py +13 -0
  66. arbi/types/api/doc_response.py +48 -0
  67. arbi/types/api/document/__init__.py +8 -0
  68. arbi/types/api/document/annotation_create_params.py +16 -0
  69. arbi/types/api/document/annotation_delete_response.py +11 -0
  70. arbi/types/api/document/annotation_update_params.py +16 -0
  71. arbi/types/api/document/doc_tag_response.py +26 -0
  72. arbi/types/api/document_date_extractor_llm_config.py +29 -0
  73. arbi/types/api/document_date_extractor_llm_config_param.py +28 -0
  74. arbi/types/api/document_delete_response.py +11 -0
  75. arbi/types/api/document_get_parsed_response.py +26 -0
  76. arbi/types/api/document_get_tags_response.py +10 -0
  77. arbi/types/api/document_update_params.py +19 -0
  78. arbi/types/api/document_update_response.py +22 -0
  79. arbi/types/api/document_upload_params.py +23 -0
  80. arbi/types/api/document_view_params.py +13 -0
  81. arbi/types/api/embedder_config.py +18 -0
  82. arbi/types/api/embedder_config_param.py +17 -0
  83. arbi/types/api/health_check_app_response.py +9 -0
  84. arbi/types/api/health_check_models_response.py +21 -0
  85. arbi/types/api/health_check_services_response.py +23 -0
  86. arbi/types/api/health_get_models_response.py +19 -0
  87. arbi/types/api/model_citation_config.py +23 -0
  88. arbi/types/api/model_citation_config_param.py +23 -0
  89. arbi/types/api/parser_config_param.py +9 -0
  90. arbi/types/api/query_llm_config.py +30 -0
  91. arbi/types/api/query_llm_config_param.py +29 -0
  92. arbi/types/api/reranker_config.py +21 -0
  93. arbi/types/api/reranker_config_param.py +20 -0
  94. arbi/types/api/retriever_config.py +23 -0
  95. arbi/types/api/retriever_config_param.py +23 -0
  96. arbi/types/api/sso_invite_params.py +11 -0
  97. arbi/types/api/sso_invite_response.py +11 -0
  98. arbi/types/api/sso_login_params.py +16 -0
  99. arbi/types/api/sso_login_response.py +15 -0
  100. arbi/types/api/sso_rotate_passcode_response.py +11 -0
  101. arbi/types/api/tag_apply_to_docs_params.py +12 -0
  102. arbi/types/api/tag_apply_to_docs_response.py +13 -0
  103. arbi/types/api/tag_create_params.py +18 -0
  104. arbi/types/api/tag_create_response.py +11 -0
  105. arbi/types/api/tag_delete_response.py +9 -0
  106. arbi/types/api/tag_get_docs_response.py +10 -0
  107. arbi/types/api/tag_remove_from_docs_params.py +12 -0
  108. arbi/types/api/tag_remove_from_docs_response.py +13 -0
  109. arbi/types/api/tag_update_params.py +14 -0
  110. arbi/types/api/tag_update_response.py +17 -0
  111. arbi/types/api/title_llm_config.py +29 -0
  112. arbi/types/api/title_llm_config_param.py +28 -0
  113. arbi/types/api/token.py +13 -0
  114. arbi/types/api/user/__init__.py +6 -0
  115. arbi/types/api/user/setting_retrieve_response.py +36 -0
  116. arbi/types/api/user/setting_update_params.py +24 -0
  117. arbi/types/api/user_list_workspaces_response.py +10 -0
  118. arbi/types/api/user_login_params.py +13 -0
  119. arbi/types/api/user_logout_response.py +9 -0
  120. arbi/types/api/user_register_params.py +17 -0
  121. arbi/types/api/user_response.py +19 -0
  122. arbi/types/api/workspace_create_protected_params.py +14 -0
  123. arbi/types/api/workspace_delete_response.py +9 -0
  124. arbi/types/api/workspace_get_conversations_response.py +28 -0
  125. arbi/types/api/workspace_get_doctags_response.py +10 -0
  126. arbi/types/api/workspace_get_documents_response.py +10 -0
  127. arbi/types/api/workspace_get_stats_response.py +13 -0
  128. arbi/types/api/workspace_get_tags_response.py +30 -0
  129. arbi/types/api/workspace_get_users_response.py +17 -0
  130. arbi/types/api/workspace_remove_user_params.py +11 -0
  131. arbi/types/api/workspace_remove_user_response.py +11 -0
  132. arbi/types/api/workspace_response.py +24 -0
  133. arbi/types/api/workspace_share_params.py +11 -0
  134. arbi/types/api/workspace_share_response.py +21 -0
  135. arbi/types/api/workspace_update_params.py +14 -0
  136. arbi/types/chunk.py +12 -0
  137. arbi/types/chunk_metadata.py +31 -0
  138. arbi/types/chunk_metadata_param.py +32 -0
  139. arbi/types/chunk_param.py +15 -0
  140. arbi-0.1.0.dist-info/METADATA +410 -0
  141. arbi-0.1.0.dist-info/RECORD +143 -0
  142. arbi-0.1.0.dist-info/WHEEL +4 -0
  143. arbi-0.1.0.dist-info/licenses/LICENSE +201 -0
arbi/_client.py ADDED
@@ -0,0 +1,394 @@
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 Any, Union, 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
+ NOT_GIVEN,
15
+ Omit,
16
+ Timeout,
17
+ NotGiven,
18
+ Transport,
19
+ ProxiesTypes,
20
+ RequestOptions,
21
+ )
22
+ from ._utils import is_given, get_async_library
23
+ from ._version import __version__
24
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
25
+ from ._exceptions import ArbiError, APIStatusError
26
+ from ._base_client import (
27
+ DEFAULT_MAX_RETRIES,
28
+ SyncAPIClient,
29
+ AsyncAPIClient,
30
+ )
31
+ from .resources.api import api
32
+
33
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Arbi", "AsyncArbi", "Client", "AsyncClient"]
34
+
35
+
36
+ class Arbi(SyncAPIClient):
37
+ api: api.APIResource
38
+ with_raw_response: ArbiWithRawResponse
39
+ with_streaming_response: ArbiWithStreamedResponse
40
+
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: Union[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
+ self.api = api.APIResource(self)
96
+ self.with_raw_response = ArbiWithRawResponse(self)
97
+ self.with_streaming_response = ArbiWithStreamedResponse(self)
98
+
99
+ @property
100
+ @override
101
+ def qs(self) -> Querystring:
102
+ return Querystring(array_format="comma")
103
+
104
+ @property
105
+ @override
106
+ def auth_headers(self) -> dict[str, str]:
107
+ api_key = self.api_key
108
+ return {"Authorization": f"Bearer {api_key}"}
109
+
110
+ @property
111
+ @override
112
+ def default_headers(self) -> dict[str, str | Omit]:
113
+ return {
114
+ **super().default_headers,
115
+ "X-Stainless-Async": "false",
116
+ **self._custom_headers,
117
+ }
118
+
119
+ def copy(
120
+ self,
121
+ *,
122
+ api_key: str | None = None,
123
+ base_url: str | httpx.URL | None = None,
124
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
125
+ http_client: httpx.Client | None = None,
126
+ max_retries: int | NotGiven = NOT_GIVEN,
127
+ default_headers: Mapping[str, str] | None = None,
128
+ set_default_headers: Mapping[str, str] | None = None,
129
+ default_query: Mapping[str, object] | None = None,
130
+ set_default_query: Mapping[str, object] | None = None,
131
+ _extra_kwargs: Mapping[str, Any] = {},
132
+ ) -> Self:
133
+ """
134
+ Create a new client instance re-using the same options given to the current client with optional overriding.
135
+ """
136
+ if default_headers is not None and set_default_headers is not None:
137
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
138
+
139
+ if default_query is not None and set_default_query is not None:
140
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
141
+
142
+ headers = self._custom_headers
143
+ if default_headers is not None:
144
+ headers = {**headers, **default_headers}
145
+ elif set_default_headers is not None:
146
+ headers = set_default_headers
147
+
148
+ params = self._custom_query
149
+ if default_query is not None:
150
+ params = {**params, **default_query}
151
+ elif set_default_query is not None:
152
+ params = set_default_query
153
+
154
+ http_client = http_client or self._client
155
+ return self.__class__(
156
+ api_key=api_key or self.api_key,
157
+ base_url=base_url or self.base_url,
158
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
159
+ http_client=http_client,
160
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
161
+ default_headers=headers,
162
+ default_query=params,
163
+ **_extra_kwargs,
164
+ )
165
+
166
+ # Alias for `copy` for nicer inline usage, e.g.
167
+ # client.with_options(timeout=10).foo.create(...)
168
+ with_options = copy
169
+
170
+ @override
171
+ def _make_status_error(
172
+ self,
173
+ err_msg: str,
174
+ *,
175
+ body: object,
176
+ response: httpx.Response,
177
+ ) -> APIStatusError:
178
+ if response.status_code == 400:
179
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
180
+
181
+ if response.status_code == 401:
182
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
183
+
184
+ if response.status_code == 403:
185
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
186
+
187
+ if response.status_code == 404:
188
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
189
+
190
+ if response.status_code == 409:
191
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
192
+
193
+ if response.status_code == 422:
194
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
195
+
196
+ if response.status_code == 429:
197
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
198
+
199
+ if response.status_code >= 500:
200
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
201
+ return APIStatusError(err_msg, response=response, body=body)
202
+
203
+
204
+ class AsyncArbi(AsyncAPIClient):
205
+ api: api.AsyncAPIResource
206
+ with_raw_response: AsyncArbiWithRawResponse
207
+ with_streaming_response: AsyncArbiWithStreamedResponse
208
+
209
+ # client options
210
+ api_key: str
211
+
212
+ def __init__(
213
+ self,
214
+ *,
215
+ api_key: str | None = None,
216
+ base_url: str | httpx.URL | None = None,
217
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
218
+ max_retries: int = DEFAULT_MAX_RETRIES,
219
+ default_headers: Mapping[str, str] | None = None,
220
+ default_query: Mapping[str, object] | None = None,
221
+ # Configure a custom httpx client.
222
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
223
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
224
+ http_client: httpx.AsyncClient | None = None,
225
+ # Enable or disable schema validation for data returned by the API.
226
+ # When enabled an error APIResponseValidationError is raised
227
+ # if the API responds with invalid data for the expected schema.
228
+ #
229
+ # This parameter may be removed or changed in the future.
230
+ # If you rely on this feature, please open a GitHub issue
231
+ # outlining your use-case to help us decide if it should be
232
+ # part of our public interface in the future.
233
+ _strict_response_validation: bool = False,
234
+ ) -> None:
235
+ """Construct a new async AsyncArbi client instance.
236
+
237
+ This automatically infers the `api_key` argument from the `ARBI_API_KEY` environment variable if it is not provided.
238
+ """
239
+ if api_key is None:
240
+ api_key = os.environ.get("ARBI_API_KEY")
241
+ if api_key is None:
242
+ raise ArbiError(
243
+ "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"
244
+ )
245
+ self.api_key = api_key
246
+
247
+ if base_url is None:
248
+ base_url = os.environ.get("ARBI_BASE_URL")
249
+ if base_url is None:
250
+ base_url = f"https://api.example.com"
251
+
252
+ super().__init__(
253
+ version=__version__,
254
+ base_url=base_url,
255
+ max_retries=max_retries,
256
+ timeout=timeout,
257
+ http_client=http_client,
258
+ custom_headers=default_headers,
259
+ custom_query=default_query,
260
+ _strict_response_validation=_strict_response_validation,
261
+ )
262
+
263
+ self.api = api.AsyncAPIResource(self)
264
+ self.with_raw_response = AsyncArbiWithRawResponse(self)
265
+ self.with_streaming_response = AsyncArbiWithStreamedResponse(self)
266
+
267
+ @property
268
+ @override
269
+ def qs(self) -> Querystring:
270
+ return Querystring(array_format="comma")
271
+
272
+ @property
273
+ @override
274
+ def auth_headers(self) -> dict[str, str]:
275
+ api_key = self.api_key
276
+ return {"Authorization": f"Bearer {api_key}"}
277
+
278
+ @property
279
+ @override
280
+ def default_headers(self) -> dict[str, str | Omit]:
281
+ return {
282
+ **super().default_headers,
283
+ "X-Stainless-Async": f"async:{get_async_library()}",
284
+ **self._custom_headers,
285
+ }
286
+
287
+ def copy(
288
+ self,
289
+ *,
290
+ api_key: str | None = None,
291
+ base_url: str | httpx.URL | None = None,
292
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
293
+ http_client: httpx.AsyncClient | None = None,
294
+ max_retries: int | NotGiven = NOT_GIVEN,
295
+ default_headers: Mapping[str, str] | None = None,
296
+ set_default_headers: Mapping[str, str] | None = None,
297
+ default_query: Mapping[str, object] | None = None,
298
+ set_default_query: Mapping[str, object] | None = None,
299
+ _extra_kwargs: Mapping[str, Any] = {},
300
+ ) -> Self:
301
+ """
302
+ Create a new client instance re-using the same options given to the current client with optional overriding.
303
+ """
304
+ if default_headers is not None and set_default_headers is not None:
305
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
306
+
307
+ if default_query is not None and set_default_query is not None:
308
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
309
+
310
+ headers = self._custom_headers
311
+ if default_headers is not None:
312
+ headers = {**headers, **default_headers}
313
+ elif set_default_headers is not None:
314
+ headers = set_default_headers
315
+
316
+ params = self._custom_query
317
+ if default_query is not None:
318
+ params = {**params, **default_query}
319
+ elif set_default_query is not None:
320
+ params = set_default_query
321
+
322
+ http_client = http_client or self._client
323
+ return self.__class__(
324
+ api_key=api_key or self.api_key,
325
+ base_url=base_url or self.base_url,
326
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
327
+ http_client=http_client,
328
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
329
+ default_headers=headers,
330
+ default_query=params,
331
+ **_extra_kwargs,
332
+ )
333
+
334
+ # Alias for `copy` for nicer inline usage, e.g.
335
+ # client.with_options(timeout=10).foo.create(...)
336
+ with_options = copy
337
+
338
+ @override
339
+ def _make_status_error(
340
+ self,
341
+ err_msg: str,
342
+ *,
343
+ body: object,
344
+ response: httpx.Response,
345
+ ) -> APIStatusError:
346
+ if response.status_code == 400:
347
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
348
+
349
+ if response.status_code == 401:
350
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
351
+
352
+ if response.status_code == 403:
353
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
354
+
355
+ if response.status_code == 404:
356
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
357
+
358
+ if response.status_code == 409:
359
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
360
+
361
+ if response.status_code == 422:
362
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
363
+
364
+ if response.status_code == 429:
365
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
366
+
367
+ if response.status_code >= 500:
368
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
369
+ return APIStatusError(err_msg, response=response, body=body)
370
+
371
+
372
+ class ArbiWithRawResponse:
373
+ def __init__(self, client: Arbi) -> None:
374
+ self.api = api.APIResourceWithRawResponse(client.api)
375
+
376
+
377
+ class AsyncArbiWithRawResponse:
378
+ def __init__(self, client: AsyncArbi) -> None:
379
+ self.api = api.AsyncAPIResourceWithRawResponse(client.api)
380
+
381
+
382
+ class ArbiWithStreamedResponse:
383
+ def __init__(self, client: Arbi) -> None:
384
+ self.api = api.APIResourceWithStreamingResponse(client.api)
385
+
386
+
387
+ class AsyncArbiWithStreamedResponse:
388
+ def __init__(self, client: AsyncArbi) -> None:
389
+ self.api = api.AsyncAPIResourceWithStreamingResponse(client.api)
390
+
391
+
392
+ Client = Arbi
393
+
394
+ 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 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_V2 = pydantic.VERSION.startswith("2.")
21
+
22
+ # v1 re-exports
23
+ if TYPE_CHECKING:
24
+
25
+ def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
26
+ ...
27
+
28
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime: # noqa: ARG001
29
+ ...
30
+
31
+ def get_args(t: type[Any]) -> tuple[Any, ...]: # noqa: ARG001
32
+ ...
33
+
34
+ def is_union(tp: type[Any] | None) -> bool: # noqa: ARG001
35
+ ...
36
+
37
+ def get_origin(t: type[Any]) -> type[Any] | None: # noqa: ARG001
38
+ ...
39
+
40
+ def is_literal_type(type_: type[Any]) -> bool: # noqa: ARG001
41
+ ...
42
+
43
+ def is_typeddict(type_: type[Any]) -> bool: # noqa: ARG001
44
+ ...
45
+
46
+ else:
47
+ if PYDANTIC_V2:
48
+ from pydantic.v1.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.v1.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
56
+ else:
57
+ from pydantic.typing import (
58
+ get_args as get_args,
59
+ is_union as is_union,
60
+ get_origin as get_origin,
61
+ is_typeddict as is_typeddict,
62
+ is_literal_type as is_literal_type,
63
+ )
64
+ from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
65
+
66
+
67
+ # refactored config
68
+ if TYPE_CHECKING:
69
+ from pydantic import ConfigDict as ConfigDict
70
+ else:
71
+ if PYDANTIC_V2:
72
+ from pydantic import ConfigDict
73
+ else:
74
+ # TODO: provide an error message here?
75
+ ConfigDict = None
76
+
77
+
78
+ # renamed methods / properties
79
+ def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
80
+ if PYDANTIC_V2:
81
+ return model.model_validate(value)
82
+ else:
83
+ return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
84
+
85
+
86
+ def field_is_required(field: FieldInfo) -> bool:
87
+ if PYDANTIC_V2:
88
+ return field.is_required()
89
+ return field.required # type: ignore
90
+
91
+
92
+ def field_get_default(field: FieldInfo) -> Any:
93
+ value = field.get_default()
94
+ if PYDANTIC_V2:
95
+ from pydantic_core import PydanticUndefined
96
+
97
+ if value == PydanticUndefined:
98
+ return None
99
+ return value
100
+ return value
101
+
102
+
103
+ def field_outer_type(field: FieldInfo) -> Any:
104
+ if PYDANTIC_V2:
105
+ return field.annotation
106
+ return field.outer_type_ # type: ignore
107
+
108
+
109
+ def get_model_config(model: type[pydantic.BaseModel]) -> Any:
110
+ if PYDANTIC_V2:
111
+ return model.model_config
112
+ return model.__config__ # type: ignore
113
+
114
+
115
+ def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
116
+ if PYDANTIC_V2:
117
+ return model.model_fields
118
+ return model.__fields__ # type: ignore
119
+
120
+
121
+ def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
122
+ if PYDANTIC_V2:
123
+ return model.model_copy(deep=deep)
124
+ return model.copy(deep=deep) # type: ignore
125
+
126
+
127
+ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
128
+ if PYDANTIC_V2:
129
+ return model.model_dump_json(indent=indent)
130
+ return model.json(indent=indent) # type: ignore
131
+
132
+
133
+ def model_dump(
134
+ model: pydantic.BaseModel,
135
+ *,
136
+ exclude: IncEx | None = None,
137
+ exclude_unset: bool = False,
138
+ exclude_defaults: bool = False,
139
+ warnings: bool = True,
140
+ mode: Literal["json", "python"] = "python",
141
+ ) -> dict[str, Any]:
142
+ if PYDANTIC_V2 or hasattr(model, "model_dump"):
143
+ return model.model_dump(
144
+ mode=mode,
145
+ exclude=exclude,
146
+ exclude_unset=exclude_unset,
147
+ exclude_defaults=exclude_defaults,
148
+ # warnings are not supported in Pydantic v1
149
+ warnings=warnings if PYDANTIC_V2 else True,
150
+ )
151
+ return cast(
152
+ "dict[str, Any]",
153
+ model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
154
+ exclude=exclude,
155
+ exclude_unset=exclude_unset,
156
+ exclude_defaults=exclude_defaults,
157
+ ),
158
+ )
159
+
160
+
161
+ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
162
+ if PYDANTIC_V2:
163
+ return model.model_validate(data)
164
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
165
+
166
+
167
+ # generic models
168
+ if TYPE_CHECKING:
169
+
170
+ class GenericModel(pydantic.BaseModel): ...
171
+
172
+ else:
173
+ if PYDANTIC_V2:
174
+ # there no longer needs to be a distinction in v2 but
175
+ # we still have to create our own subclass to avoid
176
+ # inconsistent MRO ordering errors
177
+ class GenericModel(pydantic.BaseModel): ...
178
+
179
+ else:
180
+ import pydantic.generics
181
+
182
+ class GenericModel(pydantic.generics.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