usecortex-ai 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.
Files changed (89) hide show
  1. cortex_ai/__init__.py +103 -0
  2. cortex_ai/client.py +244 -0
  3. cortex_ai/core/__init__.py +52 -0
  4. cortex_ai/core/api_error.py +23 -0
  5. cortex_ai/core/client_wrapper.py +84 -0
  6. cortex_ai/core/datetime_utils.py +28 -0
  7. cortex_ai/core/file.py +67 -0
  8. cortex_ai/core/force_multipart.py +18 -0
  9. cortex_ai/core/http_client.py +543 -0
  10. cortex_ai/core/http_response.py +55 -0
  11. cortex_ai/core/jsonable_encoder.py +100 -0
  12. cortex_ai/core/pydantic_utilities.py +258 -0
  13. cortex_ai/core/query_encoder.py +58 -0
  14. cortex_ai/core/remove_none_from_dict.py +11 -0
  15. cortex_ai/core/request_options.py +35 -0
  16. cortex_ai/core/serialization.py +276 -0
  17. cortex_ai/embeddings/__init__.py +4 -0
  18. cortex_ai/embeddings/client.py +442 -0
  19. cortex_ai/embeddings/raw_client.py +1153 -0
  20. cortex_ai/environment.py +7 -0
  21. cortex_ai/errors/__init__.py +21 -0
  22. cortex_ai/errors/bad_request_error.py +11 -0
  23. cortex_ai/errors/forbidden_error.py +11 -0
  24. cortex_ai/errors/internal_server_error.py +11 -0
  25. cortex_ai/errors/not_found_error.py +11 -0
  26. cortex_ai/errors/service_unavailable_error.py +11 -0
  27. cortex_ai/errors/unauthorized_error.py +11 -0
  28. cortex_ai/errors/unprocessable_entity_error.py +10 -0
  29. cortex_ai/fetch/__init__.py +4 -0
  30. cortex_ai/fetch/client.py +143 -0
  31. cortex_ai/fetch/raw_client.py +310 -0
  32. cortex_ai/raw_client.py +90 -0
  33. cortex_ai/search/__init__.py +7 -0
  34. cortex_ai/search/client.py +536 -0
  35. cortex_ai/search/raw_client.py +1064 -0
  36. cortex_ai/search/types/__init__.py +7 -0
  37. cortex_ai/search/types/alpha.py +5 -0
  38. cortex_ai/sources/__init__.py +4 -0
  39. cortex_ai/sources/client.py +187 -0
  40. cortex_ai/sources/raw_client.py +532 -0
  41. cortex_ai/tenant/__init__.py +4 -0
  42. cortex_ai/tenant/client.py +120 -0
  43. cortex_ai/tenant/raw_client.py +283 -0
  44. cortex_ai/types/__init__.py +69 -0
  45. cortex_ai/types/actual_error_response.py +20 -0
  46. cortex_ai/types/app_sources_upload_data.py +22 -0
  47. cortex_ai/types/attachment_model.py +26 -0
  48. cortex_ai/types/batch_upload_data.py +22 -0
  49. cortex_ai/types/bm_25_operator_type.py +5 -0
  50. cortex_ai/types/content_model.py +26 -0
  51. cortex_ai/types/delete_memory_request.py +21 -0
  52. cortex_ai/types/embeddings_create_collection_data.py +22 -0
  53. cortex_ai/types/embeddings_delete_data.py +22 -0
  54. cortex_ai/types/embeddings_get_data.py +22 -0
  55. cortex_ai/types/embeddings_search_data.py +22 -0
  56. cortex_ai/types/error_response.py +22 -0
  57. cortex_ai/types/extended_context.py +20 -0
  58. cortex_ai/types/fetch_content_data.py +23 -0
  59. cortex_ai/types/file_upload_result.py +20 -0
  60. cortex_ai/types/full_text_search_data.py +22 -0
  61. cortex_ai/types/http_validation_error.py +20 -0
  62. cortex_ai/types/list_sources_response.py +22 -0
  63. cortex_ai/types/markdown_upload_request.py +21 -0
  64. cortex_ai/types/processing_status.py +22 -0
  65. cortex_ai/types/related_chunk.py +22 -0
  66. cortex_ai/types/search_chunk.py +34 -0
  67. cortex_ai/types/search_data.py +22 -0
  68. cortex_ai/types/single_upload_data.py +21 -0
  69. cortex_ai/types/source.py +32 -0
  70. cortex_ai/types/source_content.py +26 -0
  71. cortex_ai/types/source_model.py +32 -0
  72. cortex_ai/types/tenant_create_data.py +22 -0
  73. cortex_ai/types/tenant_stats.py +23 -0
  74. cortex_ai/types/validation_error.py +22 -0
  75. cortex_ai/types/validation_error_loc_item.py +5 -0
  76. cortex_ai/upload/__init__.py +4 -0
  77. cortex_ai/upload/client.py +1572 -0
  78. cortex_ai/upload/raw_client.py +4202 -0
  79. cortex_ai/user/__init__.py +4 -0
  80. cortex_ai/user/client.py +125 -0
  81. cortex_ai/user/raw_client.py +300 -0
  82. cortex_ai/user_memory/__init__.py +4 -0
  83. cortex_ai/user_memory/client.py +443 -0
  84. cortex_ai/user_memory/raw_client.py +651 -0
  85. usecortex_ai-0.1.0.dist-info/METADATA +136 -0
  86. usecortex_ai-0.1.0.dist-info/RECORD +89 -0
  87. usecortex_ai-0.1.0.dist-info/WHEEL +5 -0
  88. usecortex_ai-0.1.0.dist-info/licenses/LICENSE +22 -0
  89. usecortex_ai-0.1.0.dist-info/top_level.txt +1 -0
cortex_ai/__init__.py ADDED
@@ -0,0 +1,103 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ from .types import (
6
+ ActualErrorResponse,
7
+ AppSourcesUploadData,
8
+ AttachmentModel,
9
+ BatchUploadData,
10
+ Bm25OperatorType,
11
+ ContentModel,
12
+ DeleteMemoryRequest,
13
+ EmbeddingsCreateCollectionData,
14
+ EmbeddingsDeleteData,
15
+ EmbeddingsGetData,
16
+ EmbeddingsSearchData,
17
+ ErrorResponse,
18
+ ExtendedContext,
19
+ FetchContentData,
20
+ FileUploadResult,
21
+ FullTextSearchData,
22
+ HttpValidationError,
23
+ ListSourcesResponse,
24
+ MarkdownUploadRequest,
25
+ ProcessingStatus,
26
+ RelatedChunk,
27
+ SearchChunk,
28
+ SearchData,
29
+ SingleUploadData,
30
+ Source,
31
+ SourceContent,
32
+ SourceModel,
33
+ TenantCreateData,
34
+ TenantStats,
35
+ ValidationError,
36
+ ValidationErrorLocItem,
37
+ )
38
+ from .errors import (
39
+ BadRequestError,
40
+ ForbiddenError,
41
+ InternalServerError,
42
+ NotFoundError,
43
+ ServiceUnavailableError,
44
+ UnauthorizedError,
45
+ UnprocessableEntityError,
46
+ )
47
+ from . import embeddings, fetch, search, sources, tenant, upload, user, user_memory
48
+ from .client import AsyncCortexAI, CortexAI
49
+ from .environment import CortexAIEnvironment
50
+ from .search import Alpha
51
+
52
+ __all__ = [
53
+ "ActualErrorResponse",
54
+ "Alpha",
55
+ "AppSourcesUploadData",
56
+ "AsyncCortexAI",
57
+ "AttachmentModel",
58
+ "BadRequestError",
59
+ "BatchUploadData",
60
+ "Bm25OperatorType",
61
+ "ContentModel",
62
+ "CortexAI",
63
+ "CortexAIEnvironment",
64
+ "DeleteMemoryRequest",
65
+ "EmbeddingsCreateCollectionData",
66
+ "EmbeddingsDeleteData",
67
+ "EmbeddingsGetData",
68
+ "EmbeddingsSearchData",
69
+ "ErrorResponse",
70
+ "ExtendedContext",
71
+ "FetchContentData",
72
+ "FileUploadResult",
73
+ "ForbiddenError",
74
+ "FullTextSearchData",
75
+ "HttpValidationError",
76
+ "InternalServerError",
77
+ "ListSourcesResponse",
78
+ "MarkdownUploadRequest",
79
+ "NotFoundError",
80
+ "ProcessingStatus",
81
+ "RelatedChunk",
82
+ "SearchChunk",
83
+ "SearchData",
84
+ "ServiceUnavailableError",
85
+ "SingleUploadData",
86
+ "Source",
87
+ "SourceContent",
88
+ "SourceModel",
89
+ "TenantCreateData",
90
+ "TenantStats",
91
+ "UnauthorizedError",
92
+ "UnprocessableEntityError",
93
+ "ValidationError",
94
+ "ValidationErrorLocItem",
95
+ "embeddings",
96
+ "fetch",
97
+ "search",
98
+ "sources",
99
+ "tenant",
100
+ "upload",
101
+ "user",
102
+ "user_memory",
103
+ ]
cortex_ai/client.py ADDED
@@ -0,0 +1,244 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
7
+ from .core.request_options import RequestOptions
8
+ from .embeddings.client import AsyncEmbeddingsClient, EmbeddingsClient
9
+ from .environment import CortexAIEnvironment
10
+ from .fetch.client import AsyncFetchClient, FetchClient
11
+ from .raw_client import AsyncRawCortexAI, RawCortexAI
12
+ from .search.client import AsyncSearchClient, SearchClient
13
+ from .sources.client import AsyncSourcesClient, SourcesClient
14
+ from .tenant.client import AsyncTenantClient, TenantClient
15
+ from .upload.client import AsyncUploadClient, UploadClient
16
+ from .user.client import AsyncUserClient, UserClient
17
+ from .user_memory.client import AsyncUserMemoryClient, UserMemoryClient
18
+
19
+
20
+ class CortexAI:
21
+ """
22
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
23
+
24
+ Parameters
25
+ ----------
26
+ base_url : typing.Optional[str]
27
+ The base url to use for requests from the client.
28
+
29
+ environment : CortexAIEnvironment
30
+ The environment to use for requests from the client. from .environment import CortexAIEnvironment
31
+
32
+
33
+
34
+ Defaults to CortexAIEnvironment.CORTEX_PROD
35
+
36
+
37
+
38
+ token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
39
+ headers : typing.Optional[typing.Dict[str, str]]
40
+ Additional headers to send with every request.
41
+
42
+ timeout : typing.Optional[float]
43
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
44
+
45
+ follow_redirects : typing.Optional[bool]
46
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
47
+
48
+ httpx_client : typing.Optional[httpx.Client]
49
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
50
+
51
+ Examples
52
+ --------
53
+ from cortex-ai import CortexAI
54
+
55
+ client = CortexAI(token="YOUR_TOKEN", )
56
+ """
57
+
58
+ def __init__(
59
+ self,
60
+ *,
61
+ base_url: typing.Optional[str] = None,
62
+ environment: CortexAIEnvironment = CortexAIEnvironment.CORTEX_PROD,
63
+ token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
64
+ headers: typing.Optional[typing.Dict[str, str]] = None,
65
+ timeout: typing.Optional[float] = None,
66
+ follow_redirects: typing.Optional[bool] = True,
67
+ httpx_client: typing.Optional[httpx.Client] = None,
68
+ ):
69
+ _defaulted_timeout = (
70
+ timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
71
+ )
72
+ self._client_wrapper = SyncClientWrapper(
73
+ base_url=_get_base_url(base_url=base_url, environment=environment),
74
+ token=token,
75
+ headers=headers,
76
+ httpx_client=httpx_client
77
+ if httpx_client is not None
78
+ else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
79
+ if follow_redirects is not None
80
+ else httpx.Client(timeout=_defaulted_timeout),
81
+ timeout=_defaulted_timeout,
82
+ )
83
+ self._raw_client = RawCortexAI(client_wrapper=self._client_wrapper)
84
+ self.search = SearchClient(client_wrapper=self._client_wrapper)
85
+ self.sources = SourcesClient(client_wrapper=self._client_wrapper)
86
+ self.user_memory = UserMemoryClient(client_wrapper=self._client_wrapper)
87
+ self.fetch = FetchClient(client_wrapper=self._client_wrapper)
88
+ self.upload = UploadClient(client_wrapper=self._client_wrapper)
89
+ self.embeddings = EmbeddingsClient(client_wrapper=self._client_wrapper)
90
+ self.user = UserClient(client_wrapper=self._client_wrapper)
91
+ self.tenant = TenantClient(client_wrapper=self._client_wrapper)
92
+
93
+ @property
94
+ def with_raw_response(self) -> RawCortexAI:
95
+ """
96
+ Retrieves a raw implementation of this client that returns raw responses.
97
+
98
+ Returns
99
+ -------
100
+ RawCortexAI
101
+ """
102
+ return self._raw_client
103
+
104
+ def root_get(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Optional[typing.Any]:
105
+ """
106
+ Parameters
107
+ ----------
108
+ request_options : typing.Optional[RequestOptions]
109
+ Request-specific configuration.
110
+
111
+ Returns
112
+ -------
113
+ typing.Optional[typing.Any]
114
+ Successful Response
115
+
116
+ Examples
117
+ --------
118
+ from cortex-ai import CortexAI
119
+
120
+ client = CortexAI(token="YOUR_TOKEN", )
121
+ client.root_get()
122
+ """
123
+ _response = self._raw_client.root_get(request_options=request_options)
124
+ return _response.data
125
+
126
+
127
+ class AsyncCortexAI:
128
+ """
129
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
130
+
131
+ Parameters
132
+ ----------
133
+ base_url : typing.Optional[str]
134
+ The base url to use for requests from the client.
135
+
136
+ environment : CortexAIEnvironment
137
+ The environment to use for requests from the client. from .environment import CortexAIEnvironment
138
+
139
+
140
+
141
+ Defaults to CortexAIEnvironment.CORTEX_PROD
142
+
143
+
144
+
145
+ token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
146
+ headers : typing.Optional[typing.Dict[str, str]]
147
+ Additional headers to send with every request.
148
+
149
+ timeout : typing.Optional[float]
150
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
151
+
152
+ follow_redirects : typing.Optional[bool]
153
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
154
+
155
+ httpx_client : typing.Optional[httpx.AsyncClient]
156
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
157
+
158
+ Examples
159
+ --------
160
+ from cortex-ai import AsyncCortexAI
161
+
162
+ client = AsyncCortexAI(token="YOUR_TOKEN", )
163
+ """
164
+
165
+ def __init__(
166
+ self,
167
+ *,
168
+ base_url: typing.Optional[str] = None,
169
+ environment: CortexAIEnvironment = CortexAIEnvironment.CORTEX_PROD,
170
+ token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
171
+ headers: typing.Optional[typing.Dict[str, str]] = None,
172
+ timeout: typing.Optional[float] = None,
173
+ follow_redirects: typing.Optional[bool] = True,
174
+ httpx_client: typing.Optional[httpx.AsyncClient] = None,
175
+ ):
176
+ _defaulted_timeout = (
177
+ timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
178
+ )
179
+ self._client_wrapper = AsyncClientWrapper(
180
+ base_url=_get_base_url(base_url=base_url, environment=environment),
181
+ token=token,
182
+ headers=headers,
183
+ httpx_client=httpx_client
184
+ if httpx_client is not None
185
+ else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
186
+ if follow_redirects is not None
187
+ else httpx.AsyncClient(timeout=_defaulted_timeout),
188
+ timeout=_defaulted_timeout,
189
+ )
190
+ self._raw_client = AsyncRawCortexAI(client_wrapper=self._client_wrapper)
191
+ self.search = AsyncSearchClient(client_wrapper=self._client_wrapper)
192
+ self.sources = AsyncSourcesClient(client_wrapper=self._client_wrapper)
193
+ self.user_memory = AsyncUserMemoryClient(client_wrapper=self._client_wrapper)
194
+ self.fetch = AsyncFetchClient(client_wrapper=self._client_wrapper)
195
+ self.upload = AsyncUploadClient(client_wrapper=self._client_wrapper)
196
+ self.embeddings = AsyncEmbeddingsClient(client_wrapper=self._client_wrapper)
197
+ self.user = AsyncUserClient(client_wrapper=self._client_wrapper)
198
+ self.tenant = AsyncTenantClient(client_wrapper=self._client_wrapper)
199
+
200
+ @property
201
+ def with_raw_response(self) -> AsyncRawCortexAI:
202
+ """
203
+ Retrieves a raw implementation of this client that returns raw responses.
204
+
205
+ Returns
206
+ -------
207
+ AsyncRawCortexAI
208
+ """
209
+ return self._raw_client
210
+
211
+ async def root_get(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Optional[typing.Any]:
212
+ """
213
+ Parameters
214
+ ----------
215
+ request_options : typing.Optional[RequestOptions]
216
+ Request-specific configuration.
217
+
218
+ Returns
219
+ -------
220
+ typing.Optional[typing.Any]
221
+ Successful Response
222
+
223
+ Examples
224
+ --------
225
+ import asyncio
226
+
227
+ from cortex-ai import AsyncCortexAI
228
+
229
+ client = AsyncCortexAI(token="YOUR_TOKEN", )
230
+ async def main() -> None:
231
+ await client.root_get()
232
+ asyncio.run(main())
233
+ """
234
+ _response = await self._raw_client.root_get(request_options=request_options)
235
+ return _response.data
236
+
237
+
238
+ def _get_base_url(*, base_url: typing.Optional[str] = None, environment: CortexAIEnvironment) -> str:
239
+ if base_url is not None:
240
+ return base_url
241
+ elif environment is not None:
242
+ return environment.value
243
+ else:
244
+ raise Exception("Please pass in either base_url or environment to construct the client")
@@ -0,0 +1,52 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ from .api_error import ApiError
6
+ from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
7
+ from .datetime_utils import serialize_datetime
8
+ from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
9
+ from .http_client import AsyncHttpClient, HttpClient
10
+ from .http_response import AsyncHttpResponse, HttpResponse
11
+ from .jsonable_encoder import jsonable_encoder
12
+ from .pydantic_utilities import (
13
+ IS_PYDANTIC_V2,
14
+ UniversalBaseModel,
15
+ UniversalRootModel,
16
+ parse_obj_as,
17
+ universal_field_validator,
18
+ universal_root_validator,
19
+ update_forward_refs,
20
+ )
21
+ from .query_encoder import encode_query
22
+ from .remove_none_from_dict import remove_none_from_dict
23
+ from .request_options import RequestOptions
24
+ from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
25
+
26
+ __all__ = [
27
+ "ApiError",
28
+ "AsyncClientWrapper",
29
+ "AsyncHttpClient",
30
+ "AsyncHttpResponse",
31
+ "BaseClientWrapper",
32
+ "FieldMetadata",
33
+ "File",
34
+ "HttpClient",
35
+ "HttpResponse",
36
+ "IS_PYDANTIC_V2",
37
+ "RequestOptions",
38
+ "SyncClientWrapper",
39
+ "UniversalBaseModel",
40
+ "UniversalRootModel",
41
+ "convert_and_respect_annotation_metadata",
42
+ "convert_file_dict_to_httpx_tuples",
43
+ "encode_query",
44
+ "jsonable_encoder",
45
+ "parse_obj_as",
46
+ "remove_none_from_dict",
47
+ "serialize_datetime",
48
+ "universal_field_validator",
49
+ "universal_root_validator",
50
+ "update_forward_refs",
51
+ "with_content_type",
52
+ ]
@@ -0,0 +1,23 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+
6
+ class ApiError(Exception):
7
+ headers: Optional[Dict[str, str]]
8
+ status_code: Optional[int]
9
+ body: Any
10
+
11
+ def __init__(
12
+ self,
13
+ *,
14
+ headers: Optional[Dict[str, str]] = None,
15
+ status_code: Optional[int] = None,
16
+ body: Any = None,
17
+ ) -> None:
18
+ self.headers = headers
19
+ self.status_code = status_code
20
+ self.body = body
21
+
22
+ def __str__(self) -> str:
23
+ return f"headers: {self.headers}, status_code: {self.status_code}, body: {self.body}"
@@ -0,0 +1,84 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+ from .http_client import AsyncHttpClient, HttpClient
7
+
8
+
9
+ class BaseClientWrapper:
10
+ def __init__(
11
+ self,
12
+ *,
13
+ token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
14
+ headers: typing.Optional[typing.Dict[str, str]] = None,
15
+ base_url: str,
16
+ timeout: typing.Optional[float] = None,
17
+ ):
18
+ self._token = token
19
+ self._headers = headers
20
+ self._base_url = base_url
21
+ self._timeout = timeout
22
+
23
+ def get_headers(self) -> typing.Dict[str, str]:
24
+ headers: typing.Dict[str, str] = {
25
+ "X-Fern-Language": "Python",
26
+ **(self.get_custom_headers() or {}),
27
+ }
28
+ token = self._get_token()
29
+ if token is not None:
30
+ headers["Authorization"] = f"Bearer {token}"
31
+ return headers
32
+
33
+ def _get_token(self) -> typing.Optional[str]:
34
+ if isinstance(self._token, str) or self._token is None:
35
+ return self._token
36
+ else:
37
+ return self._token()
38
+
39
+ def get_custom_headers(self) -> typing.Optional[typing.Dict[str, str]]:
40
+ return self._headers
41
+
42
+ def get_base_url(self) -> str:
43
+ return self._base_url
44
+
45
+ def get_timeout(self) -> typing.Optional[float]:
46
+ return self._timeout
47
+
48
+
49
+ class SyncClientWrapper(BaseClientWrapper):
50
+ def __init__(
51
+ self,
52
+ *,
53
+ token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
54
+ headers: typing.Optional[typing.Dict[str, str]] = None,
55
+ base_url: str,
56
+ timeout: typing.Optional[float] = None,
57
+ httpx_client: httpx.Client,
58
+ ):
59
+ super().__init__(token=token, headers=headers, base_url=base_url, timeout=timeout)
60
+ self.httpx_client = HttpClient(
61
+ httpx_client=httpx_client,
62
+ base_headers=self.get_headers,
63
+ base_timeout=self.get_timeout,
64
+ base_url=self.get_base_url,
65
+ )
66
+
67
+
68
+ class AsyncClientWrapper(BaseClientWrapper):
69
+ def __init__(
70
+ self,
71
+ *,
72
+ token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
73
+ headers: typing.Optional[typing.Dict[str, str]] = None,
74
+ base_url: str,
75
+ timeout: typing.Optional[float] = None,
76
+ httpx_client: httpx.AsyncClient,
77
+ ):
78
+ super().__init__(token=token, headers=headers, base_url=base_url, timeout=timeout)
79
+ self.httpx_client = AsyncHttpClient(
80
+ httpx_client=httpx_client,
81
+ base_headers=self.get_headers,
82
+ base_timeout=self.get_timeout,
83
+ base_url=self.get_base_url,
84
+ )
@@ -0,0 +1,28 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import datetime as dt
4
+
5
+
6
+ def serialize_datetime(v: dt.datetime) -> str:
7
+ """
8
+ Serialize a datetime including timezone info.
9
+
10
+ Uses the timezone info provided if present, otherwise uses the current runtime's timezone info.
11
+
12
+ UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00.
13
+ """
14
+
15
+ def _serialize_zoned_datetime(v: dt.datetime) -> str:
16
+ if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None):
17
+ # UTC is a special case where we use "Z" at the end instead of "+00:00"
18
+ return v.isoformat().replace("+00:00", "Z")
19
+ else:
20
+ # Delegate to the typical +/- offset format
21
+ return v.isoformat()
22
+
23
+ if v.tzinfo is not None:
24
+ return _serialize_zoned_datetime(v)
25
+ else:
26
+ local_tz = dt.datetime.now().astimezone().tzinfo
27
+ localized_dt = v.replace(tzinfo=local_tz)
28
+ return _serialize_zoned_datetime(localized_dt)
cortex_ai/core/file.py ADDED
@@ -0,0 +1,67 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import IO, Dict, List, Mapping, Optional, Tuple, Union, cast
4
+
5
+ # File typing inspired by the flexibility of types within the httpx library
6
+ # https://github.com/encode/httpx/blob/master/httpx/_types.py
7
+ FileContent = Union[IO[bytes], bytes, str]
8
+ File = Union[
9
+ # file (or bytes)
10
+ FileContent,
11
+ # (filename, file (or bytes))
12
+ Tuple[Optional[str], FileContent],
13
+ # (filename, file (or bytes), content_type)
14
+ Tuple[Optional[str], FileContent, Optional[str]],
15
+ # (filename, file (or bytes), content_type, headers)
16
+ Tuple[
17
+ Optional[str],
18
+ FileContent,
19
+ Optional[str],
20
+ Mapping[str, str],
21
+ ],
22
+ ]
23
+
24
+
25
+ def convert_file_dict_to_httpx_tuples(
26
+ d: Dict[str, Union[File, List[File]]],
27
+ ) -> List[Tuple[str, File]]:
28
+ """
29
+ The format we use is a list of tuples, where the first element is the
30
+ name of the file and the second is the file object. Typically HTTPX wants
31
+ a dict, but to be able to send lists of files, you have to use the list
32
+ approach (which also works for non-lists)
33
+ https://github.com/encode/httpx/pull/1032
34
+ """
35
+
36
+ httpx_tuples = []
37
+ for key, file_like in d.items():
38
+ if isinstance(file_like, list):
39
+ for file_like_item in file_like:
40
+ httpx_tuples.append((key, file_like_item))
41
+ else:
42
+ httpx_tuples.append((key, file_like))
43
+ return httpx_tuples
44
+
45
+
46
+ def with_content_type(*, file: File, default_content_type: str) -> File:
47
+ """
48
+ This function resolves to the file's content type, if provided, and defaults
49
+ to the default_content_type value if not.
50
+ """
51
+ if isinstance(file, tuple):
52
+ if len(file) == 2:
53
+ filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore
54
+ return (filename, content, default_content_type)
55
+ elif len(file) == 3:
56
+ filename, content, file_content_type = cast(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore
57
+ out_content_type = file_content_type or default_content_type
58
+ return (filename, content, out_content_type)
59
+ elif len(file) == 4:
60
+ filename, content, file_content_type, headers = cast( # type: ignore
61
+ Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], file
62
+ )
63
+ out_content_type = file_content_type or default_content_type
64
+ return (filename, content, out_content_type, headers)
65
+ else:
66
+ raise ValueError(f"Unexpected tuple length: {len(file)}")
67
+ return (None, file, default_content_type)
@@ -0,0 +1,18 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import Any, Dict
4
+
5
+
6
+ class ForceMultipartDict(Dict[str, Any]):
7
+ """
8
+ A dictionary subclass that always evaluates to True in boolean contexts.
9
+
10
+ This is used to force multipart/form-data encoding in HTTP requests even when
11
+ the dictionary is empty, which would normally evaluate to False.
12
+ """
13
+
14
+ def __bool__(self) -> bool:
15
+ return True
16
+
17
+
18
+ FORCE_MULTIPART = ForceMultipartDict()