mixpeek 0.2__py3-none-any.whl → 0.6.2__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.
- mixpeek/__init__.py +100 -71
- mixpeek/base_client.py +155 -0
- mixpeek/client.py +65 -0
- mixpeek/core/__init__.py +25 -0
- mixpeek/core/api_error.py +15 -0
- mixpeek/core/client_wrapper.py +83 -0
- mixpeek/core/datetime_utils.py +28 -0
- mixpeek/core/file.py +38 -0
- mixpeek/core/http_client.py +130 -0
- mixpeek/core/jsonable_encoder.py +103 -0
- mixpeek/core/remove_none_from_dict.py +11 -0
- mixpeek/core/request_options.py +32 -0
- mixpeek/embed/__init__.py +2 -0
- mixpeek/embed/client.py +350 -0
- mixpeek/environment.py +7 -0
- mixpeek/errors/__init__.py +17 -0
- mixpeek/errors/bad_request_error.py +9 -0
- mixpeek/errors/forbidden_error.py +9 -0
- mixpeek/errors/internal_server_error.py +9 -0
- mixpeek/errors/not_found_error.py +9 -0
- mixpeek/errors/unauthorized_error.py +9 -0
- mixpeek/errors/unprocessable_entity_error.py +9 -0
- mixpeek/extract/__init__.py +2 -0
- mixpeek/extract/client.py +347 -0
- mixpeek/generators/__init__.py +2 -0
- mixpeek/generators/client.py +237 -0
- mixpeek/parse/__init__.py +2 -0
- mixpeek/parse/client.py +111 -0
- mixpeek/parse_client.py +14 -0
- mixpeek/pipelines/__init__.py +2 -0
- mixpeek/pipelines/client.py +468 -0
- mixpeek/py.typed +0 -0
- mixpeek/storage/__init__.py +2 -0
- mixpeek/storage/client.py +250 -0
- mixpeek/types/__init__.py +73 -0
- mixpeek/types/api_key.py +31 -0
- mixpeek/types/audio_params.py +29 -0
- mixpeek/types/configs_response.py +31 -0
- mixpeek/types/connection.py +36 -0
- mixpeek/types/connection_engine.py +5 -0
- mixpeek/types/csv_params.py +29 -0
- mixpeek/types/destination.py +31 -0
- mixpeek/types/embedding_response.py +30 -0
- mixpeek/types/error_message.py +29 -0
- mixpeek/types/error_response.py +30 -0
- mixpeek/types/field_type.py +5 -0
- mixpeek/types/generation_response.py +34 -0
- mixpeek/types/html_params.py +29 -0
- mixpeek/types/http_validation_error.py +30 -0
- mixpeek/types/image_params.py +32 -0
- mixpeek/types/message.py +30 -0
- mixpeek/types/metadata.py +34 -0
- mixpeek/types/modality.py +5 -0
- mixpeek/types/model.py +31 -0
- mixpeek/types/models.py +5 -0
- mixpeek/types/pdf_params.py +41 -0
- mixpeek/types/ppt_params.py +27 -0
- mixpeek/types/pptx_params.py +27 -0
- mixpeek/types/settings.py +35 -0
- mixpeek/types/source.py +32 -0
- mixpeek/types/source_destination_mapping.py +33 -0
- mixpeek/types/txt_params.py +27 -0
- mixpeek/types/user.py +36 -0
- mixpeek/types/validation_error.py +32 -0
- mixpeek/types/validation_error_loc_item.py +5 -0
- mixpeek/types/video_params.py +27 -0
- mixpeek/types/workflow_response.py +32 -0
- mixpeek/types/workflow_settings.py +30 -0
- mixpeek/types/xlsx_params.py +29 -0
- mixpeek/users/__init__.py +2 -0
- mixpeek/users/client.py +308 -0
- mixpeek/version.py +4 -0
- mixpeek/workflows/__init__.py +2 -0
- mixpeek/workflows/client.py +536 -0
- mixpeek-0.2.dist-info/LICENSE.rst → mixpeek-0.6.2.dist-info/LICENSE +10 -9
- mixpeek-0.6.2.dist-info/METADATA +145 -0
- mixpeek-0.6.2.dist-info/RECORD +78 -0
- {mixpeek-0.2.dist-info → mixpeek-0.6.2.dist-info}/WHEEL +1 -2
- mixpeek-0.2.dist-info/METADATA +0 -12
- mixpeek-0.2.dist-info/RECORD +0 -6
- mixpeek-0.2.dist-info/top_level.txt +0 -1
mixpeek/__init__.py
CHANGED
@@ -1,73 +1,102 @@
|
|
1
|
-
#
|
2
|
-
import requests
|
3
|
-
import json
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
4
2
|
|
3
|
+
from .types import (
|
4
|
+
ApiKey,
|
5
|
+
AudioParams,
|
6
|
+
ConfigsResponse,
|
7
|
+
Connection,
|
8
|
+
ConnectionEngine,
|
9
|
+
CsvParams,
|
10
|
+
Destination,
|
11
|
+
EmbeddingResponse,
|
12
|
+
ErrorMessage,
|
13
|
+
ErrorResponse,
|
14
|
+
FieldType,
|
15
|
+
GenerationResponse,
|
16
|
+
HtmlParams,
|
17
|
+
HttpValidationError,
|
18
|
+
ImageParams,
|
19
|
+
Message,
|
20
|
+
Metadata,
|
21
|
+
Modality,
|
22
|
+
Model,
|
23
|
+
Models,
|
24
|
+
PdfParams,
|
25
|
+
PptParams,
|
26
|
+
PptxParams,
|
27
|
+
Settings,
|
28
|
+
Source,
|
29
|
+
SourceDestinationMapping,
|
30
|
+
TxtParams,
|
31
|
+
User,
|
32
|
+
ValidationError,
|
33
|
+
ValidationErrorLocItem,
|
34
|
+
VideoParams,
|
35
|
+
WorkflowResponse,
|
36
|
+
WorkflowSettings,
|
37
|
+
XlsxParams,
|
38
|
+
)
|
39
|
+
from .errors import (
|
40
|
+
BadRequestError,
|
41
|
+
ForbiddenError,
|
42
|
+
InternalServerError,
|
43
|
+
NotFoundError,
|
44
|
+
UnauthorizedError,
|
45
|
+
UnprocessableEntityError,
|
46
|
+
)
|
47
|
+
from . import embed, extract, generators, parse, pipelines, storage, users, workflows
|
48
|
+
from .environment import MixpeekEnvironment
|
49
|
+
from .version import __version__
|
5
50
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
class Text:
|
60
|
-
def __init__(self, mixpeek):
|
61
|
-
self.mixpeek = mixpeek
|
62
|
-
self.parse_url = f"{self.mixpeek.base_url}/parsers"
|
63
|
-
|
64
|
-
def extract(self, file_url, should_chunk=True):
|
65
|
-
url = self.parse_url + "?should_chunk=" + str(should_chunk)
|
66
|
-
return self.mixpeek._send_post(url, {"file_url": file_url})
|
67
|
-
|
68
|
-
def chunk(self, corpus):
|
69
|
-
pass
|
70
|
-
|
71
|
-
class Index:
|
72
|
-
def __init__(self):
|
73
|
-
pass
|
51
|
+
__all__ = [
|
52
|
+
"ApiKey",
|
53
|
+
"AudioParams",
|
54
|
+
"BadRequestError",
|
55
|
+
"ConfigsResponse",
|
56
|
+
"Connection",
|
57
|
+
"ConnectionEngine",
|
58
|
+
"CsvParams",
|
59
|
+
"Destination",
|
60
|
+
"EmbeddingResponse",
|
61
|
+
"ErrorMessage",
|
62
|
+
"ErrorResponse",
|
63
|
+
"FieldType",
|
64
|
+
"ForbiddenError",
|
65
|
+
"GenerationResponse",
|
66
|
+
"HtmlParams",
|
67
|
+
"HttpValidationError",
|
68
|
+
"ImageParams",
|
69
|
+
"InternalServerError",
|
70
|
+
"Message",
|
71
|
+
"Metadata",
|
72
|
+
"MixpeekEnvironment",
|
73
|
+
"Modality",
|
74
|
+
"Model",
|
75
|
+
"Models",
|
76
|
+
"NotFoundError",
|
77
|
+
"PdfParams",
|
78
|
+
"PptParams",
|
79
|
+
"PptxParams",
|
80
|
+
"Settings",
|
81
|
+
"Source",
|
82
|
+
"SourceDestinationMapping",
|
83
|
+
"TxtParams",
|
84
|
+
"UnauthorizedError",
|
85
|
+
"UnprocessableEntityError",
|
86
|
+
"User",
|
87
|
+
"ValidationError",
|
88
|
+
"ValidationErrorLocItem",
|
89
|
+
"VideoParams",
|
90
|
+
"WorkflowResponse",
|
91
|
+
"WorkflowSettings",
|
92
|
+
"XlsxParams",
|
93
|
+
"__version__",
|
94
|
+
"embed",
|
95
|
+
"extract",
|
96
|
+
"generators",
|
97
|
+
"parse",
|
98
|
+
"pipelines",
|
99
|
+
"storage",
|
100
|
+
"users",
|
101
|
+
"workflows",
|
102
|
+
]
|
mixpeek/base_client.py
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
import os
|
4
|
+
import typing
|
5
|
+
|
6
|
+
import httpx
|
7
|
+
|
8
|
+
from .core.api_error import ApiError
|
9
|
+
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
10
|
+
from .embed.client import AsyncEmbedClient, EmbedClient
|
11
|
+
from .environment import MixpeekEnvironment
|
12
|
+
from .extract.client import AsyncExtractClient, ExtractClient
|
13
|
+
from .generators.client import AsyncGeneratorsClient, GeneratorsClient
|
14
|
+
from .parse.client import AsyncParseClient, ParseClient
|
15
|
+
from .pipelines.client import AsyncPipelinesClient, PipelinesClient
|
16
|
+
from .storage.client import AsyncStorageClient, StorageClient
|
17
|
+
from .users.client import AsyncUsersClient, UsersClient
|
18
|
+
from .workflows.client import AsyncWorkflowsClient, WorkflowsClient
|
19
|
+
|
20
|
+
|
21
|
+
class BaseMixpeek:
|
22
|
+
"""
|
23
|
+
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions.
|
24
|
+
|
25
|
+
Parameters:
|
26
|
+
- base_url: typing.Optional[str]. The base url to use for requests from the client.
|
27
|
+
|
28
|
+
- environment: MixpeekEnvironment. The environment to use for requests from the client. from .environment import MixpeekEnvironment
|
29
|
+
|
30
|
+
Defaults to MixpeekEnvironment.DEFAULT
|
31
|
+
|
32
|
+
- authorization: typing.Optional[str].
|
33
|
+
|
34
|
+
- index_id: typing.Optional[str].
|
35
|
+
|
36
|
+
- api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]].
|
37
|
+
|
38
|
+
- timeout: typing.Optional[float]. 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 a default is not set.
|
39
|
+
|
40
|
+
- httpx_client: typing.Optional[httpx.Client]. 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.
|
41
|
+
---
|
42
|
+
from mixpeek.client import Mixpeek
|
43
|
+
|
44
|
+
client = Mixpeek(
|
45
|
+
authorization="YOUR_AUTHORIZATION",
|
46
|
+
index_id="YOUR_INDEX_ID",
|
47
|
+
api_key="YOUR_API_KEY",
|
48
|
+
)
|
49
|
+
"""
|
50
|
+
|
51
|
+
def __init__(
|
52
|
+
self,
|
53
|
+
*,
|
54
|
+
base_url: typing.Optional[str] = None,
|
55
|
+
environment: MixpeekEnvironment = MixpeekEnvironment.DEFAULT,
|
56
|
+
authorization: typing.Optional[str] = None,
|
57
|
+
index_id: typing.Optional[str] = None,
|
58
|
+
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("MIXPEEK_API_KEY"),
|
59
|
+
timeout: typing.Optional[float] = None,
|
60
|
+
httpx_client: typing.Optional[httpx.Client] = None
|
61
|
+
):
|
62
|
+
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
|
63
|
+
if api_key is None:
|
64
|
+
raise ApiError(
|
65
|
+
body="The client must be instantiated be either passing in api_key or setting MIXPEEK_API_KEY"
|
66
|
+
)
|
67
|
+
self._client_wrapper = SyncClientWrapper(
|
68
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
69
|
+
authorization=authorization,
|
70
|
+
index_id=index_id,
|
71
|
+
api_key=api_key,
|
72
|
+
httpx_client=httpx.Client(timeout=_defaulted_timeout) if httpx_client is None else httpx_client,
|
73
|
+
timeout=_defaulted_timeout,
|
74
|
+
)
|
75
|
+
self.users = UsersClient(client_wrapper=self._client_wrapper)
|
76
|
+
self.extract = ExtractClient(client_wrapper=self._client_wrapper)
|
77
|
+
self.generators = GeneratorsClient(client_wrapper=self._client_wrapper)
|
78
|
+
self.embed = EmbedClient(client_wrapper=self._client_wrapper)
|
79
|
+
self.pipelines = PipelinesClient(client_wrapper=self._client_wrapper)
|
80
|
+
self.workflows = WorkflowsClient(client_wrapper=self._client_wrapper)
|
81
|
+
self.storage = StorageClient(client_wrapper=self._client_wrapper)
|
82
|
+
self.parse = ParseClient(client_wrapper=self._client_wrapper)
|
83
|
+
|
84
|
+
|
85
|
+
class AsyncBaseMixpeek:
|
86
|
+
"""
|
87
|
+
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions.
|
88
|
+
|
89
|
+
Parameters:
|
90
|
+
- base_url: typing.Optional[str]. The base url to use for requests from the client.
|
91
|
+
|
92
|
+
- environment: MixpeekEnvironment. The environment to use for requests from the client. from .environment import MixpeekEnvironment
|
93
|
+
|
94
|
+
Defaults to MixpeekEnvironment.DEFAULT
|
95
|
+
|
96
|
+
- authorization: typing.Optional[str].
|
97
|
+
|
98
|
+
- index_id: typing.Optional[str].
|
99
|
+
|
100
|
+
- api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]].
|
101
|
+
|
102
|
+
- timeout: typing.Optional[float]. 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 a default is not set.
|
103
|
+
|
104
|
+
- httpx_client: typing.Optional[httpx.AsyncClient]. 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.
|
105
|
+
---
|
106
|
+
from mixpeek.client import AsyncMixpeek
|
107
|
+
|
108
|
+
client = AsyncMixpeek(
|
109
|
+
authorization="YOUR_AUTHORIZATION",
|
110
|
+
index_id="YOUR_INDEX_ID",
|
111
|
+
api_key="YOUR_API_KEY",
|
112
|
+
)
|
113
|
+
"""
|
114
|
+
|
115
|
+
def __init__(
|
116
|
+
self,
|
117
|
+
*,
|
118
|
+
base_url: typing.Optional[str] = None,
|
119
|
+
environment: MixpeekEnvironment = MixpeekEnvironment.DEFAULT,
|
120
|
+
authorization: typing.Optional[str] = None,
|
121
|
+
index_id: typing.Optional[str] = None,
|
122
|
+
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("MIXPEEK_API_KEY"),
|
123
|
+
timeout: typing.Optional[float] = None,
|
124
|
+
httpx_client: typing.Optional[httpx.AsyncClient] = None
|
125
|
+
):
|
126
|
+
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
|
127
|
+
if api_key is None:
|
128
|
+
raise ApiError(
|
129
|
+
body="The client must be instantiated be either passing in api_key or setting MIXPEEK_API_KEY"
|
130
|
+
)
|
131
|
+
self._client_wrapper = AsyncClientWrapper(
|
132
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
133
|
+
authorization=authorization,
|
134
|
+
index_id=index_id,
|
135
|
+
api_key=api_key,
|
136
|
+
httpx_client=httpx.AsyncClient(timeout=_defaulted_timeout) if httpx_client is None else httpx_client,
|
137
|
+
timeout=_defaulted_timeout,
|
138
|
+
)
|
139
|
+
self.users = AsyncUsersClient(client_wrapper=self._client_wrapper)
|
140
|
+
self.extract = AsyncExtractClient(client_wrapper=self._client_wrapper)
|
141
|
+
self.generators = AsyncGeneratorsClient(client_wrapper=self._client_wrapper)
|
142
|
+
self.embed = AsyncEmbedClient(client_wrapper=self._client_wrapper)
|
143
|
+
self.pipelines = AsyncPipelinesClient(client_wrapper=self._client_wrapper)
|
144
|
+
self.workflows = AsyncWorkflowsClient(client_wrapper=self._client_wrapper)
|
145
|
+
self.storage = AsyncStorageClient(client_wrapper=self._client_wrapper)
|
146
|
+
self.parse = AsyncParseClient(client_wrapper=self._client_wrapper)
|
147
|
+
|
148
|
+
|
149
|
+
def _get_base_url(*, base_url: typing.Optional[str] = None, environment: MixpeekEnvironment) -> str:
|
150
|
+
if base_url is not None:
|
151
|
+
return base_url
|
152
|
+
elif environment is not None:
|
153
|
+
return environment.value
|
154
|
+
else:
|
155
|
+
raise Exception("Please pass in either base_url or environment to construct the client")
|
mixpeek/client.py
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
import typing
|
3
|
+
import httpx
|
4
|
+
|
5
|
+
from .base_client import BaseMixpeek, \
|
6
|
+
AsyncBaseMixpeek
|
7
|
+
from .types.message import Message
|
8
|
+
from .types.model import Model
|
9
|
+
from .types.settings import Settings
|
10
|
+
from .types.generation_response import GenerationResponse
|
11
|
+
from .core.request_options import RequestOptions
|
12
|
+
|
13
|
+
|
14
|
+
# this is used as the default value for optional parameters
|
15
|
+
OMIT = typing.cast(typing.Any, ...)
|
16
|
+
|
17
|
+
|
18
|
+
class Mixpeek(BaseMixpeek):
|
19
|
+
|
20
|
+
def generate(
|
21
|
+
self,
|
22
|
+
*,
|
23
|
+
model: Model,
|
24
|
+
# Pydantic model that represents the JSON schema of the response
|
25
|
+
response_format: typing.Optional[typing.Any],
|
26
|
+
context: typing.Optional[str] = OMIT,
|
27
|
+
messages: typing.Sequence[Message],
|
28
|
+
settings: typing.Optional[Settings] = OMIT,
|
29
|
+
request_options: typing.Optional[RequestOptions] = None,
|
30
|
+
) -> GenerationResponse:
|
31
|
+
if response_format is not None:
|
32
|
+
response_format = response_format.model_json_schema()
|
33
|
+
return self.generators.generate(
|
34
|
+
model=model,
|
35
|
+
response_format=response_format,
|
36
|
+
context=context,
|
37
|
+
messages=messages,
|
38
|
+
settings=settings,
|
39
|
+
request_options=request_options,
|
40
|
+
)
|
41
|
+
|
42
|
+
|
43
|
+
class AsyncMixpeek(AsyncBaseMixpeek):
|
44
|
+
|
45
|
+
async def generate(
|
46
|
+
self,
|
47
|
+
*,
|
48
|
+
model: Model,
|
49
|
+
# Pydantic model that represents the JSON schema of the response
|
50
|
+
response_format: typing.Optional[typing.Any],
|
51
|
+
context: typing.Optional[str] = OMIT,
|
52
|
+
messages: typing.Sequence[Message],
|
53
|
+
settings: typing.Optional[Settings] = OMIT,
|
54
|
+
request_options: typing.Optional[RequestOptions] = None,
|
55
|
+
) -> GenerationResponse:
|
56
|
+
if response_format is not None:
|
57
|
+
response_format = response_format.model_json_schema()
|
58
|
+
return await self.generators.generate(
|
59
|
+
model=model,
|
60
|
+
response_format=response_format,
|
61
|
+
context=context,
|
62
|
+
messages=messages,
|
63
|
+
settings=settings,
|
64
|
+
request_options=request_options,
|
65
|
+
)
|
mixpeek/core/__init__.py
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from .api_error import ApiError
|
4
|
+
from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
|
5
|
+
from .datetime_utils import serialize_datetime
|
6
|
+
from .file import File, convert_file_dict_to_httpx_tuples
|
7
|
+
from .http_client import AsyncHttpClient, HttpClient
|
8
|
+
from .jsonable_encoder import jsonable_encoder
|
9
|
+
from .remove_none_from_dict import remove_none_from_dict
|
10
|
+
from .request_options import RequestOptions
|
11
|
+
|
12
|
+
__all__ = [
|
13
|
+
"ApiError",
|
14
|
+
"AsyncClientWrapper",
|
15
|
+
"AsyncHttpClient",
|
16
|
+
"BaseClientWrapper",
|
17
|
+
"File",
|
18
|
+
"HttpClient",
|
19
|
+
"RequestOptions",
|
20
|
+
"SyncClientWrapper",
|
21
|
+
"convert_file_dict_to_httpx_tuples",
|
22
|
+
"jsonable_encoder",
|
23
|
+
"remove_none_from_dict",
|
24
|
+
"serialize_datetime",
|
25
|
+
]
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
import typing
|
4
|
+
|
5
|
+
|
6
|
+
class ApiError(Exception):
|
7
|
+
status_code: typing.Optional[int]
|
8
|
+
body: typing.Any
|
9
|
+
|
10
|
+
def __init__(self, *, status_code: typing.Optional[int] = None, body: typing.Any = None):
|
11
|
+
self.status_code = status_code
|
12
|
+
self.body = body
|
13
|
+
|
14
|
+
def __str__(self) -> str:
|
15
|
+
return f"status_code: {self.status_code}, body: {self.body}"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
import typing
|
4
|
+
|
5
|
+
import httpx
|
6
|
+
|
7
|
+
from .http_client import AsyncHttpClient, HttpClient
|
8
|
+
|
9
|
+
|
10
|
+
class BaseClientWrapper:
|
11
|
+
def __init__(
|
12
|
+
self,
|
13
|
+
*,
|
14
|
+
authorization: typing.Optional[str] = None,
|
15
|
+
index_id: typing.Optional[str] = None,
|
16
|
+
api_key: typing.Union[str, typing.Callable[[], str]],
|
17
|
+
base_url: str,
|
18
|
+
timeout: typing.Optional[float] = None,
|
19
|
+
):
|
20
|
+
self._authorization = authorization
|
21
|
+
self._index_id = index_id
|
22
|
+
self._api_key = api_key
|
23
|
+
self._base_url = base_url
|
24
|
+
self._timeout = timeout
|
25
|
+
|
26
|
+
def get_headers(self) -> typing.Dict[str, str]:
|
27
|
+
headers: typing.Dict[str, str] = {
|
28
|
+
"X-Fern-Language": "Python",
|
29
|
+
"X-Fern-SDK-Name": "mixpeek",
|
30
|
+
"X-Fern-SDK-Version": "0.6.2",
|
31
|
+
}
|
32
|
+
if self._authorization is not None:
|
33
|
+
headers["Authorization"] = self._authorization
|
34
|
+
if self._index_id is not None:
|
35
|
+
headers["index-id"] = self._index_id
|
36
|
+
headers["Authorization"] = f"Bearer {self._get_api_key()}"
|
37
|
+
return headers
|
38
|
+
|
39
|
+
def _get_api_key(self) -> str:
|
40
|
+
if isinstance(self._api_key, str):
|
41
|
+
return self._api_key
|
42
|
+
else:
|
43
|
+
return self._api_key()
|
44
|
+
|
45
|
+
def get_base_url(self) -> str:
|
46
|
+
return self._base_url
|
47
|
+
|
48
|
+
def get_timeout(self) -> typing.Optional[float]:
|
49
|
+
return self._timeout
|
50
|
+
|
51
|
+
|
52
|
+
class SyncClientWrapper(BaseClientWrapper):
|
53
|
+
def __init__(
|
54
|
+
self,
|
55
|
+
*,
|
56
|
+
authorization: typing.Optional[str] = None,
|
57
|
+
index_id: typing.Optional[str] = None,
|
58
|
+
api_key: typing.Union[str, typing.Callable[[], str]],
|
59
|
+
base_url: str,
|
60
|
+
timeout: typing.Optional[float] = None,
|
61
|
+
httpx_client: httpx.Client,
|
62
|
+
):
|
63
|
+
super().__init__(
|
64
|
+
authorization=authorization, index_id=index_id, api_key=api_key, base_url=base_url, timeout=timeout
|
65
|
+
)
|
66
|
+
self.httpx_client = HttpClient(httpx_client=httpx_client)
|
67
|
+
|
68
|
+
|
69
|
+
class AsyncClientWrapper(BaseClientWrapper):
|
70
|
+
def __init__(
|
71
|
+
self,
|
72
|
+
*,
|
73
|
+
authorization: typing.Optional[str] = None,
|
74
|
+
index_id: typing.Optional[str] = None,
|
75
|
+
api_key: typing.Union[str, typing.Callable[[], str]],
|
76
|
+
base_url: str,
|
77
|
+
timeout: typing.Optional[float] = None,
|
78
|
+
httpx_client: httpx.AsyncClient,
|
79
|
+
):
|
80
|
+
super().__init__(
|
81
|
+
authorization=authorization, index_id=index_id, api_key=api_key, base_url=base_url, timeout=timeout
|
82
|
+
)
|
83
|
+
self.httpx_client = AsyncHttpClient(httpx_client=httpx_client)
|
@@ -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)
|
mixpeek/core/file.py
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
import typing
|
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 = typing.Union[typing.IO[bytes], bytes, str]
|
8
|
+
File = typing.Union[
|
9
|
+
# file (or bytes)
|
10
|
+
FileContent,
|
11
|
+
# (filename, file (or bytes))
|
12
|
+
typing.Tuple[typing.Optional[str], FileContent],
|
13
|
+
# (filename, file (or bytes), content_type)
|
14
|
+
typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str]],
|
15
|
+
# (filename, file (or bytes), content_type, headers)
|
16
|
+
typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str], typing.Mapping[str, str]],
|
17
|
+
]
|
18
|
+
|
19
|
+
|
20
|
+
def convert_file_dict_to_httpx_tuples(
|
21
|
+
d: typing.Dict[str, typing.Union[File, typing.List[File]]]
|
22
|
+
) -> typing.List[typing.Tuple[str, File]]:
|
23
|
+
"""
|
24
|
+
The format we use is a list of tuples, where the first element is the
|
25
|
+
name of the file and the second is the file object. Typically HTTPX wants
|
26
|
+
a dict, but to be able to send lists of files, you have to use the list
|
27
|
+
approach (which also works for non-lists)
|
28
|
+
https://github.com/encode/httpx/pull/1032
|
29
|
+
"""
|
30
|
+
|
31
|
+
httpx_tuples = []
|
32
|
+
for key, file_like in d.items():
|
33
|
+
if isinstance(file_like, list):
|
34
|
+
for file_like_item in file_like:
|
35
|
+
httpx_tuples.append((key, file_like_item))
|
36
|
+
else:
|
37
|
+
httpx_tuples.append((key, file_like))
|
38
|
+
return httpx_tuples
|