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
@@ -0,0 +1,130 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
import asyncio
|
4
|
+
import email.utils
|
5
|
+
import re
|
6
|
+
import time
|
7
|
+
import typing
|
8
|
+
from contextlib import asynccontextmanager, contextmanager
|
9
|
+
from functools import wraps
|
10
|
+
from random import random
|
11
|
+
|
12
|
+
import httpx
|
13
|
+
|
14
|
+
INITIAL_RETRY_DELAY_SECONDS = 0.5
|
15
|
+
MAX_RETRY_DELAY_SECONDS = 10
|
16
|
+
MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30
|
17
|
+
|
18
|
+
|
19
|
+
def _parse_retry_after(response_headers: httpx.Headers) -> typing.Optional[float]:
|
20
|
+
"""
|
21
|
+
This function parses the `Retry-After` header in a HTTP response and returns the number of seconds to wait.
|
22
|
+
|
23
|
+
Inspired by the urllib3 retry implementation.
|
24
|
+
"""
|
25
|
+
retry_after_ms = response_headers.get("retry-after-ms")
|
26
|
+
if retry_after_ms is not None:
|
27
|
+
try:
|
28
|
+
return int(retry_after_ms) / 1000 if retry_after_ms > 0 else 0
|
29
|
+
except Exception:
|
30
|
+
pass
|
31
|
+
|
32
|
+
retry_after = response_headers.get("retry-after")
|
33
|
+
if retry_after is None:
|
34
|
+
return None
|
35
|
+
|
36
|
+
# Attempt to parse the header as an int.
|
37
|
+
if re.match(r"^\s*[0-9]+\s*$", retry_after):
|
38
|
+
seconds = float(retry_after)
|
39
|
+
# Fallback to parsing it as a date.
|
40
|
+
else:
|
41
|
+
retry_date_tuple = email.utils.parsedate_tz(retry_after)
|
42
|
+
if retry_date_tuple is None:
|
43
|
+
return None
|
44
|
+
if retry_date_tuple[9] is None: # Python 2
|
45
|
+
# Assume UTC if no timezone was specified
|
46
|
+
# On Python2.7, parsedate_tz returns None for a timezone offset
|
47
|
+
# instead of 0 if no timezone is given, where mktime_tz treats
|
48
|
+
# a None timezone offset as local time.
|
49
|
+
retry_date_tuple = retry_date_tuple[:9] + (0,) + retry_date_tuple[10:]
|
50
|
+
|
51
|
+
retry_date = email.utils.mktime_tz(retry_date_tuple)
|
52
|
+
seconds = retry_date - time.time()
|
53
|
+
|
54
|
+
if seconds < 0:
|
55
|
+
seconds = 0
|
56
|
+
|
57
|
+
return seconds
|
58
|
+
|
59
|
+
|
60
|
+
def _retry_timeout(response: httpx.Response, retries: int) -> float:
|
61
|
+
"""
|
62
|
+
Determine the amount of time to wait before retrying a request.
|
63
|
+
This function begins by trying to parse a retry-after header from the response, and then proceeds to use exponential backoff
|
64
|
+
with a jitter to determine the number of seconds to wait.
|
65
|
+
"""
|
66
|
+
|
67
|
+
# If the API asks us to wait a certain amount of time (and it's a reasonable amount), just do what it says.
|
68
|
+
retry_after = _parse_retry_after(response.headers)
|
69
|
+
if retry_after is not None and retry_after <= MAX_RETRY_DELAY_SECONDS_FROM_HEADER:
|
70
|
+
return retry_after
|
71
|
+
|
72
|
+
# Apply exponential backoff, capped at MAX_RETRY_DELAY_SECONDS.
|
73
|
+
retry_delay = min(INITIAL_RETRY_DELAY_SECONDS * pow(2.0, retries), MAX_RETRY_DELAY_SECONDS)
|
74
|
+
|
75
|
+
# Add a randomness / jitter to the retry delay to avoid overwhelming the server with retries.
|
76
|
+
timeout = retry_delay * (1 - 0.25 * random())
|
77
|
+
return timeout if timeout >= 0 else 0
|
78
|
+
|
79
|
+
|
80
|
+
def _should_retry(response: httpx.Response) -> bool:
|
81
|
+
retriable_400s = [429, 408, 409]
|
82
|
+
return response.status_code >= 500 or response.status_code in retriable_400s
|
83
|
+
|
84
|
+
|
85
|
+
class HttpClient:
|
86
|
+
def __init__(self, *, httpx_client: httpx.Client):
|
87
|
+
self.httpx_client = httpx_client
|
88
|
+
|
89
|
+
# Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method
|
90
|
+
@wraps(httpx.Client.request)
|
91
|
+
def request(
|
92
|
+
self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any
|
93
|
+
) -> httpx.Response:
|
94
|
+
response = self.httpx_client.request(*args, **kwargs)
|
95
|
+
if _should_retry(response=response):
|
96
|
+
if max_retries > retries:
|
97
|
+
time.sleep(_retry_timeout(response=response, retries=retries))
|
98
|
+
return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs)
|
99
|
+
return response
|
100
|
+
|
101
|
+
@wraps(httpx.Client.stream)
|
102
|
+
@contextmanager
|
103
|
+
def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any:
|
104
|
+
with self.httpx_client.stream(*args, **kwargs) as stream:
|
105
|
+
yield stream
|
106
|
+
|
107
|
+
|
108
|
+
class AsyncHttpClient:
|
109
|
+
def __init__(self, *, httpx_client: httpx.AsyncClient):
|
110
|
+
self.httpx_client = httpx_client
|
111
|
+
|
112
|
+
# Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method
|
113
|
+
@wraps(httpx.AsyncClient.request)
|
114
|
+
async def request(
|
115
|
+
self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any
|
116
|
+
) -> httpx.Response:
|
117
|
+
response = await self.httpx_client.request(*args, **kwargs)
|
118
|
+
if _should_retry(response=response):
|
119
|
+
if max_retries > retries:
|
120
|
+
await asyncio.sleep(_retry_timeout(response=response, retries=retries))
|
121
|
+
return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs)
|
122
|
+
return response
|
123
|
+
|
124
|
+
@wraps(httpx.AsyncClient.stream)
|
125
|
+
@asynccontextmanager
|
126
|
+
async def stream(
|
127
|
+
self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any
|
128
|
+
) -> typing.Any:
|
129
|
+
async with self.httpx_client.stream(*args, **kwargs) as stream:
|
130
|
+
yield stream
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
"""
|
4
|
+
jsonable_encoder converts a Python object to a JSON-friendly dict
|
5
|
+
(e.g. datetimes to strings, Pydantic models to dicts).
|
6
|
+
|
7
|
+
Taken from FastAPI, and made a bit simpler
|
8
|
+
https://github.com/tiangolo/fastapi/blob/master/fastapi/encoders.py
|
9
|
+
"""
|
10
|
+
|
11
|
+
import dataclasses
|
12
|
+
import datetime as dt
|
13
|
+
from collections import defaultdict
|
14
|
+
from enum import Enum
|
15
|
+
from pathlib import PurePath
|
16
|
+
from types import GeneratorType
|
17
|
+
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
|
18
|
+
|
19
|
+
try:
|
20
|
+
import pydantic.v1 as pydantic # type: ignore
|
21
|
+
except ImportError:
|
22
|
+
import pydantic # type: ignore
|
23
|
+
|
24
|
+
from .datetime_utils import serialize_datetime
|
25
|
+
|
26
|
+
SetIntStr = Set[Union[int, str]]
|
27
|
+
DictIntStrAny = Dict[Union[int, str], Any]
|
28
|
+
|
29
|
+
|
30
|
+
def generate_encoders_by_class_tuples(
|
31
|
+
type_encoder_map: Dict[Any, Callable[[Any], Any]]
|
32
|
+
) -> Dict[Callable[[Any], Any], Tuple[Any, ...]]:
|
33
|
+
encoders_by_class_tuples: Dict[Callable[[Any], Any], Tuple[Any, ...]] = defaultdict(tuple)
|
34
|
+
for type_, encoder in type_encoder_map.items():
|
35
|
+
encoders_by_class_tuples[encoder] += (type_,)
|
36
|
+
return encoders_by_class_tuples
|
37
|
+
|
38
|
+
|
39
|
+
encoders_by_class_tuples = generate_encoders_by_class_tuples(pydantic.json.ENCODERS_BY_TYPE)
|
40
|
+
|
41
|
+
|
42
|
+
def jsonable_encoder(obj: Any, custom_encoder: Optional[Dict[Any, Callable[[Any], Any]]] = None) -> Any:
|
43
|
+
custom_encoder = custom_encoder or {}
|
44
|
+
if custom_encoder:
|
45
|
+
if type(obj) in custom_encoder:
|
46
|
+
return custom_encoder[type(obj)](obj)
|
47
|
+
else:
|
48
|
+
for encoder_type, encoder_instance in custom_encoder.items():
|
49
|
+
if isinstance(obj, encoder_type):
|
50
|
+
return encoder_instance(obj)
|
51
|
+
if isinstance(obj, pydantic.BaseModel):
|
52
|
+
encoder = getattr(obj.__config__, "json_encoders", {})
|
53
|
+
if custom_encoder:
|
54
|
+
encoder.update(custom_encoder)
|
55
|
+
obj_dict = obj.dict(by_alias=True)
|
56
|
+
if "__root__" in obj_dict:
|
57
|
+
obj_dict = obj_dict["__root__"]
|
58
|
+
return jsonable_encoder(obj_dict, custom_encoder=encoder)
|
59
|
+
if dataclasses.is_dataclass(obj):
|
60
|
+
obj_dict = dataclasses.asdict(obj)
|
61
|
+
return jsonable_encoder(obj_dict, custom_encoder=custom_encoder)
|
62
|
+
if isinstance(obj, Enum):
|
63
|
+
return obj.value
|
64
|
+
if isinstance(obj, PurePath):
|
65
|
+
return str(obj)
|
66
|
+
if isinstance(obj, (str, int, float, type(None))):
|
67
|
+
return obj
|
68
|
+
if isinstance(obj, dt.datetime):
|
69
|
+
return serialize_datetime(obj)
|
70
|
+
if isinstance(obj, dt.date):
|
71
|
+
return str(obj)
|
72
|
+
if isinstance(obj, dict):
|
73
|
+
encoded_dict = {}
|
74
|
+
allowed_keys = set(obj.keys())
|
75
|
+
for key, value in obj.items():
|
76
|
+
if key in allowed_keys:
|
77
|
+
encoded_key = jsonable_encoder(key, custom_encoder=custom_encoder)
|
78
|
+
encoded_value = jsonable_encoder(value, custom_encoder=custom_encoder)
|
79
|
+
encoded_dict[encoded_key] = encoded_value
|
80
|
+
return encoded_dict
|
81
|
+
if isinstance(obj, (list, set, frozenset, GeneratorType, tuple)):
|
82
|
+
encoded_list = []
|
83
|
+
for item in obj:
|
84
|
+
encoded_list.append(jsonable_encoder(item, custom_encoder=custom_encoder))
|
85
|
+
return encoded_list
|
86
|
+
|
87
|
+
if type(obj) in pydantic.json.ENCODERS_BY_TYPE:
|
88
|
+
return pydantic.json.ENCODERS_BY_TYPE[type(obj)](obj)
|
89
|
+
for encoder, classes_tuple in encoders_by_class_tuples.items():
|
90
|
+
if isinstance(obj, classes_tuple):
|
91
|
+
return encoder(obj)
|
92
|
+
|
93
|
+
try:
|
94
|
+
data = dict(obj)
|
95
|
+
except Exception as e:
|
96
|
+
errors: List[Exception] = []
|
97
|
+
errors.append(e)
|
98
|
+
try:
|
99
|
+
data = vars(obj)
|
100
|
+
except Exception as e:
|
101
|
+
errors.append(e)
|
102
|
+
raise ValueError(errors) from e
|
103
|
+
return jsonable_encoder(data, custom_encoder=custom_encoder)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from typing import Any, Dict, Optional
|
4
|
+
|
5
|
+
|
6
|
+
def remove_none_from_dict(original: Dict[str, Optional[Any]]) -> Dict[str, Any]:
|
7
|
+
new: Dict[str, Any] = {}
|
8
|
+
for key, value in original.items():
|
9
|
+
if value is not None:
|
10
|
+
new[key] = value
|
11
|
+
return new
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
import typing
|
4
|
+
|
5
|
+
try:
|
6
|
+
from typing import NotRequired # type: ignore
|
7
|
+
except ImportError:
|
8
|
+
from typing_extensions import NotRequired # type: ignore
|
9
|
+
|
10
|
+
|
11
|
+
class RequestOptions(typing.TypedDict):
|
12
|
+
"""
|
13
|
+
Additional options for request-specific configuration when calling APIs via the SDK.
|
14
|
+
This is used primarily as an optional final parameter for service functions.
|
15
|
+
|
16
|
+
Attributes:
|
17
|
+
- timeout_in_seconds: int. The number of seconds to await an API call before timing out.
|
18
|
+
|
19
|
+
- max_retries: int. The max number of retries to attempt if the API call fails.
|
20
|
+
|
21
|
+
- additional_headers: typing.Dict[str, typing.Any]. A dictionary containing additional parameters to spread into the request's header dict
|
22
|
+
|
23
|
+
- additional_query_parameters: typing.Dict[str, typing.Any]. A dictionary containing additional parameters to spread into the request's query parameters dict
|
24
|
+
|
25
|
+
- additional_body_parameters: typing.Dict[str, typing.Any]. A dictionary containing additional parameters to spread into the request's body parameters dict
|
26
|
+
"""
|
27
|
+
|
28
|
+
timeout_in_seconds: NotRequired[int]
|
29
|
+
max_retries: NotRequired[int]
|
30
|
+
additional_headers: NotRequired[typing.Dict[str, typing.Any]]
|
31
|
+
additional_query_parameters: NotRequired[typing.Dict[str, typing.Any]]
|
32
|
+
additional_body_parameters: NotRequired[typing.Dict[str, typing.Any]]
|
mixpeek/embed/client.py
ADDED
@@ -0,0 +1,350 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
import typing
|
4
|
+
import urllib.parse
|
5
|
+
from json.decoder import JSONDecodeError
|
6
|
+
|
7
|
+
from ..core.api_error import ApiError
|
8
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
9
|
+
from ..core.jsonable_encoder import jsonable_encoder
|
10
|
+
from ..core.remove_none_from_dict import remove_none_from_dict
|
11
|
+
from ..core.request_options import RequestOptions
|
12
|
+
from ..errors.bad_request_error import BadRequestError
|
13
|
+
from ..errors.forbidden_error import ForbiddenError
|
14
|
+
from ..errors.internal_server_error import InternalServerError
|
15
|
+
from ..errors.not_found_error import NotFoundError
|
16
|
+
from ..errors.unauthorized_error import UnauthorizedError
|
17
|
+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
18
|
+
from ..types.configs_response import ConfigsResponse
|
19
|
+
from ..types.embedding_response import EmbeddingResponse
|
20
|
+
from ..types.error_response import ErrorResponse
|
21
|
+
from ..types.http_validation_error import HttpValidationError
|
22
|
+
from ..types.modality import Modality
|
23
|
+
|
24
|
+
try:
|
25
|
+
import pydantic.v1 as pydantic # type: ignore
|
26
|
+
except ImportError:
|
27
|
+
import pydantic # type: ignore
|
28
|
+
|
29
|
+
# this is used as the default value for optional parameters
|
30
|
+
OMIT = typing.cast(typing.Any, ...)
|
31
|
+
|
32
|
+
|
33
|
+
class EmbedClient:
|
34
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
35
|
+
self._client_wrapper = client_wrapper
|
36
|
+
|
37
|
+
def get_dimensions(
|
38
|
+
self,
|
39
|
+
*,
|
40
|
+
modality: typing.Optional[Modality] = OMIT,
|
41
|
+
model: typing.Optional[str] = OMIT,
|
42
|
+
request_options: typing.Optional[RequestOptions] = None,
|
43
|
+
) -> ConfigsResponse:
|
44
|
+
"""
|
45
|
+
Parameters:
|
46
|
+
- modality: typing.Optional[Modality].
|
47
|
+
|
48
|
+
- model: typing.Optional[str].
|
49
|
+
|
50
|
+
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
|
51
|
+
---
|
52
|
+
from mixpeek.client import Mixpeek
|
53
|
+
|
54
|
+
client = Mixpeek(
|
55
|
+
authorization="YOUR_AUTHORIZATION",
|
56
|
+
index_id="YOUR_INDEX_ID",
|
57
|
+
api_key="YOUR_API_KEY",
|
58
|
+
)
|
59
|
+
client.embed.get_dimensions()
|
60
|
+
"""
|
61
|
+
_request: typing.Dict[str, typing.Any] = {}
|
62
|
+
if modality is not OMIT:
|
63
|
+
_request["modality"] = modality
|
64
|
+
if model is not OMIT:
|
65
|
+
_request["model"] = model
|
66
|
+
_response = self._client_wrapper.httpx_client.request(
|
67
|
+
"POST",
|
68
|
+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "embed/config"),
|
69
|
+
params=jsonable_encoder(
|
70
|
+
request_options.get("additional_query_parameters") if request_options is not None else None
|
71
|
+
),
|
72
|
+
json=jsonable_encoder(_request)
|
73
|
+
if request_options is None or request_options.get("additional_body_parameters") is None
|
74
|
+
else {
|
75
|
+
**jsonable_encoder(_request),
|
76
|
+
**(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
|
77
|
+
},
|
78
|
+
headers=jsonable_encoder(
|
79
|
+
remove_none_from_dict(
|
80
|
+
{
|
81
|
+
**self._client_wrapper.get_headers(),
|
82
|
+
**(request_options.get("additional_headers", {}) if request_options is not None else {}),
|
83
|
+
}
|
84
|
+
)
|
85
|
+
),
|
86
|
+
timeout=request_options.get("timeout_in_seconds")
|
87
|
+
if request_options is not None and request_options.get("timeout_in_seconds") is not None
|
88
|
+
else self._client_wrapper.get_timeout(),
|
89
|
+
retries=0,
|
90
|
+
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
|
91
|
+
)
|
92
|
+
if 200 <= _response.status_code < 300:
|
93
|
+
return pydantic.parse_obj_as(ConfigsResponse, _response.json()) # type: ignore
|
94
|
+
if _response.status_code == 400:
|
95
|
+
raise BadRequestError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
96
|
+
if _response.status_code == 401:
|
97
|
+
raise UnauthorizedError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
98
|
+
if _response.status_code == 403:
|
99
|
+
raise ForbiddenError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
100
|
+
if _response.status_code == 404:
|
101
|
+
raise NotFoundError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
102
|
+
if _response.status_code == 422:
|
103
|
+
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
104
|
+
if _response.status_code == 500:
|
105
|
+
raise InternalServerError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
106
|
+
try:
|
107
|
+
_response_json = _response.json()
|
108
|
+
except JSONDecodeError:
|
109
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
110
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
111
|
+
|
112
|
+
def input_embed_post(
|
113
|
+
self,
|
114
|
+
*,
|
115
|
+
input: str,
|
116
|
+
modality: typing.Optional[Modality] = OMIT,
|
117
|
+
model: typing.Optional[str] = OMIT,
|
118
|
+
request_options: typing.Optional[RequestOptions] = None,
|
119
|
+
) -> EmbeddingResponse:
|
120
|
+
"""
|
121
|
+
Parameters:
|
122
|
+
- input: str.
|
123
|
+
|
124
|
+
- modality: typing.Optional[Modality].
|
125
|
+
|
126
|
+
- model: typing.Optional[str].
|
127
|
+
|
128
|
+
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
|
129
|
+
---
|
130
|
+
from mixpeek.client import Mixpeek
|
131
|
+
|
132
|
+
client = Mixpeek(
|
133
|
+
authorization="YOUR_AUTHORIZATION",
|
134
|
+
index_id="YOUR_INDEX_ID",
|
135
|
+
api_key="YOUR_API_KEY",
|
136
|
+
)
|
137
|
+
client.embed.input_embed_post(
|
138
|
+
input="input",
|
139
|
+
)
|
140
|
+
"""
|
141
|
+
_request: typing.Dict[str, typing.Any] = {"input": input}
|
142
|
+
if modality is not OMIT:
|
143
|
+
_request["modality"] = modality
|
144
|
+
if model is not OMIT:
|
145
|
+
_request["model"] = model
|
146
|
+
_response = self._client_wrapper.httpx_client.request(
|
147
|
+
"POST",
|
148
|
+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "embed"),
|
149
|
+
params=jsonable_encoder(
|
150
|
+
request_options.get("additional_query_parameters") if request_options is not None else None
|
151
|
+
),
|
152
|
+
json=jsonable_encoder(_request)
|
153
|
+
if request_options is None or request_options.get("additional_body_parameters") is None
|
154
|
+
else {
|
155
|
+
**jsonable_encoder(_request),
|
156
|
+
**(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
|
157
|
+
},
|
158
|
+
headers=jsonable_encoder(
|
159
|
+
remove_none_from_dict(
|
160
|
+
{
|
161
|
+
**self._client_wrapper.get_headers(),
|
162
|
+
**(request_options.get("additional_headers", {}) if request_options is not None else {}),
|
163
|
+
}
|
164
|
+
)
|
165
|
+
),
|
166
|
+
timeout=request_options.get("timeout_in_seconds")
|
167
|
+
if request_options is not None and request_options.get("timeout_in_seconds") is not None
|
168
|
+
else self._client_wrapper.get_timeout(),
|
169
|
+
retries=0,
|
170
|
+
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
|
171
|
+
)
|
172
|
+
if 200 <= _response.status_code < 300:
|
173
|
+
return pydantic.parse_obj_as(EmbeddingResponse, _response.json()) # type: ignore
|
174
|
+
if _response.status_code == 400:
|
175
|
+
raise BadRequestError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
176
|
+
if _response.status_code == 401:
|
177
|
+
raise UnauthorizedError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
178
|
+
if _response.status_code == 403:
|
179
|
+
raise ForbiddenError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
180
|
+
if _response.status_code == 404:
|
181
|
+
raise NotFoundError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
182
|
+
if _response.status_code == 422:
|
183
|
+
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
184
|
+
if _response.status_code == 500:
|
185
|
+
raise InternalServerError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
186
|
+
try:
|
187
|
+
_response_json = _response.json()
|
188
|
+
except JSONDecodeError:
|
189
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
190
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
191
|
+
|
192
|
+
|
193
|
+
class AsyncEmbedClient:
|
194
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
195
|
+
self._client_wrapper = client_wrapper
|
196
|
+
|
197
|
+
async def get_dimensions(
|
198
|
+
self,
|
199
|
+
*,
|
200
|
+
modality: typing.Optional[Modality] = OMIT,
|
201
|
+
model: typing.Optional[str] = OMIT,
|
202
|
+
request_options: typing.Optional[RequestOptions] = None,
|
203
|
+
) -> ConfigsResponse:
|
204
|
+
"""
|
205
|
+
Parameters:
|
206
|
+
- modality: typing.Optional[Modality].
|
207
|
+
|
208
|
+
- model: typing.Optional[str].
|
209
|
+
|
210
|
+
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
|
211
|
+
---
|
212
|
+
from mixpeek.client import AsyncMixpeek
|
213
|
+
|
214
|
+
client = AsyncMixpeek(
|
215
|
+
authorization="YOUR_AUTHORIZATION",
|
216
|
+
index_id="YOUR_INDEX_ID",
|
217
|
+
api_key="YOUR_API_KEY",
|
218
|
+
)
|
219
|
+
await client.embed.get_dimensions()
|
220
|
+
"""
|
221
|
+
_request: typing.Dict[str, typing.Any] = {}
|
222
|
+
if modality is not OMIT:
|
223
|
+
_request["modality"] = modality
|
224
|
+
if model is not OMIT:
|
225
|
+
_request["model"] = model
|
226
|
+
_response = await self._client_wrapper.httpx_client.request(
|
227
|
+
"POST",
|
228
|
+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "embed/config"),
|
229
|
+
params=jsonable_encoder(
|
230
|
+
request_options.get("additional_query_parameters") if request_options is not None else None
|
231
|
+
),
|
232
|
+
json=jsonable_encoder(_request)
|
233
|
+
if request_options is None or request_options.get("additional_body_parameters") is None
|
234
|
+
else {
|
235
|
+
**jsonable_encoder(_request),
|
236
|
+
**(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
|
237
|
+
},
|
238
|
+
headers=jsonable_encoder(
|
239
|
+
remove_none_from_dict(
|
240
|
+
{
|
241
|
+
**self._client_wrapper.get_headers(),
|
242
|
+
**(request_options.get("additional_headers", {}) if request_options is not None else {}),
|
243
|
+
}
|
244
|
+
)
|
245
|
+
),
|
246
|
+
timeout=request_options.get("timeout_in_seconds")
|
247
|
+
if request_options is not None and request_options.get("timeout_in_seconds") is not None
|
248
|
+
else self._client_wrapper.get_timeout(),
|
249
|
+
retries=0,
|
250
|
+
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
|
251
|
+
)
|
252
|
+
if 200 <= _response.status_code < 300:
|
253
|
+
return pydantic.parse_obj_as(ConfigsResponse, _response.json()) # type: ignore
|
254
|
+
if _response.status_code == 400:
|
255
|
+
raise BadRequestError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
256
|
+
if _response.status_code == 401:
|
257
|
+
raise UnauthorizedError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
258
|
+
if _response.status_code == 403:
|
259
|
+
raise ForbiddenError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
260
|
+
if _response.status_code == 404:
|
261
|
+
raise NotFoundError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
262
|
+
if _response.status_code == 422:
|
263
|
+
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
264
|
+
if _response.status_code == 500:
|
265
|
+
raise InternalServerError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
266
|
+
try:
|
267
|
+
_response_json = _response.json()
|
268
|
+
except JSONDecodeError:
|
269
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
270
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
271
|
+
|
272
|
+
async def input_embed_post(
|
273
|
+
self,
|
274
|
+
*,
|
275
|
+
input: str,
|
276
|
+
modality: typing.Optional[Modality] = OMIT,
|
277
|
+
model: typing.Optional[str] = OMIT,
|
278
|
+
request_options: typing.Optional[RequestOptions] = None,
|
279
|
+
) -> EmbeddingResponse:
|
280
|
+
"""
|
281
|
+
Parameters:
|
282
|
+
- input: str.
|
283
|
+
|
284
|
+
- modality: typing.Optional[Modality].
|
285
|
+
|
286
|
+
- model: typing.Optional[str].
|
287
|
+
|
288
|
+
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
|
289
|
+
---
|
290
|
+
from mixpeek.client import AsyncMixpeek
|
291
|
+
|
292
|
+
client = AsyncMixpeek(
|
293
|
+
authorization="YOUR_AUTHORIZATION",
|
294
|
+
index_id="YOUR_INDEX_ID",
|
295
|
+
api_key="YOUR_API_KEY",
|
296
|
+
)
|
297
|
+
await client.embed.input_embed_post(
|
298
|
+
input="input",
|
299
|
+
)
|
300
|
+
"""
|
301
|
+
_request: typing.Dict[str, typing.Any] = {"input": input}
|
302
|
+
if modality is not OMIT:
|
303
|
+
_request["modality"] = modality
|
304
|
+
if model is not OMIT:
|
305
|
+
_request["model"] = model
|
306
|
+
_response = await self._client_wrapper.httpx_client.request(
|
307
|
+
"POST",
|
308
|
+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "embed"),
|
309
|
+
params=jsonable_encoder(
|
310
|
+
request_options.get("additional_query_parameters") if request_options is not None else None
|
311
|
+
),
|
312
|
+
json=jsonable_encoder(_request)
|
313
|
+
if request_options is None or request_options.get("additional_body_parameters") is None
|
314
|
+
else {
|
315
|
+
**jsonable_encoder(_request),
|
316
|
+
**(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
|
317
|
+
},
|
318
|
+
headers=jsonable_encoder(
|
319
|
+
remove_none_from_dict(
|
320
|
+
{
|
321
|
+
**self._client_wrapper.get_headers(),
|
322
|
+
**(request_options.get("additional_headers", {}) if request_options is not None else {}),
|
323
|
+
}
|
324
|
+
)
|
325
|
+
),
|
326
|
+
timeout=request_options.get("timeout_in_seconds")
|
327
|
+
if request_options is not None and request_options.get("timeout_in_seconds") is not None
|
328
|
+
else self._client_wrapper.get_timeout(),
|
329
|
+
retries=0,
|
330
|
+
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
|
331
|
+
)
|
332
|
+
if 200 <= _response.status_code < 300:
|
333
|
+
return pydantic.parse_obj_as(EmbeddingResponse, _response.json()) # type: ignore
|
334
|
+
if _response.status_code == 400:
|
335
|
+
raise BadRequestError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
336
|
+
if _response.status_code == 401:
|
337
|
+
raise UnauthorizedError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
338
|
+
if _response.status_code == 403:
|
339
|
+
raise ForbiddenError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
340
|
+
if _response.status_code == 404:
|
341
|
+
raise NotFoundError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
342
|
+
if _response.status_code == 422:
|
343
|
+
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
344
|
+
if _response.status_code == 500:
|
345
|
+
raise InternalServerError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
346
|
+
try:
|
347
|
+
_response_json = _response.json()
|
348
|
+
except JSONDecodeError:
|
349
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
350
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
mixpeek/environment.py
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from .bad_request_error import BadRequestError
|
4
|
+
from .forbidden_error import ForbiddenError
|
5
|
+
from .internal_server_error import InternalServerError
|
6
|
+
from .not_found_error import NotFoundError
|
7
|
+
from .unauthorized_error import UnauthorizedError
|
8
|
+
from .unprocessable_entity_error import UnprocessableEntityError
|
9
|
+
|
10
|
+
__all__ = [
|
11
|
+
"BadRequestError",
|
12
|
+
"ForbiddenError",
|
13
|
+
"InternalServerError",
|
14
|
+
"NotFoundError",
|
15
|
+
"UnauthorizedError",
|
16
|
+
"UnprocessableEntityError",
|
17
|
+
]
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from ..core.api_error import ApiError
|
4
|
+
from ..types.error_response import ErrorResponse
|
5
|
+
|
6
|
+
|
7
|
+
class BadRequestError(ApiError):
|
8
|
+
def __init__(self, body: ErrorResponse):
|
9
|
+
super().__init__(status_code=400, body=body)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from ..core.api_error import ApiError
|
4
|
+
from ..types.error_response import ErrorResponse
|
5
|
+
|
6
|
+
|
7
|
+
class ForbiddenError(ApiError):
|
8
|
+
def __init__(self, body: ErrorResponse):
|
9
|
+
super().__init__(status_code=403, body=body)
|