mixpeek 0.1.0__py3-none-any.whl → 0.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mixpeek/__init__.py +95 -71
- mixpeek/base_client.py +128 -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/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/generators/__init__.py +2 -0
- mixpeek/generators/client.py +239 -0
- mixpeek/parse/__init__.py +2 -0
- mixpeek/parse/client.py +349 -0
- mixpeek/parse_client.py +14 -0
- mixpeek/pipelines/__init__.py +2 -0
- mixpeek/pipelines/client.py +546 -0
- mixpeek/py.typed +0 -0
- mixpeek/storage/__init__.py +2 -0
- mixpeek/storage/client.py +254 -0
- mixpeek/types/__init__.py +73 -0
- mixpeek/types/audio_params.py +29 -0
- mixpeek/types/configs_request.py +31 -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_schema.py +31 -0
- mixpeek/types/embedding_request.py +32 -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_schema.py +33 -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 +30 -0
- mixpeek/types/pdf_params.py +41 -0
- mixpeek/types/pipeline_response.py +39 -0
- mixpeek/types/ppt_params.py +27 -0
- mixpeek/types/pptx_params.py +27 -0
- mixpeek/types/settings.py +35 -0
- mixpeek/types/source_schema.py +32 -0
- mixpeek/types/txt_params.py +27 -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/version.py +4 -0
- mixpeek/workflows/__init__.py +2 -0
- mixpeek/workflows/client.py +418 -0
- mixpeek-0.1.0.dist-info/LICENSE.rst → mixpeek-0.6.1.dist-info/LICENSE +10 -9
- mixpeek-0.6.1.dist-info/METADATA +145 -0
- mixpeek-0.6.1.dist-info/RECORD +71 -0
- {mixpeek-0.1.0.dist-info → mixpeek-0.6.1.dist-info}/WHEEL +1 -1
- mixpeek-0.1.0.dist-info/METADATA +0 -211
- mixpeek-0.1.0.dist-info/RECORD +0 -5
@@ -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]]
|
@@ -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)
|
@@ -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 InternalServerError(ApiError):
|
8
|
+
def __init__(self, body: ErrorResponse):
|
9
|
+
super().__init__(status_code=500, 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 NotFoundError(ApiError):
|
8
|
+
def __init__(self, body: ErrorResponse):
|
9
|
+
super().__init__(status_code=404, 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 UnauthorizedError(ApiError):
|
8
|
+
def __init__(self, body: ErrorResponse):
|
9
|
+
super().__init__(status_code=401, 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.http_validation_error import HttpValidationError
|
5
|
+
|
6
|
+
|
7
|
+
class UnprocessableEntityError(ApiError):
|
8
|
+
def __init__(self, body: HttpValidationError):
|
9
|
+
super().__init__(status_code=422, body=body)
|
@@ -0,0 +1,239 @@
|
|
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.error_response import ErrorResponse
|
19
|
+
from ..types.generation_response import GenerationResponse
|
20
|
+
from ..types.http_validation_error import HttpValidationError
|
21
|
+
from ..types.message import Message
|
22
|
+
from ..types.model import Model
|
23
|
+
from ..types.settings import Settings
|
24
|
+
|
25
|
+
try:
|
26
|
+
import pydantic.v1 as pydantic # type: ignore
|
27
|
+
except ImportError:
|
28
|
+
import pydantic # type: ignore
|
29
|
+
|
30
|
+
# this is used as the default value for optional parameters
|
31
|
+
OMIT = typing.cast(typing.Any, ...)
|
32
|
+
|
33
|
+
|
34
|
+
class GeneratorsClient:
|
35
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
36
|
+
self._client_wrapper = client_wrapper
|
37
|
+
|
38
|
+
def generate(
|
39
|
+
self,
|
40
|
+
*,
|
41
|
+
model: Model,
|
42
|
+
response_format: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
|
43
|
+
context: typing.Optional[str] = OMIT,
|
44
|
+
messages: typing.Sequence[Message],
|
45
|
+
settings: typing.Optional[Settings] = OMIT,
|
46
|
+
request_options: typing.Optional[RequestOptions] = None,
|
47
|
+
) -> GenerationResponse:
|
48
|
+
"""
|
49
|
+
Parameters:
|
50
|
+
- model: Model.
|
51
|
+
|
52
|
+
- response_format: typing.Optional[typing.Dict[str, typing.Any]].
|
53
|
+
|
54
|
+
- context: typing.Optional[str].
|
55
|
+
|
56
|
+
- messages: typing.Sequence[Message].
|
57
|
+
|
58
|
+
- settings: typing.Optional[Settings].
|
59
|
+
|
60
|
+
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
|
61
|
+
---
|
62
|
+
from mixpeek import Message, Model
|
63
|
+
from mixpeek.client import Mixpeek
|
64
|
+
|
65
|
+
client = Mixpeek(
|
66
|
+
authorization="YOUR_AUTHORIZATION",
|
67
|
+
index_id="YOUR_INDEX_ID",
|
68
|
+
api_key="YOUR_API_KEY",
|
69
|
+
base_url="https://yourhost.com/path/to/api",
|
70
|
+
)
|
71
|
+
client.generators.generate(
|
72
|
+
model=Model(
|
73
|
+
provider="provider",
|
74
|
+
model="model",
|
75
|
+
),
|
76
|
+
messages=[
|
77
|
+
Message(
|
78
|
+
role="role",
|
79
|
+
content="content",
|
80
|
+
)
|
81
|
+
],
|
82
|
+
)
|
83
|
+
"""
|
84
|
+
_request: typing.Dict[str, typing.Any] = {"model": model, "messages": messages}
|
85
|
+
if response_format is not OMIT:
|
86
|
+
_request["response_format"] = response_format
|
87
|
+
if context is not OMIT:
|
88
|
+
_request["context"] = context
|
89
|
+
if settings is not OMIT:
|
90
|
+
_request["settings"] = settings
|
91
|
+
_response = self._client_wrapper.httpx_client.request(
|
92
|
+
"POST",
|
93
|
+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "generate"),
|
94
|
+
params=jsonable_encoder(
|
95
|
+
request_options.get("additional_query_parameters") if request_options is not None else None
|
96
|
+
),
|
97
|
+
json=jsonable_encoder(_request)
|
98
|
+
if request_options is None or request_options.get("additional_body_parameters") is None
|
99
|
+
else {
|
100
|
+
**jsonable_encoder(_request),
|
101
|
+
**(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
|
102
|
+
},
|
103
|
+
headers=jsonable_encoder(
|
104
|
+
remove_none_from_dict(
|
105
|
+
{
|
106
|
+
**self._client_wrapper.get_headers(),
|
107
|
+
**(request_options.get("additional_headers", {}) if request_options is not None else {}),
|
108
|
+
}
|
109
|
+
)
|
110
|
+
),
|
111
|
+
timeout=request_options.get("timeout_in_seconds")
|
112
|
+
if request_options is not None and request_options.get("timeout_in_seconds") is not None
|
113
|
+
else self._client_wrapper.get_timeout(),
|
114
|
+
retries=0,
|
115
|
+
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
|
116
|
+
)
|
117
|
+
if 200 <= _response.status_code < 300:
|
118
|
+
return pydantic.parse_obj_as(GenerationResponse, _response.json()) # type: ignore
|
119
|
+
if _response.status_code == 400:
|
120
|
+
raise BadRequestError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
121
|
+
if _response.status_code == 401:
|
122
|
+
raise UnauthorizedError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
123
|
+
if _response.status_code == 403:
|
124
|
+
raise ForbiddenError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
125
|
+
if _response.status_code == 404:
|
126
|
+
raise NotFoundError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
127
|
+
if _response.status_code == 422:
|
128
|
+
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
129
|
+
if _response.status_code == 500:
|
130
|
+
raise InternalServerError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
131
|
+
try:
|
132
|
+
_response_json = _response.json()
|
133
|
+
except JSONDecodeError:
|
134
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
135
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
136
|
+
|
137
|
+
|
138
|
+
class AsyncGeneratorsClient:
|
139
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
140
|
+
self._client_wrapper = client_wrapper
|
141
|
+
|
142
|
+
async def generate(
|
143
|
+
self,
|
144
|
+
*,
|
145
|
+
model: Model,
|
146
|
+
response_format: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
|
147
|
+
context: typing.Optional[str] = OMIT,
|
148
|
+
messages: typing.Sequence[Message],
|
149
|
+
settings: typing.Optional[Settings] = OMIT,
|
150
|
+
request_options: typing.Optional[RequestOptions] = None,
|
151
|
+
) -> GenerationResponse:
|
152
|
+
"""
|
153
|
+
Parameters:
|
154
|
+
- model: Model.
|
155
|
+
|
156
|
+
- response_format: typing.Optional[typing.Dict[str, typing.Any]].
|
157
|
+
|
158
|
+
- context: typing.Optional[str].
|
159
|
+
|
160
|
+
- messages: typing.Sequence[Message].
|
161
|
+
|
162
|
+
- settings: typing.Optional[Settings].
|
163
|
+
|
164
|
+
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
|
165
|
+
---
|
166
|
+
from mixpeek import Message, Model
|
167
|
+
from mixpeek.client import AsyncMixpeek
|
168
|
+
|
169
|
+
client = AsyncMixpeek(
|
170
|
+
authorization="YOUR_AUTHORIZATION",
|
171
|
+
index_id="YOUR_INDEX_ID",
|
172
|
+
api_key="YOUR_API_KEY",
|
173
|
+
base_url="https://yourhost.com/path/to/api",
|
174
|
+
)
|
175
|
+
await client.generators.generate(
|
176
|
+
model=Model(
|
177
|
+
provider="provider",
|
178
|
+
model="model",
|
179
|
+
),
|
180
|
+
messages=[
|
181
|
+
Message(
|
182
|
+
role="role",
|
183
|
+
content="content",
|
184
|
+
)
|
185
|
+
],
|
186
|
+
)
|
187
|
+
"""
|
188
|
+
_request: typing.Dict[str, typing.Any] = {"model": model, "messages": messages}
|
189
|
+
if response_format is not OMIT:
|
190
|
+
_request["response_format"] = response_format
|
191
|
+
if context is not OMIT:
|
192
|
+
_request["context"] = context
|
193
|
+
if settings is not OMIT:
|
194
|
+
_request["settings"] = settings
|
195
|
+
_response = await self._client_wrapper.httpx_client.request(
|
196
|
+
"POST",
|
197
|
+
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "generate"),
|
198
|
+
params=jsonable_encoder(
|
199
|
+
request_options.get("additional_query_parameters") if request_options is not None else None
|
200
|
+
),
|
201
|
+
json=jsonable_encoder(_request)
|
202
|
+
if request_options is None or request_options.get("additional_body_parameters") is None
|
203
|
+
else {
|
204
|
+
**jsonable_encoder(_request),
|
205
|
+
**(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))),
|
206
|
+
},
|
207
|
+
headers=jsonable_encoder(
|
208
|
+
remove_none_from_dict(
|
209
|
+
{
|
210
|
+
**self._client_wrapper.get_headers(),
|
211
|
+
**(request_options.get("additional_headers", {}) if request_options is not None else {}),
|
212
|
+
}
|
213
|
+
)
|
214
|
+
),
|
215
|
+
timeout=request_options.get("timeout_in_seconds")
|
216
|
+
if request_options is not None and request_options.get("timeout_in_seconds") is not None
|
217
|
+
else self._client_wrapper.get_timeout(),
|
218
|
+
retries=0,
|
219
|
+
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
|
220
|
+
)
|
221
|
+
if 200 <= _response.status_code < 300:
|
222
|
+
return pydantic.parse_obj_as(GenerationResponse, _response.json()) # type: ignore
|
223
|
+
if _response.status_code == 400:
|
224
|
+
raise BadRequestError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
225
|
+
if _response.status_code == 401:
|
226
|
+
raise UnauthorizedError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
227
|
+
if _response.status_code == 403:
|
228
|
+
raise ForbiddenError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
229
|
+
if _response.status_code == 404:
|
230
|
+
raise NotFoundError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
231
|
+
if _response.status_code == 422:
|
232
|
+
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
233
|
+
if _response.status_code == 500:
|
234
|
+
raise InternalServerError(pydantic.parse_obj_as(ErrorResponse, _response.json())) # type: ignore
|
235
|
+
try:
|
236
|
+
_response_json = _response.json()
|
237
|
+
except JSONDecodeError:
|
238
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
239
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|