letta-client 0.1.0__py3-none-any.whl → 0.1.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.
- letta/__init__.py +293 -0
- letta/agents/__init__.py +28 -0
- letta/agents/archival_memory/__init__.py +2 -0
- letta/agents/archival_memory/client.py +591 -0
- letta/agents/client.py +2166 -0
- letta/agents/context/__init__.py +2 -0
- letta/agents/context/client.py +145 -0
- letta/agents/memory/__init__.py +5 -0
- letta/agents/memory/client.py +149 -0
- letta/agents/memory/messages/__init__.py +2 -0
- letta/agents/memory/messages/client.py +147 -0
- letta/agents/memory_blocks/__init__.py +2 -0
- letta/agents/memory_blocks/client.py +364 -0
- letta/agents/messages/__init__.py +5 -0
- letta/agents/messages/client.py +787 -0
- letta/agents/messages/types/__init__.py +7 -0
- letta/agents/messages/types/letta_streaming_response.py +20 -0
- letta/agents/messages/types/messages_list_response.py +7 -0
- letta/agents/messages/types/messages_list_response_item.py +13 -0
- letta/agents/recall_memory/__init__.py +2 -0
- letta/agents/recall_memory/client.py +147 -0
- letta/agents/sources/__init__.py +2 -0
- letta/agents/sources/client.py +145 -0
- letta/agents/tools/__init__.py +2 -0
- letta/agents/tools/client.py +408 -0
- letta/agents/types/__init__.py +13 -0
- letta/agents/types/agents_create_version_response.py +22 -0
- letta/agents/types/agents_migrate_response.py +19 -0
- letta/agents/types/create_agent_request_tool_rules_item.py +9 -0
- letta/agents/types/update_agent_tool_rules_item.py +9 -0
- letta/blocks/__init__.py +2 -0
- letta/blocks/client.py +1054 -0
- letta/client.py +164 -0
- letta/core/__init__.py +47 -0
- letta/core/api_error.py +15 -0
- letta/core/client_wrapper.py +76 -0
- letta/core/datetime_utils.py +28 -0
- letta/core/file.py +67 -0
- letta/core/http_client.py +499 -0
- letta/core/jsonable_encoder.py +101 -0
- letta/core/pydantic_utilities.py +296 -0
- letta/core/query_encoder.py +58 -0
- letta/core/remove_none_from_dict.py +11 -0
- letta/core/request_options.py +35 -0
- letta/core/serialization.py +272 -0
- letta/environment.py +8 -0
- letta/errors/__init__.py +8 -0
- letta/errors/conflict_error.py +9 -0
- letta/errors/internal_server_error.py +9 -0
- letta/errors/not_found_error.py +9 -0
- letta/errors/unprocessable_entity_error.py +9 -0
- letta/health/__init__.py +2 -0
- letta/health/client.py +108 -0
- letta/jobs/__init__.py +2 -0
- letta/jobs/client.py +503 -0
- letta/models/__init__.py +2 -0
- letta/models/client.py +201 -0
- letta/sources/__init__.py +5 -0
- letta/sources/client.py +1154 -0
- letta/sources/files/__init__.py +2 -0
- letta/sources/files/client.py +436 -0
- letta/sources/passages/__init__.py +2 -0
- letta/sources/passages/client.py +145 -0
- letta/tools/__init__.py +2 -0
- letta/tools/client.py +1823 -0
- letta/types/__init__.py +263 -0
- letta/types/action_model.py +36 -0
- letta/types/action_parameters_model.py +26 -0
- letta/types/action_response_model.py +26 -0
- letta/types/agent_state.py +139 -0
- letta/types/agent_state_tool_rules_item.py +9 -0
- letta/types/agent_type.py +8 -0
- letta/types/app_auth_scheme.py +34 -0
- letta/types/app_auth_scheme_auth_mode.py +7 -0
- letta/types/app_model.py +44 -0
- letta/types/archival_memory_summary.py +22 -0
- letta/types/assistant_file.py +33 -0
- letta/types/assistant_message_input.py +23 -0
- letta/types/assistant_message_output.py +23 -0
- letta/types/auth_request.py +22 -0
- letta/types/auth_response.py +29 -0
- letta/types/auth_scheme_field.py +30 -0
- letta/types/block.py +91 -0
- letta/types/block_update.py +60 -0
- letta/types/chat_completion_request.py +49 -0
- letta/types/chat_completion_request_function_call.py +6 -0
- letta/types/chat_completion_request_messages_item.py +11 -0
- letta/types/chat_completion_request_stop.py +5 -0
- letta/types/chat_completion_request_tool_choice.py +8 -0
- letta/types/chat_completion_response.py +32 -0
- letta/types/child_tool_rule.py +33 -0
- letta/types/choice.py +25 -0
- letta/types/conditional_tool_rule.py +43 -0
- letta/types/conflict_error_body.py +21 -0
- letta/types/context_window_overview.py +105 -0
- letta/types/create_assistant_file_request.py +22 -0
- letta/types/create_assistant_request.py +57 -0
- letta/types/create_block.py +56 -0
- letta/types/delete_assistant_file_response.py +28 -0
- letta/types/delete_assistant_response.py +28 -0
- letta/types/e_2_b_sandbox_config.py +32 -0
- letta/types/embedding_config.py +72 -0
- letta/types/embedding_config_embedding_endpoint_type.py +26 -0
- letta/types/file_metadata.py +82 -0
- letta/types/function_call_input.py +19 -0
- letta/types/function_call_output.py +20 -0
- letta/types/function_schema.py +21 -0
- letta/types/health.py +24 -0
- letta/types/http_validation_error.py +20 -0
- letta/types/init_tool_rule.py +29 -0
- letta/types/internal_server_error_body.py +19 -0
- letta/types/job.py +79 -0
- letta/types/job_status.py +5 -0
- letta/types/letta_request.py +33 -0
- letta/types/letta_response.py +125 -0
- letta/types/letta_response_assistant_message.py +23 -0
- letta/types/letta_response_letta_usage_statistics.py +47 -0
- letta/types/letta_response_reasoning_message.py +32 -0
- letta/types/letta_response_system_message.py +32 -0
- letta/types/letta_response_tool_call.py +21 -0
- letta/types/letta_response_tool_call_delta.py +21 -0
- letta/types/letta_response_tool_call_message.py +33 -0
- letta/types/letta_response_tool_call_message_tool_call.py +9 -0
- letta/types/letta_response_tool_call_message_tool_call_one.py +21 -0
- letta/types/letta_response_tool_call_message_tool_call_zero.py +21 -0
- letta/types/letta_response_tool_return_message.py +41 -0
- letta/types/letta_response_tool_return_message_status.py +5 -0
- letta/types/letta_response_usage_message.py +40 -0
- letta/types/letta_response_usage_message_usage.py +47 -0
- letta/types/letta_response_user_message.py +32 -0
- letta/types/letta_schemas_letta_message_tool_call.py +21 -0
- letta/types/letta_schemas_message_message.py +103 -0
- letta/types/letta_schemas_openai_chat_completion_request_tool.py +21 -0
- letta/types/letta_schemas_openai_chat_completion_request_tool_call.py +24 -0
- letta/types/letta_schemas_openai_chat_completion_request_tool_call_function.py +20 -0
- letta/types/letta_schemas_openai_chat_completion_response_message.py +24 -0
- letta/types/letta_schemas_openai_chat_completion_response_tool_call.py +22 -0
- letta/types/letta_schemas_openai_chat_completions_tool_call_function.py +27 -0
- letta/types/letta_schemas_openai_chat_completions_tool_call_input.py +29 -0
- letta/types/letta_schemas_openai_chat_completions_tool_call_output.py +29 -0
- letta/types/letta_schemas_tool_tool.py +88 -0
- letta/types/letta_usage_statistics.py +47 -0
- letta/types/llm_config.py +60 -0
- letta/types/llm_config_model_endpoint_type.py +26 -0
- letta/types/local_sandbox_config.py +32 -0
- letta/types/log_prob_token.py +21 -0
- letta/types/memory.py +32 -0
- letta/types/message_content_log_prob.py +23 -0
- letta/types/message_create.py +37 -0
- letta/types/message_create_role.py +5 -0
- letta/types/message_role.py +5 -0
- letta/types/not_found_error_body.py +20 -0
- letta/types/not_found_error_body_message.py +11 -0
- letta/types/open_ai_assistant.py +67 -0
- letta/types/organization.py +33 -0
- letta/types/organization_create.py +22 -0
- letta/types/passage.py +107 -0
- letta/types/reasoning_message.py +32 -0
- letta/types/recall_memory_summary.py +22 -0
- letta/types/response_format.py +19 -0
- letta/types/sandbox_config.py +59 -0
- letta/types/sandbox_config_create.py +23 -0
- letta/types/sandbox_config_create_config.py +7 -0
- letta/types/sandbox_config_update.py +27 -0
- letta/types/sandbox_config_update_config.py +7 -0
- letta/types/sandbox_environment_variable.py +68 -0
- letta/types/sandbox_environment_variable_create.py +32 -0
- letta/types/sandbox_environment_variable_update.py +36 -0
- letta/types/sandbox_type.py +5 -0
- letta/types/source.py +85 -0
- letta/types/system_message_input.py +21 -0
- letta/types/system_message_output.py +32 -0
- letta/types/terminal_tool_rule.py +29 -0
- letta/types/tool_call_delta.py +21 -0
- letta/types/tool_call_function_output.py +27 -0
- letta/types/tool_call_message.py +33 -0
- letta/types/tool_call_message_tool_call.py +7 -0
- letta/types/tool_create.py +57 -0
- letta/types/tool_function_choice.py +21 -0
- letta/types/tool_input.py +21 -0
- letta/types/tool_message.py +21 -0
- letta/types/tool_return_message.py +41 -0
- letta/types/tool_return_message_status.py +5 -0
- letta/types/tool_rule_type.py +10 -0
- letta/types/usage_message.py +31 -0
- letta/types/usage_statistics.py +21 -0
- letta/types/user.py +57 -0
- letta/types/user_create.py +27 -0
- letta/types/user_message_input.py +22 -0
- letta/types/user_message_input_content.py +5 -0
- letta/types/user_message_output.py +32 -0
- letta/types/user_update.py +32 -0
- letta/types/validation_error.py +22 -0
- letta/types/validation_error_loc_item.py +5 -0
- letta/version.py +3 -0
- letta_client-0.1.2.dist-info/METADATA +189 -0
- letta_client-0.1.2.dist-info/RECORD +199 -0
- {letta_client-0.1.0.dist-info → letta_client-0.1.2.dist-info}/WHEEL +1 -1
- letta_client-0.1.0.dist-info/METADATA +0 -15
- letta_client-0.1.0.dist-info/RECORD +0 -4
- /letta_client/__init__.py → /letta/py.typed +0 -0
letta/sources/client.py
ADDED
|
@@ -0,0 +1,1154 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from ..core.client_wrapper import SyncClientWrapper
|
|
5
|
+
from .files.client import FilesClient
|
|
6
|
+
from .passages.client import PassagesClient
|
|
7
|
+
from ..core.request_options import RequestOptions
|
|
8
|
+
from ..types.source import Source
|
|
9
|
+
from ..core.jsonable_encoder import jsonable_encoder
|
|
10
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
11
|
+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
|
12
|
+
from ..types.http_validation_error import HttpValidationError
|
|
13
|
+
from json.decoder import JSONDecodeError
|
|
14
|
+
from ..core.api_error import ApiError
|
|
15
|
+
from ..types.embedding_config import EmbeddingConfig
|
|
16
|
+
from ..core.serialization import convert_and_respect_annotation_metadata
|
|
17
|
+
from ..core.client_wrapper import AsyncClientWrapper
|
|
18
|
+
from .files.client import AsyncFilesClient
|
|
19
|
+
from .passages.client import AsyncPassagesClient
|
|
20
|
+
|
|
21
|
+
# this is used as the default value for optional parameters
|
|
22
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class SourcesClient:
|
|
26
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
27
|
+
self._client_wrapper = client_wrapper
|
|
28
|
+
self.files = FilesClient(client_wrapper=self._client_wrapper)
|
|
29
|
+
self.passages = PassagesClient(client_wrapper=self._client_wrapper)
|
|
30
|
+
|
|
31
|
+
def get(self, source_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Source:
|
|
32
|
+
"""
|
|
33
|
+
Get all sources
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
source_id : str
|
|
38
|
+
|
|
39
|
+
request_options : typing.Optional[RequestOptions]
|
|
40
|
+
Request-specific configuration.
|
|
41
|
+
|
|
42
|
+
Returns
|
|
43
|
+
-------
|
|
44
|
+
Source
|
|
45
|
+
Successful Response
|
|
46
|
+
|
|
47
|
+
Examples
|
|
48
|
+
--------
|
|
49
|
+
from letta import Letta
|
|
50
|
+
|
|
51
|
+
client = Letta(
|
|
52
|
+
token="YOUR_TOKEN",
|
|
53
|
+
)
|
|
54
|
+
client.sources.get(
|
|
55
|
+
source_id="source_id",
|
|
56
|
+
)
|
|
57
|
+
"""
|
|
58
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
59
|
+
f"v1/sources/{jsonable_encoder(source_id)}",
|
|
60
|
+
method="GET",
|
|
61
|
+
request_options=request_options,
|
|
62
|
+
)
|
|
63
|
+
try:
|
|
64
|
+
if 200 <= _response.status_code < 300:
|
|
65
|
+
return typing.cast(
|
|
66
|
+
Source,
|
|
67
|
+
parse_obj_as(
|
|
68
|
+
type_=Source, # type: ignore
|
|
69
|
+
object_=_response.json(),
|
|
70
|
+
),
|
|
71
|
+
)
|
|
72
|
+
if _response.status_code == 422:
|
|
73
|
+
raise UnprocessableEntityError(
|
|
74
|
+
typing.cast(
|
|
75
|
+
HttpValidationError,
|
|
76
|
+
parse_obj_as(
|
|
77
|
+
type_=HttpValidationError, # type: ignore
|
|
78
|
+
object_=_response.json(),
|
|
79
|
+
),
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
_response_json = _response.json()
|
|
83
|
+
except JSONDecodeError:
|
|
84
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
85
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
86
|
+
|
|
87
|
+
def delete(
|
|
88
|
+
self, source_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
89
|
+
) -> typing.Optional[typing.Any]:
|
|
90
|
+
"""
|
|
91
|
+
Delete a data source.
|
|
92
|
+
|
|
93
|
+
Parameters
|
|
94
|
+
----------
|
|
95
|
+
source_id : str
|
|
96
|
+
|
|
97
|
+
request_options : typing.Optional[RequestOptions]
|
|
98
|
+
Request-specific configuration.
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
typing.Optional[typing.Any]
|
|
103
|
+
Successful Response
|
|
104
|
+
|
|
105
|
+
Examples
|
|
106
|
+
--------
|
|
107
|
+
from letta import Letta
|
|
108
|
+
|
|
109
|
+
client = Letta(
|
|
110
|
+
token="YOUR_TOKEN",
|
|
111
|
+
)
|
|
112
|
+
client.sources.delete(
|
|
113
|
+
source_id="source_id",
|
|
114
|
+
)
|
|
115
|
+
"""
|
|
116
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
117
|
+
f"v1/sources/{jsonable_encoder(source_id)}",
|
|
118
|
+
method="DELETE",
|
|
119
|
+
request_options=request_options,
|
|
120
|
+
)
|
|
121
|
+
try:
|
|
122
|
+
if 200 <= _response.status_code < 300:
|
|
123
|
+
return typing.cast(
|
|
124
|
+
typing.Optional[typing.Any],
|
|
125
|
+
parse_obj_as(
|
|
126
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
127
|
+
object_=_response.json(),
|
|
128
|
+
),
|
|
129
|
+
)
|
|
130
|
+
if _response.status_code == 422:
|
|
131
|
+
raise UnprocessableEntityError(
|
|
132
|
+
typing.cast(
|
|
133
|
+
HttpValidationError,
|
|
134
|
+
parse_obj_as(
|
|
135
|
+
type_=HttpValidationError, # type: ignore
|
|
136
|
+
object_=_response.json(),
|
|
137
|
+
),
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
_response_json = _response.json()
|
|
141
|
+
except JSONDecodeError:
|
|
142
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
143
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
144
|
+
|
|
145
|
+
def update(
|
|
146
|
+
self,
|
|
147
|
+
source_id: str,
|
|
148
|
+
*,
|
|
149
|
+
name: typing.Optional[str] = OMIT,
|
|
150
|
+
description: typing.Optional[str] = OMIT,
|
|
151
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
152
|
+
embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
|
|
153
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
154
|
+
) -> Source:
|
|
155
|
+
"""
|
|
156
|
+
Update the name or documentation of an existing data source.
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
----------
|
|
160
|
+
source_id : str
|
|
161
|
+
|
|
162
|
+
name : typing.Optional[str]
|
|
163
|
+
The name of the source.
|
|
164
|
+
|
|
165
|
+
description : typing.Optional[str]
|
|
166
|
+
The description of the source.
|
|
167
|
+
|
|
168
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
169
|
+
Metadata associated with the source.
|
|
170
|
+
|
|
171
|
+
embedding_config : typing.Optional[EmbeddingConfig]
|
|
172
|
+
The embedding configuration used by the source.
|
|
173
|
+
|
|
174
|
+
request_options : typing.Optional[RequestOptions]
|
|
175
|
+
Request-specific configuration.
|
|
176
|
+
|
|
177
|
+
Returns
|
|
178
|
+
-------
|
|
179
|
+
Source
|
|
180
|
+
Successful Response
|
|
181
|
+
|
|
182
|
+
Examples
|
|
183
|
+
--------
|
|
184
|
+
from letta import Letta
|
|
185
|
+
|
|
186
|
+
client = Letta(
|
|
187
|
+
token="YOUR_TOKEN",
|
|
188
|
+
)
|
|
189
|
+
client.sources.update(
|
|
190
|
+
source_id="source_id",
|
|
191
|
+
)
|
|
192
|
+
"""
|
|
193
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
194
|
+
f"v1/sources/{jsonable_encoder(source_id)}",
|
|
195
|
+
method="PATCH",
|
|
196
|
+
json={
|
|
197
|
+
"name": name,
|
|
198
|
+
"description": description,
|
|
199
|
+
"metadata_": metadata,
|
|
200
|
+
"embedding_config": convert_and_respect_annotation_metadata(
|
|
201
|
+
object_=embedding_config, annotation=EmbeddingConfig, direction="write"
|
|
202
|
+
),
|
|
203
|
+
},
|
|
204
|
+
headers={
|
|
205
|
+
"content-type": "application/json",
|
|
206
|
+
},
|
|
207
|
+
request_options=request_options,
|
|
208
|
+
omit=OMIT,
|
|
209
|
+
)
|
|
210
|
+
try:
|
|
211
|
+
if 200 <= _response.status_code < 300:
|
|
212
|
+
return typing.cast(
|
|
213
|
+
Source,
|
|
214
|
+
parse_obj_as(
|
|
215
|
+
type_=Source, # type: ignore
|
|
216
|
+
object_=_response.json(),
|
|
217
|
+
),
|
|
218
|
+
)
|
|
219
|
+
if _response.status_code == 422:
|
|
220
|
+
raise UnprocessableEntityError(
|
|
221
|
+
typing.cast(
|
|
222
|
+
HttpValidationError,
|
|
223
|
+
parse_obj_as(
|
|
224
|
+
type_=HttpValidationError, # type: ignore
|
|
225
|
+
object_=_response.json(),
|
|
226
|
+
),
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
_response_json = _response.json()
|
|
230
|
+
except JSONDecodeError:
|
|
231
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
232
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
233
|
+
|
|
234
|
+
def get_by_name(self, source_name: str, *, request_options: typing.Optional[RequestOptions] = None) -> str:
|
|
235
|
+
"""
|
|
236
|
+
Get a source by name
|
|
237
|
+
|
|
238
|
+
Parameters
|
|
239
|
+
----------
|
|
240
|
+
source_name : str
|
|
241
|
+
|
|
242
|
+
request_options : typing.Optional[RequestOptions]
|
|
243
|
+
Request-specific configuration.
|
|
244
|
+
|
|
245
|
+
Returns
|
|
246
|
+
-------
|
|
247
|
+
str
|
|
248
|
+
Successful Response
|
|
249
|
+
|
|
250
|
+
Examples
|
|
251
|
+
--------
|
|
252
|
+
from letta import Letta
|
|
253
|
+
|
|
254
|
+
client = Letta(
|
|
255
|
+
token="YOUR_TOKEN",
|
|
256
|
+
)
|
|
257
|
+
client.sources.get_by_name(
|
|
258
|
+
source_name="source_name",
|
|
259
|
+
)
|
|
260
|
+
"""
|
|
261
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
262
|
+
f"v1/sources/name/{jsonable_encoder(source_name)}",
|
|
263
|
+
method="GET",
|
|
264
|
+
request_options=request_options,
|
|
265
|
+
)
|
|
266
|
+
try:
|
|
267
|
+
if 200 <= _response.status_code < 300:
|
|
268
|
+
return typing.cast(
|
|
269
|
+
str,
|
|
270
|
+
parse_obj_as(
|
|
271
|
+
type_=str, # type: ignore
|
|
272
|
+
object_=_response.json(),
|
|
273
|
+
),
|
|
274
|
+
)
|
|
275
|
+
if _response.status_code == 422:
|
|
276
|
+
raise UnprocessableEntityError(
|
|
277
|
+
typing.cast(
|
|
278
|
+
HttpValidationError,
|
|
279
|
+
parse_obj_as(
|
|
280
|
+
type_=HttpValidationError, # type: ignore
|
|
281
|
+
object_=_response.json(),
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
)
|
|
285
|
+
_response_json = _response.json()
|
|
286
|
+
except JSONDecodeError:
|
|
287
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
288
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
289
|
+
|
|
290
|
+
def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Source]:
|
|
291
|
+
"""
|
|
292
|
+
List all data sources created by a user.
|
|
293
|
+
|
|
294
|
+
Parameters
|
|
295
|
+
----------
|
|
296
|
+
request_options : typing.Optional[RequestOptions]
|
|
297
|
+
Request-specific configuration.
|
|
298
|
+
|
|
299
|
+
Returns
|
|
300
|
+
-------
|
|
301
|
+
typing.List[Source]
|
|
302
|
+
Successful Response
|
|
303
|
+
|
|
304
|
+
Examples
|
|
305
|
+
--------
|
|
306
|
+
from letta import Letta
|
|
307
|
+
|
|
308
|
+
client = Letta(
|
|
309
|
+
token="YOUR_TOKEN",
|
|
310
|
+
)
|
|
311
|
+
client.sources.list()
|
|
312
|
+
"""
|
|
313
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
314
|
+
"v1/sources/",
|
|
315
|
+
method="GET",
|
|
316
|
+
request_options=request_options,
|
|
317
|
+
)
|
|
318
|
+
try:
|
|
319
|
+
if 200 <= _response.status_code < 300:
|
|
320
|
+
return typing.cast(
|
|
321
|
+
typing.List[Source],
|
|
322
|
+
parse_obj_as(
|
|
323
|
+
type_=typing.List[Source], # type: ignore
|
|
324
|
+
object_=_response.json(),
|
|
325
|
+
),
|
|
326
|
+
)
|
|
327
|
+
if _response.status_code == 422:
|
|
328
|
+
raise UnprocessableEntityError(
|
|
329
|
+
typing.cast(
|
|
330
|
+
HttpValidationError,
|
|
331
|
+
parse_obj_as(
|
|
332
|
+
type_=HttpValidationError, # type: ignore
|
|
333
|
+
object_=_response.json(),
|
|
334
|
+
),
|
|
335
|
+
)
|
|
336
|
+
)
|
|
337
|
+
_response_json = _response.json()
|
|
338
|
+
except JSONDecodeError:
|
|
339
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
340
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
341
|
+
|
|
342
|
+
def create(
|
|
343
|
+
self,
|
|
344
|
+
*,
|
|
345
|
+
name: str,
|
|
346
|
+
embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
|
|
347
|
+
description: typing.Optional[str] = OMIT,
|
|
348
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
349
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
350
|
+
) -> Source:
|
|
351
|
+
"""
|
|
352
|
+
Create a new data source.
|
|
353
|
+
|
|
354
|
+
Parameters
|
|
355
|
+
----------
|
|
356
|
+
name : str
|
|
357
|
+
The name of the source.
|
|
358
|
+
|
|
359
|
+
embedding_config : typing.Optional[EmbeddingConfig]
|
|
360
|
+
The embedding configuration used by the source.
|
|
361
|
+
|
|
362
|
+
description : typing.Optional[str]
|
|
363
|
+
The description of the source.
|
|
364
|
+
|
|
365
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
366
|
+
Metadata associated with the source.
|
|
367
|
+
|
|
368
|
+
request_options : typing.Optional[RequestOptions]
|
|
369
|
+
Request-specific configuration.
|
|
370
|
+
|
|
371
|
+
Returns
|
|
372
|
+
-------
|
|
373
|
+
Source
|
|
374
|
+
Successful Response
|
|
375
|
+
|
|
376
|
+
Examples
|
|
377
|
+
--------
|
|
378
|
+
from letta import Letta
|
|
379
|
+
|
|
380
|
+
client = Letta(
|
|
381
|
+
token="YOUR_TOKEN",
|
|
382
|
+
)
|
|
383
|
+
client.sources.create(
|
|
384
|
+
name="name",
|
|
385
|
+
)
|
|
386
|
+
"""
|
|
387
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
388
|
+
"v1/sources/",
|
|
389
|
+
method="POST",
|
|
390
|
+
json={
|
|
391
|
+
"name": name,
|
|
392
|
+
"embedding_config": convert_and_respect_annotation_metadata(
|
|
393
|
+
object_=embedding_config, annotation=EmbeddingConfig, direction="write"
|
|
394
|
+
),
|
|
395
|
+
"description": description,
|
|
396
|
+
"metadata_": metadata,
|
|
397
|
+
},
|
|
398
|
+
headers={
|
|
399
|
+
"content-type": "application/json",
|
|
400
|
+
},
|
|
401
|
+
request_options=request_options,
|
|
402
|
+
omit=OMIT,
|
|
403
|
+
)
|
|
404
|
+
try:
|
|
405
|
+
if 200 <= _response.status_code < 300:
|
|
406
|
+
return typing.cast(
|
|
407
|
+
Source,
|
|
408
|
+
parse_obj_as(
|
|
409
|
+
type_=Source, # type: ignore
|
|
410
|
+
object_=_response.json(),
|
|
411
|
+
),
|
|
412
|
+
)
|
|
413
|
+
if _response.status_code == 422:
|
|
414
|
+
raise UnprocessableEntityError(
|
|
415
|
+
typing.cast(
|
|
416
|
+
HttpValidationError,
|
|
417
|
+
parse_obj_as(
|
|
418
|
+
type_=HttpValidationError, # type: ignore
|
|
419
|
+
object_=_response.json(),
|
|
420
|
+
),
|
|
421
|
+
)
|
|
422
|
+
)
|
|
423
|
+
_response_json = _response.json()
|
|
424
|
+
except JSONDecodeError:
|
|
425
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
426
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
427
|
+
|
|
428
|
+
def attach(
|
|
429
|
+
self, source_id: str, *, agent_id: str, request_options: typing.Optional[RequestOptions] = None
|
|
430
|
+
) -> Source:
|
|
431
|
+
"""
|
|
432
|
+
Attach a data source to an existing agent.
|
|
433
|
+
|
|
434
|
+
Parameters
|
|
435
|
+
----------
|
|
436
|
+
source_id : str
|
|
437
|
+
|
|
438
|
+
agent_id : str
|
|
439
|
+
The unique identifier of the agent to attach the source to.
|
|
440
|
+
|
|
441
|
+
request_options : typing.Optional[RequestOptions]
|
|
442
|
+
Request-specific configuration.
|
|
443
|
+
|
|
444
|
+
Returns
|
|
445
|
+
-------
|
|
446
|
+
Source
|
|
447
|
+
Successful Response
|
|
448
|
+
|
|
449
|
+
Examples
|
|
450
|
+
--------
|
|
451
|
+
from letta import Letta
|
|
452
|
+
|
|
453
|
+
client = Letta(
|
|
454
|
+
token="YOUR_TOKEN",
|
|
455
|
+
)
|
|
456
|
+
client.sources.attach(
|
|
457
|
+
source_id="source_id",
|
|
458
|
+
agent_id="agent_id",
|
|
459
|
+
)
|
|
460
|
+
"""
|
|
461
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
462
|
+
f"v1/sources/{jsonable_encoder(source_id)}/attach",
|
|
463
|
+
method="POST",
|
|
464
|
+
params={
|
|
465
|
+
"agent_id": agent_id,
|
|
466
|
+
},
|
|
467
|
+
request_options=request_options,
|
|
468
|
+
)
|
|
469
|
+
try:
|
|
470
|
+
if 200 <= _response.status_code < 300:
|
|
471
|
+
return typing.cast(
|
|
472
|
+
Source,
|
|
473
|
+
parse_obj_as(
|
|
474
|
+
type_=Source, # type: ignore
|
|
475
|
+
object_=_response.json(),
|
|
476
|
+
),
|
|
477
|
+
)
|
|
478
|
+
if _response.status_code == 422:
|
|
479
|
+
raise UnprocessableEntityError(
|
|
480
|
+
typing.cast(
|
|
481
|
+
HttpValidationError,
|
|
482
|
+
parse_obj_as(
|
|
483
|
+
type_=HttpValidationError, # type: ignore
|
|
484
|
+
object_=_response.json(),
|
|
485
|
+
),
|
|
486
|
+
)
|
|
487
|
+
)
|
|
488
|
+
_response_json = _response.json()
|
|
489
|
+
except JSONDecodeError:
|
|
490
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
491
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
492
|
+
|
|
493
|
+
def detach(
|
|
494
|
+
self, source_id: str, *, agent_id: str, request_options: typing.Optional[RequestOptions] = None
|
|
495
|
+
) -> Source:
|
|
496
|
+
"""
|
|
497
|
+
Detach a data source from an existing agent.
|
|
498
|
+
|
|
499
|
+
Parameters
|
|
500
|
+
----------
|
|
501
|
+
source_id : str
|
|
502
|
+
|
|
503
|
+
agent_id : str
|
|
504
|
+
The unique identifier of the agent to detach the source from.
|
|
505
|
+
|
|
506
|
+
request_options : typing.Optional[RequestOptions]
|
|
507
|
+
Request-specific configuration.
|
|
508
|
+
|
|
509
|
+
Returns
|
|
510
|
+
-------
|
|
511
|
+
Source
|
|
512
|
+
Successful Response
|
|
513
|
+
|
|
514
|
+
Examples
|
|
515
|
+
--------
|
|
516
|
+
from letta import Letta
|
|
517
|
+
|
|
518
|
+
client = Letta(
|
|
519
|
+
token="YOUR_TOKEN",
|
|
520
|
+
)
|
|
521
|
+
client.sources.detach(
|
|
522
|
+
source_id="source_id",
|
|
523
|
+
agent_id="agent_id",
|
|
524
|
+
)
|
|
525
|
+
"""
|
|
526
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
527
|
+
f"v1/sources/{jsonable_encoder(source_id)}/detach",
|
|
528
|
+
method="POST",
|
|
529
|
+
params={
|
|
530
|
+
"agent_id": agent_id,
|
|
531
|
+
},
|
|
532
|
+
request_options=request_options,
|
|
533
|
+
)
|
|
534
|
+
try:
|
|
535
|
+
if 200 <= _response.status_code < 300:
|
|
536
|
+
return typing.cast(
|
|
537
|
+
Source,
|
|
538
|
+
parse_obj_as(
|
|
539
|
+
type_=Source, # type: ignore
|
|
540
|
+
object_=_response.json(),
|
|
541
|
+
),
|
|
542
|
+
)
|
|
543
|
+
if _response.status_code == 422:
|
|
544
|
+
raise UnprocessableEntityError(
|
|
545
|
+
typing.cast(
|
|
546
|
+
HttpValidationError,
|
|
547
|
+
parse_obj_as(
|
|
548
|
+
type_=HttpValidationError, # type: ignore
|
|
549
|
+
object_=_response.json(),
|
|
550
|
+
),
|
|
551
|
+
)
|
|
552
|
+
)
|
|
553
|
+
_response_json = _response.json()
|
|
554
|
+
except JSONDecodeError:
|
|
555
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
556
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
class AsyncSourcesClient:
|
|
560
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
561
|
+
self._client_wrapper = client_wrapper
|
|
562
|
+
self.files = AsyncFilesClient(client_wrapper=self._client_wrapper)
|
|
563
|
+
self.passages = AsyncPassagesClient(client_wrapper=self._client_wrapper)
|
|
564
|
+
|
|
565
|
+
async def get(self, source_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Source:
|
|
566
|
+
"""
|
|
567
|
+
Get all sources
|
|
568
|
+
|
|
569
|
+
Parameters
|
|
570
|
+
----------
|
|
571
|
+
source_id : str
|
|
572
|
+
|
|
573
|
+
request_options : typing.Optional[RequestOptions]
|
|
574
|
+
Request-specific configuration.
|
|
575
|
+
|
|
576
|
+
Returns
|
|
577
|
+
-------
|
|
578
|
+
Source
|
|
579
|
+
Successful Response
|
|
580
|
+
|
|
581
|
+
Examples
|
|
582
|
+
--------
|
|
583
|
+
import asyncio
|
|
584
|
+
|
|
585
|
+
from letta import AsyncLetta
|
|
586
|
+
|
|
587
|
+
client = AsyncLetta(
|
|
588
|
+
token="YOUR_TOKEN",
|
|
589
|
+
)
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
async def main() -> None:
|
|
593
|
+
await client.sources.get(
|
|
594
|
+
source_id="source_id",
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
asyncio.run(main())
|
|
599
|
+
"""
|
|
600
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
601
|
+
f"v1/sources/{jsonable_encoder(source_id)}",
|
|
602
|
+
method="GET",
|
|
603
|
+
request_options=request_options,
|
|
604
|
+
)
|
|
605
|
+
try:
|
|
606
|
+
if 200 <= _response.status_code < 300:
|
|
607
|
+
return typing.cast(
|
|
608
|
+
Source,
|
|
609
|
+
parse_obj_as(
|
|
610
|
+
type_=Source, # type: ignore
|
|
611
|
+
object_=_response.json(),
|
|
612
|
+
),
|
|
613
|
+
)
|
|
614
|
+
if _response.status_code == 422:
|
|
615
|
+
raise UnprocessableEntityError(
|
|
616
|
+
typing.cast(
|
|
617
|
+
HttpValidationError,
|
|
618
|
+
parse_obj_as(
|
|
619
|
+
type_=HttpValidationError, # type: ignore
|
|
620
|
+
object_=_response.json(),
|
|
621
|
+
),
|
|
622
|
+
)
|
|
623
|
+
)
|
|
624
|
+
_response_json = _response.json()
|
|
625
|
+
except JSONDecodeError:
|
|
626
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
627
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
628
|
+
|
|
629
|
+
async def delete(
|
|
630
|
+
self, source_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
631
|
+
) -> typing.Optional[typing.Any]:
|
|
632
|
+
"""
|
|
633
|
+
Delete a data source.
|
|
634
|
+
|
|
635
|
+
Parameters
|
|
636
|
+
----------
|
|
637
|
+
source_id : str
|
|
638
|
+
|
|
639
|
+
request_options : typing.Optional[RequestOptions]
|
|
640
|
+
Request-specific configuration.
|
|
641
|
+
|
|
642
|
+
Returns
|
|
643
|
+
-------
|
|
644
|
+
typing.Optional[typing.Any]
|
|
645
|
+
Successful Response
|
|
646
|
+
|
|
647
|
+
Examples
|
|
648
|
+
--------
|
|
649
|
+
import asyncio
|
|
650
|
+
|
|
651
|
+
from letta import AsyncLetta
|
|
652
|
+
|
|
653
|
+
client = AsyncLetta(
|
|
654
|
+
token="YOUR_TOKEN",
|
|
655
|
+
)
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
async def main() -> None:
|
|
659
|
+
await client.sources.delete(
|
|
660
|
+
source_id="source_id",
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
asyncio.run(main())
|
|
665
|
+
"""
|
|
666
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
667
|
+
f"v1/sources/{jsonable_encoder(source_id)}",
|
|
668
|
+
method="DELETE",
|
|
669
|
+
request_options=request_options,
|
|
670
|
+
)
|
|
671
|
+
try:
|
|
672
|
+
if 200 <= _response.status_code < 300:
|
|
673
|
+
return typing.cast(
|
|
674
|
+
typing.Optional[typing.Any],
|
|
675
|
+
parse_obj_as(
|
|
676
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
677
|
+
object_=_response.json(),
|
|
678
|
+
),
|
|
679
|
+
)
|
|
680
|
+
if _response.status_code == 422:
|
|
681
|
+
raise UnprocessableEntityError(
|
|
682
|
+
typing.cast(
|
|
683
|
+
HttpValidationError,
|
|
684
|
+
parse_obj_as(
|
|
685
|
+
type_=HttpValidationError, # type: ignore
|
|
686
|
+
object_=_response.json(),
|
|
687
|
+
),
|
|
688
|
+
)
|
|
689
|
+
)
|
|
690
|
+
_response_json = _response.json()
|
|
691
|
+
except JSONDecodeError:
|
|
692
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
693
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
694
|
+
|
|
695
|
+
async def update(
|
|
696
|
+
self,
|
|
697
|
+
source_id: str,
|
|
698
|
+
*,
|
|
699
|
+
name: typing.Optional[str] = OMIT,
|
|
700
|
+
description: typing.Optional[str] = OMIT,
|
|
701
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
702
|
+
embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
|
|
703
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
704
|
+
) -> Source:
|
|
705
|
+
"""
|
|
706
|
+
Update the name or documentation of an existing data source.
|
|
707
|
+
|
|
708
|
+
Parameters
|
|
709
|
+
----------
|
|
710
|
+
source_id : str
|
|
711
|
+
|
|
712
|
+
name : typing.Optional[str]
|
|
713
|
+
The name of the source.
|
|
714
|
+
|
|
715
|
+
description : typing.Optional[str]
|
|
716
|
+
The description of the source.
|
|
717
|
+
|
|
718
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
719
|
+
Metadata associated with the source.
|
|
720
|
+
|
|
721
|
+
embedding_config : typing.Optional[EmbeddingConfig]
|
|
722
|
+
The embedding configuration used by the source.
|
|
723
|
+
|
|
724
|
+
request_options : typing.Optional[RequestOptions]
|
|
725
|
+
Request-specific configuration.
|
|
726
|
+
|
|
727
|
+
Returns
|
|
728
|
+
-------
|
|
729
|
+
Source
|
|
730
|
+
Successful Response
|
|
731
|
+
|
|
732
|
+
Examples
|
|
733
|
+
--------
|
|
734
|
+
import asyncio
|
|
735
|
+
|
|
736
|
+
from letta import AsyncLetta
|
|
737
|
+
|
|
738
|
+
client = AsyncLetta(
|
|
739
|
+
token="YOUR_TOKEN",
|
|
740
|
+
)
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
async def main() -> None:
|
|
744
|
+
await client.sources.update(
|
|
745
|
+
source_id="source_id",
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
asyncio.run(main())
|
|
750
|
+
"""
|
|
751
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
752
|
+
f"v1/sources/{jsonable_encoder(source_id)}",
|
|
753
|
+
method="PATCH",
|
|
754
|
+
json={
|
|
755
|
+
"name": name,
|
|
756
|
+
"description": description,
|
|
757
|
+
"metadata_": metadata,
|
|
758
|
+
"embedding_config": convert_and_respect_annotation_metadata(
|
|
759
|
+
object_=embedding_config, annotation=EmbeddingConfig, direction="write"
|
|
760
|
+
),
|
|
761
|
+
},
|
|
762
|
+
headers={
|
|
763
|
+
"content-type": "application/json",
|
|
764
|
+
},
|
|
765
|
+
request_options=request_options,
|
|
766
|
+
omit=OMIT,
|
|
767
|
+
)
|
|
768
|
+
try:
|
|
769
|
+
if 200 <= _response.status_code < 300:
|
|
770
|
+
return typing.cast(
|
|
771
|
+
Source,
|
|
772
|
+
parse_obj_as(
|
|
773
|
+
type_=Source, # type: ignore
|
|
774
|
+
object_=_response.json(),
|
|
775
|
+
),
|
|
776
|
+
)
|
|
777
|
+
if _response.status_code == 422:
|
|
778
|
+
raise UnprocessableEntityError(
|
|
779
|
+
typing.cast(
|
|
780
|
+
HttpValidationError,
|
|
781
|
+
parse_obj_as(
|
|
782
|
+
type_=HttpValidationError, # type: ignore
|
|
783
|
+
object_=_response.json(),
|
|
784
|
+
),
|
|
785
|
+
)
|
|
786
|
+
)
|
|
787
|
+
_response_json = _response.json()
|
|
788
|
+
except JSONDecodeError:
|
|
789
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
790
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
791
|
+
|
|
792
|
+
async def get_by_name(self, source_name: str, *, request_options: typing.Optional[RequestOptions] = None) -> str:
|
|
793
|
+
"""
|
|
794
|
+
Get a source by name
|
|
795
|
+
|
|
796
|
+
Parameters
|
|
797
|
+
----------
|
|
798
|
+
source_name : str
|
|
799
|
+
|
|
800
|
+
request_options : typing.Optional[RequestOptions]
|
|
801
|
+
Request-specific configuration.
|
|
802
|
+
|
|
803
|
+
Returns
|
|
804
|
+
-------
|
|
805
|
+
str
|
|
806
|
+
Successful Response
|
|
807
|
+
|
|
808
|
+
Examples
|
|
809
|
+
--------
|
|
810
|
+
import asyncio
|
|
811
|
+
|
|
812
|
+
from letta import AsyncLetta
|
|
813
|
+
|
|
814
|
+
client = AsyncLetta(
|
|
815
|
+
token="YOUR_TOKEN",
|
|
816
|
+
)
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
async def main() -> None:
|
|
820
|
+
await client.sources.get_by_name(
|
|
821
|
+
source_name="source_name",
|
|
822
|
+
)
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
asyncio.run(main())
|
|
826
|
+
"""
|
|
827
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
828
|
+
f"v1/sources/name/{jsonable_encoder(source_name)}",
|
|
829
|
+
method="GET",
|
|
830
|
+
request_options=request_options,
|
|
831
|
+
)
|
|
832
|
+
try:
|
|
833
|
+
if 200 <= _response.status_code < 300:
|
|
834
|
+
return typing.cast(
|
|
835
|
+
str,
|
|
836
|
+
parse_obj_as(
|
|
837
|
+
type_=str, # type: ignore
|
|
838
|
+
object_=_response.json(),
|
|
839
|
+
),
|
|
840
|
+
)
|
|
841
|
+
if _response.status_code == 422:
|
|
842
|
+
raise UnprocessableEntityError(
|
|
843
|
+
typing.cast(
|
|
844
|
+
HttpValidationError,
|
|
845
|
+
parse_obj_as(
|
|
846
|
+
type_=HttpValidationError, # type: ignore
|
|
847
|
+
object_=_response.json(),
|
|
848
|
+
),
|
|
849
|
+
)
|
|
850
|
+
)
|
|
851
|
+
_response_json = _response.json()
|
|
852
|
+
except JSONDecodeError:
|
|
853
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
854
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
855
|
+
|
|
856
|
+
async def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Source]:
|
|
857
|
+
"""
|
|
858
|
+
List all data sources created by a user.
|
|
859
|
+
|
|
860
|
+
Parameters
|
|
861
|
+
----------
|
|
862
|
+
request_options : typing.Optional[RequestOptions]
|
|
863
|
+
Request-specific configuration.
|
|
864
|
+
|
|
865
|
+
Returns
|
|
866
|
+
-------
|
|
867
|
+
typing.List[Source]
|
|
868
|
+
Successful Response
|
|
869
|
+
|
|
870
|
+
Examples
|
|
871
|
+
--------
|
|
872
|
+
import asyncio
|
|
873
|
+
|
|
874
|
+
from letta import AsyncLetta
|
|
875
|
+
|
|
876
|
+
client = AsyncLetta(
|
|
877
|
+
token="YOUR_TOKEN",
|
|
878
|
+
)
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
async def main() -> None:
|
|
882
|
+
await client.sources.list()
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
asyncio.run(main())
|
|
886
|
+
"""
|
|
887
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
888
|
+
"v1/sources/",
|
|
889
|
+
method="GET",
|
|
890
|
+
request_options=request_options,
|
|
891
|
+
)
|
|
892
|
+
try:
|
|
893
|
+
if 200 <= _response.status_code < 300:
|
|
894
|
+
return typing.cast(
|
|
895
|
+
typing.List[Source],
|
|
896
|
+
parse_obj_as(
|
|
897
|
+
type_=typing.List[Source], # type: ignore
|
|
898
|
+
object_=_response.json(),
|
|
899
|
+
),
|
|
900
|
+
)
|
|
901
|
+
if _response.status_code == 422:
|
|
902
|
+
raise UnprocessableEntityError(
|
|
903
|
+
typing.cast(
|
|
904
|
+
HttpValidationError,
|
|
905
|
+
parse_obj_as(
|
|
906
|
+
type_=HttpValidationError, # type: ignore
|
|
907
|
+
object_=_response.json(),
|
|
908
|
+
),
|
|
909
|
+
)
|
|
910
|
+
)
|
|
911
|
+
_response_json = _response.json()
|
|
912
|
+
except JSONDecodeError:
|
|
913
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
914
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
915
|
+
|
|
916
|
+
async def create(
|
|
917
|
+
self,
|
|
918
|
+
*,
|
|
919
|
+
name: str,
|
|
920
|
+
embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
|
|
921
|
+
description: typing.Optional[str] = OMIT,
|
|
922
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
923
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
924
|
+
) -> Source:
|
|
925
|
+
"""
|
|
926
|
+
Create a new data source.
|
|
927
|
+
|
|
928
|
+
Parameters
|
|
929
|
+
----------
|
|
930
|
+
name : str
|
|
931
|
+
The name of the source.
|
|
932
|
+
|
|
933
|
+
embedding_config : typing.Optional[EmbeddingConfig]
|
|
934
|
+
The embedding configuration used by the source.
|
|
935
|
+
|
|
936
|
+
description : typing.Optional[str]
|
|
937
|
+
The description of the source.
|
|
938
|
+
|
|
939
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
940
|
+
Metadata associated with the source.
|
|
941
|
+
|
|
942
|
+
request_options : typing.Optional[RequestOptions]
|
|
943
|
+
Request-specific configuration.
|
|
944
|
+
|
|
945
|
+
Returns
|
|
946
|
+
-------
|
|
947
|
+
Source
|
|
948
|
+
Successful Response
|
|
949
|
+
|
|
950
|
+
Examples
|
|
951
|
+
--------
|
|
952
|
+
import asyncio
|
|
953
|
+
|
|
954
|
+
from letta import AsyncLetta
|
|
955
|
+
|
|
956
|
+
client = AsyncLetta(
|
|
957
|
+
token="YOUR_TOKEN",
|
|
958
|
+
)
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
async def main() -> None:
|
|
962
|
+
await client.sources.create(
|
|
963
|
+
name="name",
|
|
964
|
+
)
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
asyncio.run(main())
|
|
968
|
+
"""
|
|
969
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
970
|
+
"v1/sources/",
|
|
971
|
+
method="POST",
|
|
972
|
+
json={
|
|
973
|
+
"name": name,
|
|
974
|
+
"embedding_config": convert_and_respect_annotation_metadata(
|
|
975
|
+
object_=embedding_config, annotation=EmbeddingConfig, direction="write"
|
|
976
|
+
),
|
|
977
|
+
"description": description,
|
|
978
|
+
"metadata_": metadata,
|
|
979
|
+
},
|
|
980
|
+
headers={
|
|
981
|
+
"content-type": "application/json",
|
|
982
|
+
},
|
|
983
|
+
request_options=request_options,
|
|
984
|
+
omit=OMIT,
|
|
985
|
+
)
|
|
986
|
+
try:
|
|
987
|
+
if 200 <= _response.status_code < 300:
|
|
988
|
+
return typing.cast(
|
|
989
|
+
Source,
|
|
990
|
+
parse_obj_as(
|
|
991
|
+
type_=Source, # type: ignore
|
|
992
|
+
object_=_response.json(),
|
|
993
|
+
),
|
|
994
|
+
)
|
|
995
|
+
if _response.status_code == 422:
|
|
996
|
+
raise UnprocessableEntityError(
|
|
997
|
+
typing.cast(
|
|
998
|
+
HttpValidationError,
|
|
999
|
+
parse_obj_as(
|
|
1000
|
+
type_=HttpValidationError, # type: ignore
|
|
1001
|
+
object_=_response.json(),
|
|
1002
|
+
),
|
|
1003
|
+
)
|
|
1004
|
+
)
|
|
1005
|
+
_response_json = _response.json()
|
|
1006
|
+
except JSONDecodeError:
|
|
1007
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1008
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1009
|
+
|
|
1010
|
+
async def attach(
|
|
1011
|
+
self, source_id: str, *, agent_id: str, request_options: typing.Optional[RequestOptions] = None
|
|
1012
|
+
) -> Source:
|
|
1013
|
+
"""
|
|
1014
|
+
Attach a data source to an existing agent.
|
|
1015
|
+
|
|
1016
|
+
Parameters
|
|
1017
|
+
----------
|
|
1018
|
+
source_id : str
|
|
1019
|
+
|
|
1020
|
+
agent_id : str
|
|
1021
|
+
The unique identifier of the agent to attach the source to.
|
|
1022
|
+
|
|
1023
|
+
request_options : typing.Optional[RequestOptions]
|
|
1024
|
+
Request-specific configuration.
|
|
1025
|
+
|
|
1026
|
+
Returns
|
|
1027
|
+
-------
|
|
1028
|
+
Source
|
|
1029
|
+
Successful Response
|
|
1030
|
+
|
|
1031
|
+
Examples
|
|
1032
|
+
--------
|
|
1033
|
+
import asyncio
|
|
1034
|
+
|
|
1035
|
+
from letta import AsyncLetta
|
|
1036
|
+
|
|
1037
|
+
client = AsyncLetta(
|
|
1038
|
+
token="YOUR_TOKEN",
|
|
1039
|
+
)
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
async def main() -> None:
|
|
1043
|
+
await client.sources.attach(
|
|
1044
|
+
source_id="source_id",
|
|
1045
|
+
agent_id="agent_id",
|
|
1046
|
+
)
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
asyncio.run(main())
|
|
1050
|
+
"""
|
|
1051
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1052
|
+
f"v1/sources/{jsonable_encoder(source_id)}/attach",
|
|
1053
|
+
method="POST",
|
|
1054
|
+
params={
|
|
1055
|
+
"agent_id": agent_id,
|
|
1056
|
+
},
|
|
1057
|
+
request_options=request_options,
|
|
1058
|
+
)
|
|
1059
|
+
try:
|
|
1060
|
+
if 200 <= _response.status_code < 300:
|
|
1061
|
+
return typing.cast(
|
|
1062
|
+
Source,
|
|
1063
|
+
parse_obj_as(
|
|
1064
|
+
type_=Source, # type: ignore
|
|
1065
|
+
object_=_response.json(),
|
|
1066
|
+
),
|
|
1067
|
+
)
|
|
1068
|
+
if _response.status_code == 422:
|
|
1069
|
+
raise UnprocessableEntityError(
|
|
1070
|
+
typing.cast(
|
|
1071
|
+
HttpValidationError,
|
|
1072
|
+
parse_obj_as(
|
|
1073
|
+
type_=HttpValidationError, # type: ignore
|
|
1074
|
+
object_=_response.json(),
|
|
1075
|
+
),
|
|
1076
|
+
)
|
|
1077
|
+
)
|
|
1078
|
+
_response_json = _response.json()
|
|
1079
|
+
except JSONDecodeError:
|
|
1080
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1081
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1082
|
+
|
|
1083
|
+
async def detach(
|
|
1084
|
+
self, source_id: str, *, agent_id: str, request_options: typing.Optional[RequestOptions] = None
|
|
1085
|
+
) -> Source:
|
|
1086
|
+
"""
|
|
1087
|
+
Detach a data source from an existing agent.
|
|
1088
|
+
|
|
1089
|
+
Parameters
|
|
1090
|
+
----------
|
|
1091
|
+
source_id : str
|
|
1092
|
+
|
|
1093
|
+
agent_id : str
|
|
1094
|
+
The unique identifier of the agent to detach the source from.
|
|
1095
|
+
|
|
1096
|
+
request_options : typing.Optional[RequestOptions]
|
|
1097
|
+
Request-specific configuration.
|
|
1098
|
+
|
|
1099
|
+
Returns
|
|
1100
|
+
-------
|
|
1101
|
+
Source
|
|
1102
|
+
Successful Response
|
|
1103
|
+
|
|
1104
|
+
Examples
|
|
1105
|
+
--------
|
|
1106
|
+
import asyncio
|
|
1107
|
+
|
|
1108
|
+
from letta import AsyncLetta
|
|
1109
|
+
|
|
1110
|
+
client = AsyncLetta(
|
|
1111
|
+
token="YOUR_TOKEN",
|
|
1112
|
+
)
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
async def main() -> None:
|
|
1116
|
+
await client.sources.detach(
|
|
1117
|
+
source_id="source_id",
|
|
1118
|
+
agent_id="agent_id",
|
|
1119
|
+
)
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
asyncio.run(main())
|
|
1123
|
+
"""
|
|
1124
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1125
|
+
f"v1/sources/{jsonable_encoder(source_id)}/detach",
|
|
1126
|
+
method="POST",
|
|
1127
|
+
params={
|
|
1128
|
+
"agent_id": agent_id,
|
|
1129
|
+
},
|
|
1130
|
+
request_options=request_options,
|
|
1131
|
+
)
|
|
1132
|
+
try:
|
|
1133
|
+
if 200 <= _response.status_code < 300:
|
|
1134
|
+
return typing.cast(
|
|
1135
|
+
Source,
|
|
1136
|
+
parse_obj_as(
|
|
1137
|
+
type_=Source, # type: ignore
|
|
1138
|
+
object_=_response.json(),
|
|
1139
|
+
),
|
|
1140
|
+
)
|
|
1141
|
+
if _response.status_code == 422:
|
|
1142
|
+
raise UnprocessableEntityError(
|
|
1143
|
+
typing.cast(
|
|
1144
|
+
HttpValidationError,
|
|
1145
|
+
parse_obj_as(
|
|
1146
|
+
type_=HttpValidationError, # type: ignore
|
|
1147
|
+
object_=_response.json(),
|
|
1148
|
+
),
|
|
1149
|
+
)
|
|
1150
|
+
)
|
|
1151
|
+
_response_json = _response.json()
|
|
1152
|
+
except JSONDecodeError:
|
|
1153
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1154
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|