relaxai 0.0.1__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 relaxai might be problematic. Click here for more details.

Files changed (50) hide show
  1. relaxai/__init__.py +90 -0
  2. relaxai/_base_client.py +1985 -0
  3. relaxai/_client.py +437 -0
  4. relaxai/_compat.py +219 -0
  5. relaxai/_constants.py +14 -0
  6. relaxai/_exceptions.py +108 -0
  7. relaxai/_files.py +123 -0
  8. relaxai/_models.py +805 -0
  9. relaxai/_qs.py +150 -0
  10. relaxai/_resource.py +43 -0
  11. relaxai/_response.py +830 -0
  12. relaxai/_streaming.py +333 -0
  13. relaxai/_types.py +219 -0
  14. relaxai/_utils/__init__.py +57 -0
  15. relaxai/_utils/_logs.py +25 -0
  16. relaxai/_utils/_proxy.py +65 -0
  17. relaxai/_utils/_reflection.py +42 -0
  18. relaxai/_utils/_resources_proxy.py +24 -0
  19. relaxai/_utils/_streams.py +12 -0
  20. relaxai/_utils/_sync.py +86 -0
  21. relaxai/_utils/_transform.py +447 -0
  22. relaxai/_utils/_typing.py +151 -0
  23. relaxai/_utils/_utils.py +422 -0
  24. relaxai/_version.py +4 -0
  25. relaxai/lib/.keep +4 -0
  26. relaxai/py.typed +0 -0
  27. relaxai/resources/__init__.py +61 -0
  28. relaxai/resources/chat.py +285 -0
  29. relaxai/resources/embeddings.py +189 -0
  30. relaxai/resources/health.py +134 -0
  31. relaxai/resources/models.py +214 -0
  32. relaxai/types/__init__.py +18 -0
  33. relaxai/types/chat_completion_message.py +54 -0
  34. relaxai/types/chat_completion_message_param.py +55 -0
  35. relaxai/types/chat_create_completion_params.py +106 -0
  36. relaxai/types/chat_create_completion_response.py +79 -0
  37. relaxai/types/content_filter_results.py +57 -0
  38. relaxai/types/embedding_create_params.py +19 -0
  39. relaxai/types/embedding_create_response.py +30 -0
  40. relaxai/types/function_call.py +13 -0
  41. relaxai/types/function_call_param.py +13 -0
  42. relaxai/types/function_definition_param.py +17 -0
  43. relaxai/types/health_check_response.py +7 -0
  44. relaxai/types/model.py +53 -0
  45. relaxai/types/model_list_response.py +16 -0
  46. relaxai/types/usage.py +33 -0
  47. relaxai-0.0.1.dist-info/METADATA +484 -0
  48. relaxai-0.0.1.dist-info/RECORD +50 -0
  49. relaxai-0.0.1.dist-info/WHEEL +4 -0
  50. relaxai-0.0.1.dist-info/licenses/LICENSE +201 -0
relaxai/_client.py ADDED
@@ -0,0 +1,437 @@
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
+ Headers,
17
+ Timeout,
18
+ NotGiven,
19
+ Transport,
20
+ ProxiesTypes,
21
+ RequestOptions,
22
+ )
23
+ from ._utils import is_given, get_async_library
24
+ from ._version import __version__
25
+ from .resources import chat, health, models, embeddings
26
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
27
+ from ._exceptions import APIStatusError
28
+ from ._base_client import (
29
+ DEFAULT_MAX_RETRIES,
30
+ SyncAPIClient,
31
+ AsyncAPIClient,
32
+ )
33
+
34
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Relaxai", "AsyncRelaxai", "Client", "AsyncClient"]
35
+
36
+
37
+ class Relaxai(SyncAPIClient):
38
+ chat: chat.ChatResource
39
+ embeddings: embeddings.EmbeddingsResource
40
+ health: health.HealthResource
41
+ models: models.ModelsResource
42
+ with_raw_response: RelaxaiWithRawResponse
43
+ with_streaming_response: RelaxaiWithStreamedResponse
44
+
45
+ # client options
46
+ api_key: str | None
47
+
48
+ def __init__(
49
+ self,
50
+ *,
51
+ api_key: str | None = None,
52
+ base_url: str | httpx.URL | None = None,
53
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
54
+ max_retries: int = DEFAULT_MAX_RETRIES,
55
+ default_headers: Mapping[str, str] | None = None,
56
+ default_query: Mapping[str, object] | None = None,
57
+ # Configure a custom httpx client.
58
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
59
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
60
+ http_client: httpx.Client | None = None,
61
+ # Enable or disable schema validation for data returned by the API.
62
+ # When enabled an error APIResponseValidationError is raised
63
+ # if the API responds with invalid data for the expected schema.
64
+ #
65
+ # This parameter may be removed or changed in the future.
66
+ # If you rely on this feature, please open a GitHub issue
67
+ # outlining your use-case to help us decide if it should be
68
+ # part of our public interface in the future.
69
+ _strict_response_validation: bool = False,
70
+ ) -> None:
71
+ """Construct a new synchronous Relaxai client instance.
72
+
73
+ This automatically infers the `api_key` argument from the `RELAXAI_API_KEY` environment variable if it is not provided.
74
+ """
75
+ if api_key is None:
76
+ api_key = os.environ.get("RELAXAI_API_KEY")
77
+ self.api_key = api_key
78
+
79
+ if base_url is None:
80
+ base_url = os.environ.get("RELAXAI_BASE_URL")
81
+ if base_url is None:
82
+ base_url = f"/"
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.chat = chat.ChatResource(self)
96
+ self.embeddings = embeddings.EmbeddingsResource(self)
97
+ self.health = health.HealthResource(self)
98
+ self.models = models.ModelsResource(self)
99
+ self.with_raw_response = RelaxaiWithRawResponse(self)
100
+ self.with_streaming_response = RelaxaiWithStreamedResponse(self)
101
+
102
+ @property
103
+ @override
104
+ def qs(self) -> Querystring:
105
+ return Querystring(array_format="comma")
106
+
107
+ @property
108
+ @override
109
+ def auth_headers(self) -> dict[str, str]:
110
+ api_key = self.api_key
111
+ if api_key is None:
112
+ return {}
113
+ return {"Authorization": f"Bearer {api_key}"}
114
+
115
+ @property
116
+ @override
117
+ def default_headers(self) -> dict[str, str | Omit]:
118
+ return {
119
+ **super().default_headers,
120
+ "X-Stainless-Async": "false",
121
+ **self._custom_headers,
122
+ }
123
+
124
+ @override
125
+ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
126
+ if self.api_key and headers.get("Authorization"):
127
+ return
128
+ if isinstance(custom_headers.get("Authorization"), Omit):
129
+ return
130
+
131
+ raise TypeError(
132
+ '"Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
133
+ )
134
+
135
+ def copy(
136
+ self,
137
+ *,
138
+ api_key: str | None = None,
139
+ base_url: str | httpx.URL | None = None,
140
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
141
+ http_client: httpx.Client | None = None,
142
+ max_retries: int | NotGiven = NOT_GIVEN,
143
+ default_headers: Mapping[str, str] | None = None,
144
+ set_default_headers: Mapping[str, str] | None = None,
145
+ default_query: Mapping[str, object] | None = None,
146
+ set_default_query: Mapping[str, object] | None = None,
147
+ _extra_kwargs: Mapping[str, Any] = {},
148
+ ) -> Self:
149
+ """
150
+ Create a new client instance re-using the same options given to the current client with optional overriding.
151
+ """
152
+ if default_headers is not None and set_default_headers is not None:
153
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
154
+
155
+ if default_query is not None and set_default_query is not None:
156
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
157
+
158
+ headers = self._custom_headers
159
+ if default_headers is not None:
160
+ headers = {**headers, **default_headers}
161
+ elif set_default_headers is not None:
162
+ headers = set_default_headers
163
+
164
+ params = self._custom_query
165
+ if default_query is not None:
166
+ params = {**params, **default_query}
167
+ elif set_default_query is not None:
168
+ params = set_default_query
169
+
170
+ http_client = http_client or self._client
171
+ return self.__class__(
172
+ api_key=api_key or self.api_key,
173
+ base_url=base_url or self.base_url,
174
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
175
+ http_client=http_client,
176
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
177
+ default_headers=headers,
178
+ default_query=params,
179
+ **_extra_kwargs,
180
+ )
181
+
182
+ # Alias for `copy` for nicer inline usage, e.g.
183
+ # client.with_options(timeout=10).foo.create(...)
184
+ with_options = copy
185
+
186
+ @override
187
+ def _make_status_error(
188
+ self,
189
+ err_msg: str,
190
+ *,
191
+ body: object,
192
+ response: httpx.Response,
193
+ ) -> APIStatusError:
194
+ if response.status_code == 400:
195
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
196
+
197
+ if response.status_code == 401:
198
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
199
+
200
+ if response.status_code == 403:
201
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
202
+
203
+ if response.status_code == 404:
204
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
205
+
206
+ if response.status_code == 409:
207
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
208
+
209
+ if response.status_code == 422:
210
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
211
+
212
+ if response.status_code == 429:
213
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
214
+
215
+ if response.status_code >= 500:
216
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
217
+ return APIStatusError(err_msg, response=response, body=body)
218
+
219
+
220
+ class AsyncRelaxai(AsyncAPIClient):
221
+ chat: chat.AsyncChatResource
222
+ embeddings: embeddings.AsyncEmbeddingsResource
223
+ health: health.AsyncHealthResource
224
+ models: models.AsyncModelsResource
225
+ with_raw_response: AsyncRelaxaiWithRawResponse
226
+ with_streaming_response: AsyncRelaxaiWithStreamedResponse
227
+
228
+ # client options
229
+ api_key: str | None
230
+
231
+ def __init__(
232
+ self,
233
+ *,
234
+ api_key: str | None = None,
235
+ base_url: str | httpx.URL | None = None,
236
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
237
+ max_retries: int = DEFAULT_MAX_RETRIES,
238
+ default_headers: Mapping[str, str] | None = None,
239
+ default_query: Mapping[str, object] | None = None,
240
+ # Configure a custom httpx client.
241
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
242
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
243
+ http_client: httpx.AsyncClient | None = None,
244
+ # Enable or disable schema validation for data returned by the API.
245
+ # When enabled an error APIResponseValidationError is raised
246
+ # if the API responds with invalid data for the expected schema.
247
+ #
248
+ # This parameter may be removed or changed in the future.
249
+ # If you rely on this feature, please open a GitHub issue
250
+ # outlining your use-case to help us decide if it should be
251
+ # part of our public interface in the future.
252
+ _strict_response_validation: bool = False,
253
+ ) -> None:
254
+ """Construct a new async AsyncRelaxai client instance.
255
+
256
+ This automatically infers the `api_key` argument from the `RELAXAI_API_KEY` environment variable if it is not provided.
257
+ """
258
+ if api_key is None:
259
+ api_key = os.environ.get("RELAXAI_API_KEY")
260
+ self.api_key = api_key
261
+
262
+ if base_url is None:
263
+ base_url = os.environ.get("RELAXAI_BASE_URL")
264
+ if base_url is None:
265
+ base_url = f"/"
266
+
267
+ super().__init__(
268
+ version=__version__,
269
+ base_url=base_url,
270
+ max_retries=max_retries,
271
+ timeout=timeout,
272
+ http_client=http_client,
273
+ custom_headers=default_headers,
274
+ custom_query=default_query,
275
+ _strict_response_validation=_strict_response_validation,
276
+ )
277
+
278
+ self.chat = chat.AsyncChatResource(self)
279
+ self.embeddings = embeddings.AsyncEmbeddingsResource(self)
280
+ self.health = health.AsyncHealthResource(self)
281
+ self.models = models.AsyncModelsResource(self)
282
+ self.with_raw_response = AsyncRelaxaiWithRawResponse(self)
283
+ self.with_streaming_response = AsyncRelaxaiWithStreamedResponse(self)
284
+
285
+ @property
286
+ @override
287
+ def qs(self) -> Querystring:
288
+ return Querystring(array_format="comma")
289
+
290
+ @property
291
+ @override
292
+ def auth_headers(self) -> dict[str, str]:
293
+ api_key = self.api_key
294
+ if api_key is None:
295
+ return {}
296
+ return {"Authorization": f"Bearer {api_key}"}
297
+
298
+ @property
299
+ @override
300
+ def default_headers(self) -> dict[str, str | Omit]:
301
+ return {
302
+ **super().default_headers,
303
+ "X-Stainless-Async": f"async:{get_async_library()}",
304
+ **self._custom_headers,
305
+ }
306
+
307
+ @override
308
+ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
309
+ if self.api_key and headers.get("Authorization"):
310
+ return
311
+ if isinstance(custom_headers.get("Authorization"), Omit):
312
+ return
313
+
314
+ raise TypeError(
315
+ '"Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
316
+ )
317
+
318
+ def copy(
319
+ self,
320
+ *,
321
+ api_key: str | None = None,
322
+ base_url: str | httpx.URL | None = None,
323
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
324
+ http_client: httpx.AsyncClient | None = None,
325
+ max_retries: int | NotGiven = NOT_GIVEN,
326
+ default_headers: Mapping[str, str] | None = None,
327
+ set_default_headers: Mapping[str, str] | None = None,
328
+ default_query: Mapping[str, object] | None = None,
329
+ set_default_query: Mapping[str, object] | None = None,
330
+ _extra_kwargs: Mapping[str, Any] = {},
331
+ ) -> Self:
332
+ """
333
+ Create a new client instance re-using the same options given to the current client with optional overriding.
334
+ """
335
+ if default_headers is not None and set_default_headers is not None:
336
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
337
+
338
+ if default_query is not None and set_default_query is not None:
339
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
340
+
341
+ headers = self._custom_headers
342
+ if default_headers is not None:
343
+ headers = {**headers, **default_headers}
344
+ elif set_default_headers is not None:
345
+ headers = set_default_headers
346
+
347
+ params = self._custom_query
348
+ if default_query is not None:
349
+ params = {**params, **default_query}
350
+ elif set_default_query is not None:
351
+ params = set_default_query
352
+
353
+ http_client = http_client or self._client
354
+ return self.__class__(
355
+ api_key=api_key or self.api_key,
356
+ base_url=base_url or self.base_url,
357
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
358
+ http_client=http_client,
359
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
360
+ default_headers=headers,
361
+ default_query=params,
362
+ **_extra_kwargs,
363
+ )
364
+
365
+ # Alias for `copy` for nicer inline usage, e.g.
366
+ # client.with_options(timeout=10).foo.create(...)
367
+ with_options = copy
368
+
369
+ @override
370
+ def _make_status_error(
371
+ self,
372
+ err_msg: str,
373
+ *,
374
+ body: object,
375
+ response: httpx.Response,
376
+ ) -> APIStatusError:
377
+ if response.status_code == 400:
378
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
379
+
380
+ if response.status_code == 401:
381
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
382
+
383
+ if response.status_code == 403:
384
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
385
+
386
+ if response.status_code == 404:
387
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
388
+
389
+ if response.status_code == 409:
390
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
391
+
392
+ if response.status_code == 422:
393
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
394
+
395
+ if response.status_code == 429:
396
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
397
+
398
+ if response.status_code >= 500:
399
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
400
+ return APIStatusError(err_msg, response=response, body=body)
401
+
402
+
403
+ class RelaxaiWithRawResponse:
404
+ def __init__(self, client: Relaxai) -> None:
405
+ self.chat = chat.ChatResourceWithRawResponse(client.chat)
406
+ self.embeddings = embeddings.EmbeddingsResourceWithRawResponse(client.embeddings)
407
+ self.health = health.HealthResourceWithRawResponse(client.health)
408
+ self.models = models.ModelsResourceWithRawResponse(client.models)
409
+
410
+
411
+ class AsyncRelaxaiWithRawResponse:
412
+ def __init__(self, client: AsyncRelaxai) -> None:
413
+ self.chat = chat.AsyncChatResourceWithRawResponse(client.chat)
414
+ self.embeddings = embeddings.AsyncEmbeddingsResourceWithRawResponse(client.embeddings)
415
+ self.health = health.AsyncHealthResourceWithRawResponse(client.health)
416
+ self.models = models.AsyncModelsResourceWithRawResponse(client.models)
417
+
418
+
419
+ class RelaxaiWithStreamedResponse:
420
+ def __init__(self, client: Relaxai) -> None:
421
+ self.chat = chat.ChatResourceWithStreamingResponse(client.chat)
422
+ self.embeddings = embeddings.EmbeddingsResourceWithStreamingResponse(client.embeddings)
423
+ self.health = health.HealthResourceWithStreamingResponse(client.health)
424
+ self.models = models.ModelsResourceWithStreamingResponse(client.models)
425
+
426
+
427
+ class AsyncRelaxaiWithStreamedResponse:
428
+ def __init__(self, client: AsyncRelaxai) -> None:
429
+ self.chat = chat.AsyncChatResourceWithStreamingResponse(client.chat)
430
+ self.embeddings = embeddings.AsyncEmbeddingsResourceWithStreamingResponse(client.embeddings)
431
+ self.health = health.AsyncHealthResourceWithStreamingResponse(client.health)
432
+ self.models = models.AsyncModelsResourceWithStreamingResponse(client.models)
433
+
434
+
435
+ Client = Relaxai
436
+
437
+ AsyncClient = AsyncRelaxai
relaxai/_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
relaxai/_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