vellum-ai 0.0.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.
- vellum/__init__.py +98 -0
- vellum/client.py +203 -0
- vellum/core/__init__.py +8 -0
- vellum/core/api_error.py +15 -0
- vellum/core/datetime_utils.py +28 -0
- vellum/core/jsonable_encoder.py +94 -0
- vellum/core/remove_none_from_headers.py +11 -0
- vellum/environment.py +17 -0
- vellum/py.typed +0 -0
- vellum/resources/__init__.py +5 -0
- vellum/resources/documents/__init__.py +2 -0
- vellum/resources/documents/client.py +135 -0
- vellum/resources/model_versions/__init__.py +2 -0
- vellum/resources/model_versions/client.py +53 -0
- vellum/types/__init__.py +91 -0
- vellum/types/block_type_enum.py +29 -0
- vellum/types/chat_role_enum.py +25 -0
- vellum/types/document.py +30 -0
- vellum/types/document_document_to_document_index.py +31 -0
- vellum/types/enriched_normalized_completion.py +39 -0
- vellum/types/finish_reason_enum.py +25 -0
- vellum/types/generate_error_response.py +24 -0
- vellum/types/generate_options_request.py +27 -0
- vellum/types/generate_request_request.py +31 -0
- vellum/types/generate_response.py +39 -0
- vellum/types/generate_result.py +35 -0
- vellum/types/generate_result_data.py +27 -0
- vellum/types/generate_result_error.py +24 -0
- vellum/types/indexing_state_enum.py +33 -0
- vellum/types/logprobs_enum.py +17 -0
- vellum/types/model_type_enum.py +17 -0
- vellum/types/model_version_build_config.py +34 -0
- vellum/types/model_version_exec_config_parameters.py +31 -0
- vellum/types/model_version_exec_config_read.py +35 -0
- vellum/types/model_version_read.py +43 -0
- vellum/types/model_version_read_status_enum.py +29 -0
- vellum/types/model_version_sandbox_snapshot.py +25 -0
- vellum/types/normalized_log_probs.py +26 -0
- vellum/types/normalized_token_log_probs.py +27 -0
- vellum/types/paginated_slim_document_list.py +28 -0
- vellum/types/processing_state_enum.py +29 -0
- vellum/types/prompt_template_block.py +27 -0
- vellum/types/prompt_template_block_data.py +26 -0
- vellum/types/prompt_template_block_properties.py +28 -0
- vellum/types/provider_enum.py +37 -0
- vellum/types/search_error_response.py +24 -0
- vellum/types/search_filters_request.py +26 -0
- vellum/types/search_request_options_request.py +36 -0
- vellum/types/search_response.py +27 -0
- vellum/types/search_result.py +30 -0
- vellum/types/search_result_merging_request.py +24 -0
- vellum/types/search_weights_request.py +25 -0
- vellum/types/slim_document.py +44 -0
- vellum/types/slim_document_status_enum.py +14 -0
- vellum/types/submit_completion_actual_request.py +46 -0
- vellum/types/submit_completion_actuals_error_response.py +24 -0
- vellum/types/upload_document_error_response.py +24 -0
- vellum/types/upload_document_response.py +24 -0
- vellum_ai-0.0.1.dist-info/METADATA +15 -0
- vellum_ai-0.0.1.dist-info/RECORD +61 -0
- vellum_ai-0.0.1.dist-info/WHEEL +4 -0
vellum/__init__.py
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from .environment import VellumEnvironment
|
4
|
+
from .resources import documents, model_versions
|
5
|
+
from .types import (
|
6
|
+
BlockTypeEnum,
|
7
|
+
ChatRoleEnum,
|
8
|
+
Document,
|
9
|
+
DocumentDocumentToDocumentIndex,
|
10
|
+
EnrichedNormalizedCompletion,
|
11
|
+
FinishReasonEnum,
|
12
|
+
GenerateErrorResponse,
|
13
|
+
GenerateOptionsRequest,
|
14
|
+
GenerateRequestRequest,
|
15
|
+
GenerateResponse,
|
16
|
+
GenerateResult,
|
17
|
+
GenerateResultData,
|
18
|
+
GenerateResultError,
|
19
|
+
IndexingStateEnum,
|
20
|
+
LogprobsEnum,
|
21
|
+
ModelTypeEnum,
|
22
|
+
ModelVersionBuildConfig,
|
23
|
+
ModelVersionExecConfigParameters,
|
24
|
+
ModelVersionExecConfigRead,
|
25
|
+
ModelVersionRead,
|
26
|
+
ModelVersionReadStatusEnum,
|
27
|
+
ModelVersionSandboxSnapshot,
|
28
|
+
NormalizedLogProbs,
|
29
|
+
NormalizedTokenLogProbs,
|
30
|
+
PaginatedSlimDocumentList,
|
31
|
+
ProcessingStateEnum,
|
32
|
+
PromptTemplateBlock,
|
33
|
+
PromptTemplateBlockData,
|
34
|
+
PromptTemplateBlockProperties,
|
35
|
+
ProviderEnum,
|
36
|
+
SearchErrorResponse,
|
37
|
+
SearchFiltersRequest,
|
38
|
+
SearchRequestOptionsRequest,
|
39
|
+
SearchResponse,
|
40
|
+
SearchResult,
|
41
|
+
SearchResultMergingRequest,
|
42
|
+
SearchWeightsRequest,
|
43
|
+
SlimDocument,
|
44
|
+
SlimDocumentStatusEnum,
|
45
|
+
SubmitCompletionActualRequest,
|
46
|
+
SubmitCompletionActualsErrorResponse,
|
47
|
+
UploadDocumentErrorResponse,
|
48
|
+
UploadDocumentResponse,
|
49
|
+
)
|
50
|
+
|
51
|
+
__all__ = [
|
52
|
+
"BlockTypeEnum",
|
53
|
+
"ChatRoleEnum",
|
54
|
+
"Document",
|
55
|
+
"DocumentDocumentToDocumentIndex",
|
56
|
+
"EnrichedNormalizedCompletion",
|
57
|
+
"FinishReasonEnum",
|
58
|
+
"GenerateErrorResponse",
|
59
|
+
"GenerateOptionsRequest",
|
60
|
+
"GenerateRequestRequest",
|
61
|
+
"GenerateResponse",
|
62
|
+
"GenerateResult",
|
63
|
+
"GenerateResultData",
|
64
|
+
"GenerateResultError",
|
65
|
+
"IndexingStateEnum",
|
66
|
+
"LogprobsEnum",
|
67
|
+
"ModelTypeEnum",
|
68
|
+
"ModelVersionBuildConfig",
|
69
|
+
"ModelVersionExecConfigParameters",
|
70
|
+
"ModelVersionExecConfigRead",
|
71
|
+
"ModelVersionRead",
|
72
|
+
"ModelVersionReadStatusEnum",
|
73
|
+
"ModelVersionSandboxSnapshot",
|
74
|
+
"NormalizedLogProbs",
|
75
|
+
"NormalizedTokenLogProbs",
|
76
|
+
"PaginatedSlimDocumentList",
|
77
|
+
"ProcessingStateEnum",
|
78
|
+
"PromptTemplateBlock",
|
79
|
+
"PromptTemplateBlockData",
|
80
|
+
"PromptTemplateBlockProperties",
|
81
|
+
"ProviderEnum",
|
82
|
+
"SearchErrorResponse",
|
83
|
+
"SearchFiltersRequest",
|
84
|
+
"SearchRequestOptionsRequest",
|
85
|
+
"SearchResponse",
|
86
|
+
"SearchResult",
|
87
|
+
"SearchResultMergingRequest",
|
88
|
+
"SearchWeightsRequest",
|
89
|
+
"SlimDocument",
|
90
|
+
"SlimDocumentStatusEnum",
|
91
|
+
"SubmitCompletionActualRequest",
|
92
|
+
"SubmitCompletionActualsErrorResponse",
|
93
|
+
"UploadDocumentErrorResponse",
|
94
|
+
"UploadDocumentResponse",
|
95
|
+
"VellumEnvironment",
|
96
|
+
"documents",
|
97
|
+
"model_versions",
|
98
|
+
]
|
vellum/client.py
ADDED
@@ -0,0 +1,203 @@
|
|
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
|
+
import httpx
|
8
|
+
import pydantic
|
9
|
+
from backports.cached_property import cached_property
|
10
|
+
|
11
|
+
from .core.api_error import ApiError
|
12
|
+
from .core.jsonable_encoder import jsonable_encoder
|
13
|
+
from .core.remove_none_from_headers import remove_none_from_headers
|
14
|
+
from .environment import VellumEnvironment
|
15
|
+
from .resources.documents.client import AsyncDocumentsClient, DocumentsClient
|
16
|
+
from .resources.model_versions.client import AsyncModelVersionsClient, ModelVersionsClient
|
17
|
+
from .types.generate_options_request import GenerateOptionsRequest
|
18
|
+
from .types.generate_request_request import GenerateRequestRequest
|
19
|
+
from .types.generate_response import GenerateResponse
|
20
|
+
from .types.search_request_options_request import SearchRequestOptionsRequest
|
21
|
+
from .types.search_response import SearchResponse
|
22
|
+
from .types.submit_completion_actual_request import SubmitCompletionActualRequest
|
23
|
+
|
24
|
+
|
25
|
+
class Vellum:
|
26
|
+
def __init__(self, *, environment: VellumEnvironment = VellumEnvironment.PRODUCTION, api_key: str):
|
27
|
+
self._environment = environment
|
28
|
+
self.api_key = api_key
|
29
|
+
|
30
|
+
def generate(
|
31
|
+
self,
|
32
|
+
*,
|
33
|
+
deployment_id: typing.Optional[str] = None,
|
34
|
+
deployment_name: typing.Optional[str] = None,
|
35
|
+
requests: typing.List[GenerateRequestRequest],
|
36
|
+
options: typing.Optional[GenerateOptionsRequest] = None,
|
37
|
+
) -> GenerateResponse:
|
38
|
+
_response = httpx.request(
|
39
|
+
"POST",
|
40
|
+
urllib.parse.urljoin(f"{self._environment.predict}/", "v1/generate"),
|
41
|
+
json=jsonable_encoder(
|
42
|
+
{
|
43
|
+
"deployment_id": deployment_id,
|
44
|
+
"deployment_name": deployment_name,
|
45
|
+
"requests": requests,
|
46
|
+
"options": options,
|
47
|
+
}
|
48
|
+
),
|
49
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
50
|
+
)
|
51
|
+
if 200 <= _response.status_code < 300:
|
52
|
+
return pydantic.parse_obj_as(GenerateResponse, _response.json()) # type: ignore
|
53
|
+
try:
|
54
|
+
_response_json = _response.json()
|
55
|
+
except JSONDecodeError:
|
56
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
57
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
58
|
+
|
59
|
+
def search(
|
60
|
+
self,
|
61
|
+
*,
|
62
|
+
index_id: typing.Optional[str] = None,
|
63
|
+
index_name: typing.Optional[str] = None,
|
64
|
+
query: str,
|
65
|
+
options: typing.Optional[SearchRequestOptionsRequest] = None,
|
66
|
+
) -> SearchResponse:
|
67
|
+
_response = httpx.request(
|
68
|
+
"POST",
|
69
|
+
urllib.parse.urljoin(f"{self._environment.predict}/", "v1/search"),
|
70
|
+
json=jsonable_encoder({"index_id": index_id, "index_name": index_name, "query": query, "options": options}),
|
71
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
72
|
+
)
|
73
|
+
if 200 <= _response.status_code < 300:
|
74
|
+
return pydantic.parse_obj_as(SearchResponse, _response.json()) # type: ignore
|
75
|
+
try:
|
76
|
+
_response_json = _response.json()
|
77
|
+
except JSONDecodeError:
|
78
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
79
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
80
|
+
|
81
|
+
def submit_completion_actuals(
|
82
|
+
self,
|
83
|
+
*,
|
84
|
+
deployment_id: typing.Optional[str] = None,
|
85
|
+
deployment_name: typing.Optional[str] = None,
|
86
|
+
actuals: typing.List[SubmitCompletionActualRequest],
|
87
|
+
) -> None:
|
88
|
+
_response = httpx.request(
|
89
|
+
"POST",
|
90
|
+
urllib.parse.urljoin(f"{self._environment.predict}/", "v1/submit-completion-actuals"),
|
91
|
+
json=jsonable_encoder(
|
92
|
+
{"deployment_id": deployment_id, "deployment_name": deployment_name, "actuals": actuals}
|
93
|
+
),
|
94
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
95
|
+
)
|
96
|
+
if 200 <= _response.status_code < 300:
|
97
|
+
return
|
98
|
+
try:
|
99
|
+
_response_json = _response.json()
|
100
|
+
except JSONDecodeError:
|
101
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
102
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
103
|
+
|
104
|
+
@cached_property
|
105
|
+
def documents(self) -> DocumentsClient:
|
106
|
+
return DocumentsClient(environment=self._environment, api_key=self.api_key)
|
107
|
+
|
108
|
+
@cached_property
|
109
|
+
def model_versions(self) -> ModelVersionsClient:
|
110
|
+
return ModelVersionsClient(environment=self._environment, api_key=self.api_key)
|
111
|
+
|
112
|
+
|
113
|
+
class AsyncVellum:
|
114
|
+
def __init__(self, *, environment: VellumEnvironment = VellumEnvironment.PRODUCTION, api_key: str):
|
115
|
+
self._environment = environment
|
116
|
+
self.api_key = api_key
|
117
|
+
|
118
|
+
async def generate(
|
119
|
+
self,
|
120
|
+
*,
|
121
|
+
deployment_id: typing.Optional[str] = None,
|
122
|
+
deployment_name: typing.Optional[str] = None,
|
123
|
+
requests: typing.List[GenerateRequestRequest],
|
124
|
+
options: typing.Optional[GenerateOptionsRequest] = None,
|
125
|
+
) -> GenerateResponse:
|
126
|
+
async with httpx.AsyncClient() as _client:
|
127
|
+
_response = await _client.request(
|
128
|
+
"POST",
|
129
|
+
urllib.parse.urljoin(f"{self._environment.predict}/", "v1/generate"),
|
130
|
+
json=jsonable_encoder(
|
131
|
+
{
|
132
|
+
"deployment_id": deployment_id,
|
133
|
+
"deployment_name": deployment_name,
|
134
|
+
"requests": requests,
|
135
|
+
"options": options,
|
136
|
+
}
|
137
|
+
),
|
138
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
139
|
+
)
|
140
|
+
if 200 <= _response.status_code < 300:
|
141
|
+
return pydantic.parse_obj_as(GenerateResponse, _response.json()) # type: ignore
|
142
|
+
try:
|
143
|
+
_response_json = _response.json()
|
144
|
+
except JSONDecodeError:
|
145
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
146
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
147
|
+
|
148
|
+
async def search(
|
149
|
+
self,
|
150
|
+
*,
|
151
|
+
index_id: typing.Optional[str] = None,
|
152
|
+
index_name: typing.Optional[str] = None,
|
153
|
+
query: str,
|
154
|
+
options: typing.Optional[SearchRequestOptionsRequest] = None,
|
155
|
+
) -> SearchResponse:
|
156
|
+
async with httpx.AsyncClient() as _client:
|
157
|
+
_response = await _client.request(
|
158
|
+
"POST",
|
159
|
+
urllib.parse.urljoin(f"{self._environment.predict}/", "v1/search"),
|
160
|
+
json=jsonable_encoder(
|
161
|
+
{"index_id": index_id, "index_name": index_name, "query": query, "options": options}
|
162
|
+
),
|
163
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
164
|
+
)
|
165
|
+
if 200 <= _response.status_code < 300:
|
166
|
+
return pydantic.parse_obj_as(SearchResponse, _response.json()) # type: ignore
|
167
|
+
try:
|
168
|
+
_response_json = _response.json()
|
169
|
+
except JSONDecodeError:
|
170
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
171
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
172
|
+
|
173
|
+
async def submit_completion_actuals(
|
174
|
+
self,
|
175
|
+
*,
|
176
|
+
deployment_id: typing.Optional[str] = None,
|
177
|
+
deployment_name: typing.Optional[str] = None,
|
178
|
+
actuals: typing.List[SubmitCompletionActualRequest],
|
179
|
+
) -> None:
|
180
|
+
async with httpx.AsyncClient() as _client:
|
181
|
+
_response = await _client.request(
|
182
|
+
"POST",
|
183
|
+
urllib.parse.urljoin(f"{self._environment.predict}/", "v1/submit-completion-actuals"),
|
184
|
+
json=jsonable_encoder(
|
185
|
+
{"deployment_id": deployment_id, "deployment_name": deployment_name, "actuals": actuals}
|
186
|
+
),
|
187
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
188
|
+
)
|
189
|
+
if 200 <= _response.status_code < 300:
|
190
|
+
return
|
191
|
+
try:
|
192
|
+
_response_json = _response.json()
|
193
|
+
except JSONDecodeError:
|
194
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
195
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
196
|
+
|
197
|
+
@cached_property
|
198
|
+
def documents(self) -> AsyncDocumentsClient:
|
199
|
+
return AsyncDocumentsClient(environment=self._environment, api_key=self.api_key)
|
200
|
+
|
201
|
+
@cached_property
|
202
|
+
def model_versions(self) -> AsyncModelVersionsClient:
|
203
|
+
return AsyncModelVersionsClient(environment=self._environment, api_key=self.api_key)
|
vellum/core/__init__.py
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from .api_error import ApiError
|
4
|
+
from .datetime_utils import serialize_datetime
|
5
|
+
from .jsonable_encoder import jsonable_encoder
|
6
|
+
from .remove_none_from_headers import remove_none_from_headers
|
7
|
+
|
8
|
+
__all__ = ["ApiError", "jsonable_encoder", "remove_none_from_headers", "serialize_datetime"]
|
vellum/core/api_error.py
ADDED
@@ -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,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)
|
@@ -0,0 +1,94 @@
|
|
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
|
+
from collections import defaultdict
|
13
|
+
from enum import Enum
|
14
|
+
from pathlib import PurePath
|
15
|
+
from types import GeneratorType
|
16
|
+
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
|
17
|
+
|
18
|
+
from pydantic import BaseModel
|
19
|
+
from pydantic.json import ENCODERS_BY_TYPE
|
20
|
+
|
21
|
+
SetIntStr = Set[Union[int, str]]
|
22
|
+
DictIntStrAny = Dict[Union[int, str], Any]
|
23
|
+
|
24
|
+
|
25
|
+
def generate_encoders_by_class_tuples(
|
26
|
+
type_encoder_map: Dict[Any, Callable[[Any], Any]]
|
27
|
+
) -> Dict[Callable[[Any], Any], Tuple[Any, ...]]:
|
28
|
+
encoders_by_class_tuples: Dict[Callable[[Any], Any], Tuple[Any, ...]] = defaultdict(tuple)
|
29
|
+
for type_, encoder in type_encoder_map.items():
|
30
|
+
encoders_by_class_tuples[encoder] += (type_,)
|
31
|
+
return encoders_by_class_tuples
|
32
|
+
|
33
|
+
|
34
|
+
encoders_by_class_tuples = generate_encoders_by_class_tuples(ENCODERS_BY_TYPE)
|
35
|
+
|
36
|
+
|
37
|
+
def jsonable_encoder(obj: Any, custom_encoder: Optional[Dict[Any, Callable[[Any], Any]]] = None) -> Any:
|
38
|
+
custom_encoder = custom_encoder or {}
|
39
|
+
if custom_encoder:
|
40
|
+
if type(obj) in custom_encoder:
|
41
|
+
return custom_encoder[type(obj)](obj)
|
42
|
+
else:
|
43
|
+
for encoder_type, encoder_instance in custom_encoder.items():
|
44
|
+
if isinstance(obj, encoder_type):
|
45
|
+
return encoder_instance(obj)
|
46
|
+
if isinstance(obj, BaseModel):
|
47
|
+
encoder = getattr(obj.__config__, "json_encoders", {})
|
48
|
+
if custom_encoder:
|
49
|
+
encoder.update(custom_encoder)
|
50
|
+
obj_dict = obj.dict(by_alias=True)
|
51
|
+
if "__root__" in obj_dict:
|
52
|
+
obj_dict = obj_dict["__root__"]
|
53
|
+
return jsonable_encoder(obj_dict, custom_encoder=encoder)
|
54
|
+
if dataclasses.is_dataclass(obj):
|
55
|
+
obj_dict = dataclasses.asdict(obj)
|
56
|
+
return jsonable_encoder(obj_dict, custom_encoder=custom_encoder)
|
57
|
+
if isinstance(obj, Enum):
|
58
|
+
return obj.value
|
59
|
+
if isinstance(obj, PurePath):
|
60
|
+
return str(obj)
|
61
|
+
if isinstance(obj, (str, int, float, type(None))):
|
62
|
+
return obj
|
63
|
+
if isinstance(obj, dict):
|
64
|
+
encoded_dict = {}
|
65
|
+
allowed_keys = set(obj.keys())
|
66
|
+
for key, value in obj.items():
|
67
|
+
if key in allowed_keys:
|
68
|
+
encoded_key = jsonable_encoder(key, custom_encoder=custom_encoder)
|
69
|
+
encoded_value = jsonable_encoder(value, custom_encoder=custom_encoder)
|
70
|
+
encoded_dict[encoded_key] = encoded_value
|
71
|
+
return encoded_dict
|
72
|
+
if isinstance(obj, (list, set, frozenset, GeneratorType, tuple)):
|
73
|
+
encoded_list = []
|
74
|
+
for item in obj:
|
75
|
+
encoded_list.append(jsonable_encoder(item, custom_encoder=custom_encoder))
|
76
|
+
return encoded_list
|
77
|
+
|
78
|
+
if type(obj) in ENCODERS_BY_TYPE:
|
79
|
+
return ENCODERS_BY_TYPE[type(obj)](obj)
|
80
|
+
for encoder, classes_tuple in encoders_by_class_tuples.items():
|
81
|
+
if isinstance(obj, classes_tuple):
|
82
|
+
return encoder(obj)
|
83
|
+
|
84
|
+
try:
|
85
|
+
data = dict(obj)
|
86
|
+
except Exception as e:
|
87
|
+
errors: List[Exception] = []
|
88
|
+
errors.append(e)
|
89
|
+
try:
|
90
|
+
data = vars(obj)
|
91
|
+
except Exception as e:
|
92
|
+
errors.append(e)
|
93
|
+
raise ValueError(errors) from e
|
94
|
+
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 Dict, Optional
|
4
|
+
|
5
|
+
|
6
|
+
def remove_none_from_headers(headers: Dict[str, Optional[str]]) -> Dict[str, str]:
|
7
|
+
new_headers: Dict[str, str] = {}
|
8
|
+
for header_key, header_value in headers.items():
|
9
|
+
if header_value is not None:
|
10
|
+
new_headers[header_key] = header_value
|
11
|
+
return new_headers
|
vellum/environment.py
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
|
6
|
+
class VellumEnvironment:
|
7
|
+
PRODUCTION: VellumEnvironment
|
8
|
+
|
9
|
+
def __init__(self, *, default: str, predict: str, documents: str):
|
10
|
+
self.default = default
|
11
|
+
self.predict = predict
|
12
|
+
self.documents = documents
|
13
|
+
|
14
|
+
|
15
|
+
VellumEnvironment.PRODUCTION = VellumEnvironment(
|
16
|
+
default="https://api.vellum.ai", predict="https://predict.vellum.ai", documents="https://documents.vellum.ai"
|
17
|
+
)
|
vellum/py.typed
ADDED
File without changes
|
@@ -0,0 +1,135 @@
|
|
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
|
+
import httpx
|
8
|
+
import pydantic
|
9
|
+
|
10
|
+
from ...core.api_error import ApiError
|
11
|
+
from ...core.jsonable_encoder import jsonable_encoder
|
12
|
+
from ...core.remove_none_from_headers import remove_none_from_headers
|
13
|
+
from ...environment import VellumEnvironment
|
14
|
+
from ...types.paginated_slim_document_list import PaginatedSlimDocumentList
|
15
|
+
from ...types.upload_document_response import UploadDocumentResponse
|
16
|
+
|
17
|
+
|
18
|
+
class DocumentsClient:
|
19
|
+
def __init__(self, *, environment: VellumEnvironment = VellumEnvironment.PRODUCTION, api_key: str):
|
20
|
+
self._environment = environment
|
21
|
+
self.api_key = api_key
|
22
|
+
|
23
|
+
def list(
|
24
|
+
self,
|
25
|
+
*,
|
26
|
+
document_index_id: typing.Optional[str] = None,
|
27
|
+
limit: typing.Optional[int] = None,
|
28
|
+
offset: typing.Optional[int] = None,
|
29
|
+
ordering: typing.Optional[str] = None,
|
30
|
+
) -> PaginatedSlimDocumentList:
|
31
|
+
_response = httpx.request(
|
32
|
+
"GET",
|
33
|
+
urllib.parse.urljoin(f"{self._environment.default}/", "v1/documents"),
|
34
|
+
params={"document_index_id": document_index_id, "limit": limit, "offset": offset, "ordering": ordering},
|
35
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
36
|
+
)
|
37
|
+
if 200 <= _response.status_code < 300:
|
38
|
+
return pydantic.parse_obj_as(PaginatedSlimDocumentList, _response.json()) # type: ignore
|
39
|
+
try:
|
40
|
+
_response_json = _response.json()
|
41
|
+
except JSONDecodeError:
|
42
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
43
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
44
|
+
|
45
|
+
def upload(
|
46
|
+
self,
|
47
|
+
*,
|
48
|
+
add_to_index_names: typing.List[str],
|
49
|
+
external_id: str,
|
50
|
+
label: str,
|
51
|
+
contents: typing.IO,
|
52
|
+
keywords: typing.List[str],
|
53
|
+
) -> UploadDocumentResponse:
|
54
|
+
_response = httpx.request(
|
55
|
+
"POST",
|
56
|
+
urllib.parse.urljoin(f"{self._environment.documents}/", "v1/upload-document"),
|
57
|
+
data=jsonable_encoder(
|
58
|
+
{
|
59
|
+
"add_to_index_names": add_to_index_names,
|
60
|
+
"external_id": external_id,
|
61
|
+
"label": label,
|
62
|
+
"keywords": keywords,
|
63
|
+
}
|
64
|
+
),
|
65
|
+
files={"contents": contents},
|
66
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
67
|
+
)
|
68
|
+
if 200 <= _response.status_code < 300:
|
69
|
+
return pydantic.parse_obj_as(UploadDocumentResponse, _response.json()) # type: ignore
|
70
|
+
try:
|
71
|
+
_response_json = _response.json()
|
72
|
+
except JSONDecodeError:
|
73
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
74
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
75
|
+
|
76
|
+
|
77
|
+
class AsyncDocumentsClient:
|
78
|
+
def __init__(self, *, environment: VellumEnvironment = VellumEnvironment.PRODUCTION, api_key: str):
|
79
|
+
self._environment = environment
|
80
|
+
self.api_key = api_key
|
81
|
+
|
82
|
+
async def list(
|
83
|
+
self,
|
84
|
+
*,
|
85
|
+
document_index_id: typing.Optional[str] = None,
|
86
|
+
limit: typing.Optional[int] = None,
|
87
|
+
offset: typing.Optional[int] = None,
|
88
|
+
ordering: typing.Optional[str] = None,
|
89
|
+
) -> PaginatedSlimDocumentList:
|
90
|
+
async with httpx.AsyncClient() as _client:
|
91
|
+
_response = await _client.request(
|
92
|
+
"GET",
|
93
|
+
urllib.parse.urljoin(f"{self._environment.default}/", "v1/documents"),
|
94
|
+
params={"document_index_id": document_index_id, "limit": limit, "offset": offset, "ordering": ordering},
|
95
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
96
|
+
)
|
97
|
+
if 200 <= _response.status_code < 300:
|
98
|
+
return pydantic.parse_obj_as(PaginatedSlimDocumentList, _response.json()) # type: ignore
|
99
|
+
try:
|
100
|
+
_response_json = _response.json()
|
101
|
+
except JSONDecodeError:
|
102
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
103
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
104
|
+
|
105
|
+
async def upload(
|
106
|
+
self,
|
107
|
+
*,
|
108
|
+
add_to_index_names: typing.List[str],
|
109
|
+
external_id: str,
|
110
|
+
label: str,
|
111
|
+
contents: typing.IO,
|
112
|
+
keywords: typing.List[str],
|
113
|
+
) -> UploadDocumentResponse:
|
114
|
+
async with httpx.AsyncClient() as _client:
|
115
|
+
_response = await _client.request(
|
116
|
+
"POST",
|
117
|
+
urllib.parse.urljoin(f"{self._environment.documents}/", "v1/upload-document"),
|
118
|
+
data=jsonable_encoder(
|
119
|
+
{
|
120
|
+
"add_to_index_names": add_to_index_names,
|
121
|
+
"external_id": external_id,
|
122
|
+
"label": label,
|
123
|
+
"keywords": keywords,
|
124
|
+
}
|
125
|
+
),
|
126
|
+
files={"contents": contents},
|
127
|
+
headers=remove_none_from_headers({"X_API_KEY": self.api_key}),
|
128
|
+
)
|
129
|
+
if 200 <= _response.status_code < 300:
|
130
|
+
return pydantic.parse_obj_as(UploadDocumentResponse, _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)
|