worqhat 1.0__py3-none-any.whl → 3.0.0a4__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 (60) hide show
  1. worqhat/__init__.py +90 -10
  2. worqhat/_base_client.py +1992 -0
  3. worqhat/_client.py +467 -0
  4. worqhat/_compat.py +219 -0
  5. worqhat/_constants.py +14 -0
  6. worqhat/_exceptions.py +108 -0
  7. worqhat/_files.py +123 -0
  8. worqhat/_models.py +829 -0
  9. worqhat/_qs.py +150 -0
  10. worqhat/_resource.py +43 -0
  11. worqhat/_response.py +830 -0
  12. worqhat/_streaming.py +333 -0
  13. worqhat/_types.py +219 -0
  14. worqhat/_utils/__init__.py +57 -0
  15. worqhat/_utils/_logs.py +25 -0
  16. worqhat/_utils/_proxy.py +65 -0
  17. worqhat/_utils/_reflection.py +42 -0
  18. worqhat/_utils/_resources_proxy.py +24 -0
  19. worqhat/_utils/_streams.py +12 -0
  20. worqhat/_utils/_sync.py +86 -0
  21. worqhat/_utils/_transform.py +447 -0
  22. worqhat/_utils/_typing.py +151 -0
  23. worqhat/_utils/_utils.py +422 -0
  24. worqhat/_version.py +4 -0
  25. worqhat/lib/.keep +4 -0
  26. worqhat/resources/__init__.py +33 -0
  27. worqhat/resources/flows.py +223 -0
  28. worqhat/resources/health.py +143 -0
  29. worqhat/types/__init__.py +8 -0
  30. worqhat/types/flow_retrieve_metrics_params.py +25 -0
  31. worqhat/types/flow_retrieve_metrics_response.py +55 -0
  32. worqhat/types/health_check_response.py +33 -0
  33. worqhat/types/retrieve_server_info_response.py +15 -0
  34. worqhat-3.0.0a4.dist-info/METADATA +398 -0
  35. worqhat-3.0.0a4.dist-info/RECORD +38 -0
  36. {worqhat-1.0.dist-info → worqhat-3.0.0a4.dist-info}/WHEEL +1 -2
  37. {worqhat-1.0.dist-info → worqhat-3.0.0a4.dist-info/licenses}/LICENSE +201 -201
  38. worqhat/ai_models/__init__.py +0 -9
  39. worqhat/ai_models/ai_search.py +0 -41
  40. worqhat/ai_models/content_mod.py +0 -44
  41. worqhat/ai_models/image_analysis.py +0 -94
  42. worqhat/ai_models/image_gen.py +0 -281
  43. worqhat/ai_models/model_train.py +0 -45
  44. worqhat/ai_models/text_extract.py +0 -83
  45. worqhat/ai_models/text_gen.py +0 -177
  46. worqhat/database_management/Edit.py +0 -140
  47. worqhat/database_management/Read.py +0 -152
  48. worqhat/database_management/__init__.py +0 -5
  49. worqhat/database_management/collection.py +0 -25
  50. worqhat/test/test_ai_search.py +0 -38
  51. worqhat/test/test_content_mod.py +0 -39
  52. worqhat/test/test_image_analysis.py +0 -52
  53. worqhat/test/test_image_gen.py +0 -0
  54. worqhat/test/test_model_train.py +0 -52
  55. worqhat/test/test_text_extract.py +0 -65
  56. worqhat/test/test_text_gen.py +0 -66
  57. worqhat-1.0.dist-info/METADATA +0 -127
  58. worqhat-1.0.dist-info/RECORD +0 -26
  59. worqhat-1.0.dist-info/top_level.txt +0 -1
  60. /worqhat/{test/__init__.py → py.typed} +0 -0
worqhat/_client.py ADDED
@@ -0,0 +1,467 @@
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
+ Body,
16
+ Omit,
17
+ Query,
18
+ Headers,
19
+ Timeout,
20
+ NotGiven,
21
+ Transport,
22
+ ProxiesTypes,
23
+ RequestOptions,
24
+ )
25
+ from ._utils import is_given, get_async_library
26
+ from ._version import __version__
27
+ from ._response import (
28
+ to_raw_response_wrapper,
29
+ to_streamed_response_wrapper,
30
+ async_to_raw_response_wrapper,
31
+ async_to_streamed_response_wrapper,
32
+ )
33
+ from .resources import flows, health
34
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
35
+ from ._exceptions import WorqhatError, APIStatusError
36
+ from ._base_client import (
37
+ DEFAULT_MAX_RETRIES,
38
+ SyncAPIClient,
39
+ AsyncAPIClient,
40
+ make_request_options,
41
+ )
42
+ from .types.retrieve_server_info_response import RetrieveServerInfoResponse
43
+
44
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Worqhat", "AsyncWorqhat", "Client", "AsyncClient"]
45
+
46
+
47
+ class Worqhat(SyncAPIClient):
48
+ health: health.HealthResource
49
+ flows: flows.FlowsResource
50
+ with_raw_response: WorqhatWithRawResponse
51
+ with_streaming_response: WorqhatWithStreamedResponse
52
+
53
+ # client options
54
+ api_key: str
55
+
56
+ def __init__(
57
+ self,
58
+ *,
59
+ api_key: str | None = None,
60
+ base_url: str | httpx.URL | None = None,
61
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
62
+ max_retries: int = DEFAULT_MAX_RETRIES,
63
+ default_headers: Mapping[str, str] | None = None,
64
+ default_query: Mapping[str, object] | None = None,
65
+ # Configure a custom httpx client.
66
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
67
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
68
+ http_client: httpx.Client | None = None,
69
+ # Enable or disable schema validation for data returned by the API.
70
+ # When enabled an error APIResponseValidationError is raised
71
+ # if the API responds with invalid data for the expected schema.
72
+ #
73
+ # This parameter may be removed or changed in the future.
74
+ # If you rely on this feature, please open a GitHub issue
75
+ # outlining your use-case to help us decide if it should be
76
+ # part of our public interface in the future.
77
+ _strict_response_validation: bool = False,
78
+ ) -> None:
79
+ """Construct a new synchronous Worqhat client instance.
80
+
81
+ This automatically infers the `api_key` argument from the `WORQHAT_API_KEY` environment variable if it is not provided.
82
+ """
83
+ if api_key is None:
84
+ api_key = os.environ.get("WORQHAT_API_KEY")
85
+ if api_key is None:
86
+ raise WorqhatError(
87
+ "The api_key client option must be set either by passing api_key to the client or by setting the WORQHAT_API_KEY environment variable"
88
+ )
89
+ self.api_key = api_key
90
+
91
+ if base_url is None:
92
+ base_url = os.environ.get("WORQHAT_BASE_URL")
93
+ if base_url is None:
94
+ base_url = f"https://api.worqhat.com"
95
+
96
+ super().__init__(
97
+ version=__version__,
98
+ base_url=base_url,
99
+ max_retries=max_retries,
100
+ timeout=timeout,
101
+ http_client=http_client,
102
+ custom_headers=default_headers,
103
+ custom_query=default_query,
104
+ _strict_response_validation=_strict_response_validation,
105
+ )
106
+
107
+ self.health = health.HealthResource(self)
108
+ self.flows = flows.FlowsResource(self)
109
+ self.with_raw_response = WorqhatWithRawResponse(self)
110
+ self.with_streaming_response = WorqhatWithStreamedResponse(self)
111
+
112
+ @property
113
+ @override
114
+ def qs(self) -> Querystring:
115
+ return Querystring(array_format="comma")
116
+
117
+ @property
118
+ @override
119
+ def auth_headers(self) -> dict[str, str]:
120
+ api_key = self.api_key
121
+ return {"Authorization": api_key}
122
+
123
+ @property
124
+ @override
125
+ def default_headers(self) -> dict[str, str | Omit]:
126
+ return {
127
+ **super().default_headers,
128
+ "X-Stainless-Async": "false",
129
+ **self._custom_headers,
130
+ }
131
+
132
+ def copy(
133
+ self,
134
+ *,
135
+ api_key: str | None = None,
136
+ base_url: str | httpx.URL | None = None,
137
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
138
+ http_client: httpx.Client | None = None,
139
+ max_retries: int | NotGiven = NOT_GIVEN,
140
+ default_headers: Mapping[str, str] | None = None,
141
+ set_default_headers: Mapping[str, str] | None = None,
142
+ default_query: Mapping[str, object] | None = None,
143
+ set_default_query: Mapping[str, object] | None = None,
144
+ _extra_kwargs: Mapping[str, Any] = {},
145
+ ) -> Self:
146
+ """
147
+ Create a new client instance re-using the same options given to the current client with optional overriding.
148
+ """
149
+ if default_headers is not None and set_default_headers is not None:
150
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
151
+
152
+ if default_query is not None and set_default_query is not None:
153
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
154
+
155
+ headers = self._custom_headers
156
+ if default_headers is not None:
157
+ headers = {**headers, **default_headers}
158
+ elif set_default_headers is not None:
159
+ headers = set_default_headers
160
+
161
+ params = self._custom_query
162
+ if default_query is not None:
163
+ params = {**params, **default_query}
164
+ elif set_default_query is not None:
165
+ params = set_default_query
166
+
167
+ http_client = http_client or self._client
168
+ return self.__class__(
169
+ api_key=api_key or self.api_key,
170
+ base_url=base_url or self.base_url,
171
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
172
+ http_client=http_client,
173
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
174
+ default_headers=headers,
175
+ default_query=params,
176
+ **_extra_kwargs,
177
+ )
178
+
179
+ # Alias for `copy` for nicer inline usage, e.g.
180
+ # client.with_options(timeout=10).foo.create(...)
181
+ with_options = copy
182
+
183
+ def retrieve_server_info(
184
+ self,
185
+ *,
186
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
187
+ # The extra values given here take precedence over values defined on the client or passed to this method.
188
+ extra_headers: Headers | None = None,
189
+ extra_query: Query | None = None,
190
+ extra_body: Body | None = None,
191
+ timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
192
+ ) -> RetrieveServerInfoResponse:
193
+ """Get basic server information and status"""
194
+ return self.get(
195
+ "/",
196
+ options=make_request_options(
197
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
198
+ ),
199
+ cast_to=RetrieveServerInfoResponse,
200
+ )
201
+
202
+ @override
203
+ def _make_status_error(
204
+ self,
205
+ err_msg: str,
206
+ *,
207
+ body: object,
208
+ response: httpx.Response,
209
+ ) -> APIStatusError:
210
+ if response.status_code == 400:
211
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
212
+
213
+ if response.status_code == 401:
214
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
215
+
216
+ if response.status_code == 403:
217
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
218
+
219
+ if response.status_code == 404:
220
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
221
+
222
+ if response.status_code == 409:
223
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
224
+
225
+ if response.status_code == 422:
226
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
227
+
228
+ if response.status_code == 429:
229
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
230
+
231
+ if response.status_code >= 500:
232
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
233
+ return APIStatusError(err_msg, response=response, body=body)
234
+
235
+
236
+ class AsyncWorqhat(AsyncAPIClient):
237
+ health: health.AsyncHealthResource
238
+ flows: flows.AsyncFlowsResource
239
+ with_raw_response: AsyncWorqhatWithRawResponse
240
+ with_streaming_response: AsyncWorqhatWithStreamedResponse
241
+
242
+ # client options
243
+ api_key: str
244
+
245
+ def __init__(
246
+ self,
247
+ *,
248
+ api_key: str | None = None,
249
+ base_url: str | httpx.URL | None = None,
250
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
251
+ max_retries: int = DEFAULT_MAX_RETRIES,
252
+ default_headers: Mapping[str, str] | None = None,
253
+ default_query: Mapping[str, object] | None = None,
254
+ # Configure a custom httpx client.
255
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
256
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
257
+ http_client: httpx.AsyncClient | None = None,
258
+ # Enable or disable schema validation for data returned by the API.
259
+ # When enabled an error APIResponseValidationError is raised
260
+ # if the API responds with invalid data for the expected schema.
261
+ #
262
+ # This parameter may be removed or changed in the future.
263
+ # If you rely on this feature, please open a GitHub issue
264
+ # outlining your use-case to help us decide if it should be
265
+ # part of our public interface in the future.
266
+ _strict_response_validation: bool = False,
267
+ ) -> None:
268
+ """Construct a new async AsyncWorqhat client instance.
269
+
270
+ This automatically infers the `api_key` argument from the `WORQHAT_API_KEY` environment variable if it is not provided.
271
+ """
272
+ if api_key is None:
273
+ api_key = os.environ.get("WORQHAT_API_KEY")
274
+ if api_key is None:
275
+ raise WorqhatError(
276
+ "The api_key client option must be set either by passing api_key to the client or by setting the WORQHAT_API_KEY environment variable"
277
+ )
278
+ self.api_key = api_key
279
+
280
+ if base_url is None:
281
+ base_url = os.environ.get("WORQHAT_BASE_URL")
282
+ if base_url is None:
283
+ base_url = f"https://api.worqhat.com"
284
+
285
+ super().__init__(
286
+ version=__version__,
287
+ base_url=base_url,
288
+ max_retries=max_retries,
289
+ timeout=timeout,
290
+ http_client=http_client,
291
+ custom_headers=default_headers,
292
+ custom_query=default_query,
293
+ _strict_response_validation=_strict_response_validation,
294
+ )
295
+
296
+ self.health = health.AsyncHealthResource(self)
297
+ self.flows = flows.AsyncFlowsResource(self)
298
+ self.with_raw_response = AsyncWorqhatWithRawResponse(self)
299
+ self.with_streaming_response = AsyncWorqhatWithStreamedResponse(self)
300
+
301
+ @property
302
+ @override
303
+ def qs(self) -> Querystring:
304
+ return Querystring(array_format="comma")
305
+
306
+ @property
307
+ @override
308
+ def auth_headers(self) -> dict[str, str]:
309
+ api_key = self.api_key
310
+ return {"Authorization": api_key}
311
+
312
+ @property
313
+ @override
314
+ def default_headers(self) -> dict[str, str | Omit]:
315
+ return {
316
+ **super().default_headers,
317
+ "X-Stainless-Async": f"async:{get_async_library()}",
318
+ **self._custom_headers,
319
+ }
320
+
321
+ def copy(
322
+ self,
323
+ *,
324
+ api_key: str | None = None,
325
+ base_url: str | httpx.URL | None = None,
326
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
327
+ http_client: httpx.AsyncClient | None = None,
328
+ max_retries: int | NotGiven = NOT_GIVEN,
329
+ default_headers: Mapping[str, str] | None = None,
330
+ set_default_headers: Mapping[str, str] | None = None,
331
+ default_query: Mapping[str, object] | None = None,
332
+ set_default_query: Mapping[str, object] | None = None,
333
+ _extra_kwargs: Mapping[str, Any] = {},
334
+ ) -> Self:
335
+ """
336
+ Create a new client instance re-using the same options given to the current client with optional overriding.
337
+ """
338
+ if default_headers is not None and set_default_headers is not None:
339
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
340
+
341
+ if default_query is not None and set_default_query is not None:
342
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
343
+
344
+ headers = self._custom_headers
345
+ if default_headers is not None:
346
+ headers = {**headers, **default_headers}
347
+ elif set_default_headers is not None:
348
+ headers = set_default_headers
349
+
350
+ params = self._custom_query
351
+ if default_query is not None:
352
+ params = {**params, **default_query}
353
+ elif set_default_query is not None:
354
+ params = set_default_query
355
+
356
+ http_client = http_client or self._client
357
+ return self.__class__(
358
+ api_key=api_key or self.api_key,
359
+ base_url=base_url or self.base_url,
360
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
361
+ http_client=http_client,
362
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
363
+ default_headers=headers,
364
+ default_query=params,
365
+ **_extra_kwargs,
366
+ )
367
+
368
+ # Alias for `copy` for nicer inline usage, e.g.
369
+ # client.with_options(timeout=10).foo.create(...)
370
+ with_options = copy
371
+
372
+ async def retrieve_server_info(
373
+ self,
374
+ *,
375
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
376
+ # The extra values given here take precedence over values defined on the client or passed to this method.
377
+ extra_headers: Headers | None = None,
378
+ extra_query: Query | None = None,
379
+ extra_body: Body | None = None,
380
+ timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
381
+ ) -> RetrieveServerInfoResponse:
382
+ """Get basic server information and status"""
383
+ return await self.get(
384
+ "/",
385
+ options=make_request_options(
386
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
387
+ ),
388
+ cast_to=RetrieveServerInfoResponse,
389
+ )
390
+
391
+ @override
392
+ def _make_status_error(
393
+ self,
394
+ err_msg: str,
395
+ *,
396
+ body: object,
397
+ response: httpx.Response,
398
+ ) -> APIStatusError:
399
+ if response.status_code == 400:
400
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
401
+
402
+ if response.status_code == 401:
403
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
404
+
405
+ if response.status_code == 403:
406
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
407
+
408
+ if response.status_code == 404:
409
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
410
+
411
+ if response.status_code == 409:
412
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
413
+
414
+ if response.status_code == 422:
415
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
416
+
417
+ if response.status_code == 429:
418
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
419
+
420
+ if response.status_code >= 500:
421
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
422
+ return APIStatusError(err_msg, response=response, body=body)
423
+
424
+
425
+ class WorqhatWithRawResponse:
426
+ def __init__(self, client: Worqhat) -> None:
427
+ self.health = health.HealthResourceWithRawResponse(client.health)
428
+ self.flows = flows.FlowsResourceWithRawResponse(client.flows)
429
+
430
+ self.retrieve_server_info = to_raw_response_wrapper(
431
+ client.retrieve_server_info,
432
+ )
433
+
434
+
435
+ class AsyncWorqhatWithRawResponse:
436
+ def __init__(self, client: AsyncWorqhat) -> None:
437
+ self.health = health.AsyncHealthResourceWithRawResponse(client.health)
438
+ self.flows = flows.AsyncFlowsResourceWithRawResponse(client.flows)
439
+
440
+ self.retrieve_server_info = async_to_raw_response_wrapper(
441
+ client.retrieve_server_info,
442
+ )
443
+
444
+
445
+ class WorqhatWithStreamedResponse:
446
+ def __init__(self, client: Worqhat) -> None:
447
+ self.health = health.HealthResourceWithStreamingResponse(client.health)
448
+ self.flows = flows.FlowsResourceWithStreamingResponse(client.flows)
449
+
450
+ self.retrieve_server_info = to_streamed_response_wrapper(
451
+ client.retrieve_server_info,
452
+ )
453
+
454
+
455
+ class AsyncWorqhatWithStreamedResponse:
456
+ def __init__(self, client: AsyncWorqhat) -> None:
457
+ self.health = health.AsyncHealthResourceWithStreamingResponse(client.health)
458
+ self.flows = flows.AsyncFlowsResourceWithStreamingResponse(client.flows)
459
+
460
+ self.retrieve_server_info = async_to_streamed_response_wrapper(
461
+ client.retrieve_server_info,
462
+ )
463
+
464
+
465
+ Client = Worqhat
466
+
467
+ AsyncClient = AsyncWorqhat
worqhat/_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
worqhat/_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