vector-bridge 1.0.0__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.
- vector_bridge/__init__.py +2763 -0
- vector_bridge/schema/__init__.py +0 -0
- vector_bridge/schema/ai_knowledge/__init__.py +34 -0
- vector_bridge/schema/ai_knowledge/filesystem.py +140 -0
- vector_bridge/schema/ai_knowledge/schemaless.py +45 -0
- vector_bridge/schema/api_keys.py +32 -0
- vector_bridge/schema/chat.py +74 -0
- vector_bridge/schema/error.py +13 -0
- vector_bridge/schema/functions.py +87 -0
- vector_bridge/schema/helpers/__init__.py +0 -0
- vector_bridge/schema/helpers/enums.py +326 -0
- vector_bridge/schema/helpers/weaviate_schema.py +159 -0
- vector_bridge/schema/instruction.py +182 -0
- vector_bridge/schema/integrations.py +76 -0
- vector_bridge/schema/logs.py +28 -0
- vector_bridge/schema/messages.py +210 -0
- vector_bridge/schema/notifications.py +51 -0
- vector_bridge/schema/organization.py +13 -0
- vector_bridge/schema/security_group.py +153 -0
- vector_bridge/schema/settings.py +140 -0
- vector_bridge/schema/usage.py +31 -0
- vector_bridge/schema/user.py +166 -0
- vector_bridge/schema/user_integrations.py +32 -0
- vector_bridge-1.0.0.dist-info/METADATA +902 -0
- vector_bridge-1.0.0.dist-info/RECORD +26 -0
- vector_bridge-1.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,2763 @@
|
|
|
1
|
+
from typing import Any, Dict, List, Optional, TypeVar, Union
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
|
|
6
|
+
from vector_bridge.schema.ai_knowledge import AIKnowledgeList
|
|
7
|
+
from vector_bridge.schema.ai_knowledge.filesystem import (
|
|
8
|
+
AIKnowledgeFileSystemFilters, AIKnowledgeFileSystemItem,
|
|
9
|
+
AIKnowledgeFileSystemItemsList, FileSystemItemAggregatedCount)
|
|
10
|
+
from vector_bridge.schema.ai_knowledge.schemaless import AIKnowledgeCreate
|
|
11
|
+
from vector_bridge.schema.api_keys import APIKey, APIKeyCreate
|
|
12
|
+
from vector_bridge.schema.chat import Chat, ChatsList
|
|
13
|
+
from vector_bridge.schema.error import HTTPException
|
|
14
|
+
from vector_bridge.schema.functions import (Function, FunctionCreate,
|
|
15
|
+
FunctionUpdate, PaginatedFunctions)
|
|
16
|
+
from vector_bridge.schema.helpers.enums import (AIProviders, FileAccessType,
|
|
17
|
+
MessageStorageMode, SortOrder,
|
|
18
|
+
WeaviateKey)
|
|
19
|
+
from vector_bridge.schema.instruction import (Instruction, InstructionCreate,
|
|
20
|
+
PaginatedInstructions)
|
|
21
|
+
from vector_bridge.schema.integrations import Integration, IntegrationCreate
|
|
22
|
+
from vector_bridge.schema.logs import PaginatedLogs
|
|
23
|
+
from vector_bridge.schema.messages import (MessageInDB, MessagesListDynamoDB,
|
|
24
|
+
MessagesListVectorDB,
|
|
25
|
+
StreamingResponse)
|
|
26
|
+
from vector_bridge.schema.notifications import NotificationsList
|
|
27
|
+
from vector_bridge.schema.organization import Organization
|
|
28
|
+
from vector_bridge.schema.security_group import (PaginatedSecurityGroups,
|
|
29
|
+
SecurityGroup,
|
|
30
|
+
SecurityGroupCreate,
|
|
31
|
+
SecurityGroupUpdate)
|
|
32
|
+
from vector_bridge.schema.settings import Settings
|
|
33
|
+
from vector_bridge.schema.usage import PaginatedRequestUsages
|
|
34
|
+
from vector_bridge.schema.user import (User, UsersList, UserUpdate,
|
|
35
|
+
UserWithIntegrations)
|
|
36
|
+
|
|
37
|
+
# Type definitions from OpenAPI spec
|
|
38
|
+
T = TypeVar("T")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# Models based on OpenAPI schema
|
|
42
|
+
class Token(BaseModel):
|
|
43
|
+
access_token: str
|
|
44
|
+
token_type: str
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class VectorBridgeClient:
|
|
48
|
+
"""
|
|
49
|
+
Python client for the VectorBridge.ai API.
|
|
50
|
+
|
|
51
|
+
Provides access to all functionality of the VectorBridge platform including
|
|
52
|
+
authentication, user management, AI processing, vector operations, and more.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
base_url: str = "https://api.vectorbridge.ai",
|
|
58
|
+
api_key: str = None,
|
|
59
|
+
integration_name: str = "default",
|
|
60
|
+
):
|
|
61
|
+
"""
|
|
62
|
+
Initialize the VectorBridge client.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
base_url: The base URL of the VectorBridge API. Defaults to the development server.
|
|
66
|
+
"""
|
|
67
|
+
self.base_url = base_url
|
|
68
|
+
self.session = requests.Session()
|
|
69
|
+
self.access_token = None
|
|
70
|
+
self.api_key = api_key
|
|
71
|
+
self.integration_name = integration_name
|
|
72
|
+
|
|
73
|
+
# Initialize admin client
|
|
74
|
+
self.admin = AdminClient(self)
|
|
75
|
+
|
|
76
|
+
# Initialize user client
|
|
77
|
+
self.ai = AIClient(self)
|
|
78
|
+
self.ai_message = AIMessageClient(self)
|
|
79
|
+
self.functions = FunctionClient(self)
|
|
80
|
+
self.queries = QueryClient(self)
|
|
81
|
+
|
|
82
|
+
def login(self, username: str, password: str) -> Token:
|
|
83
|
+
"""
|
|
84
|
+
Log in to obtain an access token.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
username: User's email
|
|
88
|
+
password: User's password
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
Token object containing access_token and token_type
|
|
92
|
+
"""
|
|
93
|
+
url = f"{self.base_url}/token"
|
|
94
|
+
data = {
|
|
95
|
+
"username": username,
|
|
96
|
+
"password": password,
|
|
97
|
+
}
|
|
98
|
+
response = self.session.post(
|
|
99
|
+
url,
|
|
100
|
+
data=data,
|
|
101
|
+
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
|
102
|
+
)
|
|
103
|
+
result = self._handle_response(response)
|
|
104
|
+
self.access_token = result["access_token"]
|
|
105
|
+
return Token(**result)
|
|
106
|
+
|
|
107
|
+
def _get_auth_headers(self) -> Dict[str, str]:
|
|
108
|
+
"""Get headers with bearer token authentication."""
|
|
109
|
+
if not self.access_token:
|
|
110
|
+
raise ValueError("Authentication required. Call login() first.")
|
|
111
|
+
|
|
112
|
+
return {"Authorization": f"Bearer {self.access_token}"}
|
|
113
|
+
|
|
114
|
+
def _get_api_key_headers(self, api_key: str) -> Dict[str, str]:
|
|
115
|
+
"""Get headers with API key authentication."""
|
|
116
|
+
return {"Api-Key": api_key}
|
|
117
|
+
|
|
118
|
+
def _handle_response(self, response: requests.Response) -> Any:
|
|
119
|
+
"""Handle API response and errors."""
|
|
120
|
+
if 200 <= response.status_code < 300:
|
|
121
|
+
if response.status_code == 204:
|
|
122
|
+
return None
|
|
123
|
+
try:
|
|
124
|
+
return response.json()
|
|
125
|
+
except ValueError:
|
|
126
|
+
return response.text
|
|
127
|
+
else:
|
|
128
|
+
try:
|
|
129
|
+
error_data = response.json()
|
|
130
|
+
exc = HTTPException(
|
|
131
|
+
status_code=response.status_code,
|
|
132
|
+
detail=error_data.get("detail"),
|
|
133
|
+
)
|
|
134
|
+
except ValueError:
|
|
135
|
+
exc = HTTPException(
|
|
136
|
+
status_code=response.status_code,
|
|
137
|
+
detail=response.text,
|
|
138
|
+
)
|
|
139
|
+
raise exc
|
|
140
|
+
|
|
141
|
+
def ping(self) -> str:
|
|
142
|
+
"""
|
|
143
|
+
Ping the API to check if it's available.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
Response string
|
|
147
|
+
"""
|
|
148
|
+
url = f"{self.base_url}/v1/ping"
|
|
149
|
+
response = self.session.get(url)
|
|
150
|
+
return self._handle_response(response)
|
|
151
|
+
|
|
152
|
+
def generate_crypto_key(self) -> str:
|
|
153
|
+
"""
|
|
154
|
+
Generate a crypto key.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
Generated crypto key
|
|
158
|
+
"""
|
|
159
|
+
url = f"{self.base_url}/v1/secrets/generate-crypto-key"
|
|
160
|
+
response = self.session.get(url)
|
|
161
|
+
return self._handle_response(response)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class AdminClient:
|
|
165
|
+
"""Admin client providing access to all admin endpoints that require authentication."""
|
|
166
|
+
|
|
167
|
+
def __init__(self, client: VectorBridgeClient):
|
|
168
|
+
self.client = client
|
|
169
|
+
|
|
170
|
+
# Initialize admin subclients
|
|
171
|
+
self.settings = SettingsAdmin(client)
|
|
172
|
+
self.logs = LogsAdmin(client)
|
|
173
|
+
self.notifications = NotificationsAdmin(client)
|
|
174
|
+
self.usage = UsageAdmin(client)
|
|
175
|
+
self.user = UserAdmin(client)
|
|
176
|
+
self.organization = OrganizationAdmin(client)
|
|
177
|
+
self.security_groups = SecurityGroupsAdmin(client)
|
|
178
|
+
self.integrations = IntegrationsAdmin(client)
|
|
179
|
+
self.instructions = InstructionsAdmin(client)
|
|
180
|
+
self.functions = FunctionsAdmin(client)
|
|
181
|
+
self.api_keys = APIKeysAdmin(client)
|
|
182
|
+
self.chat = ChatAdmin(client)
|
|
183
|
+
self.message = MessageAdmin(client)
|
|
184
|
+
self.ai_knowledge = AIKnowledgeAdmin(client)
|
|
185
|
+
# self.database = DatabaseAdmin(client) # TODO: Add support
|
|
186
|
+
self.queries = QueryAdmin(client)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class SettingsAdmin:
|
|
190
|
+
"""Admin client for settings endpoints."""
|
|
191
|
+
|
|
192
|
+
def __init__(self, client: VectorBridgeClient):
|
|
193
|
+
self.client = client
|
|
194
|
+
|
|
195
|
+
def get_settings(self) -> Settings:
|
|
196
|
+
"""Get system settings."""
|
|
197
|
+
url = f"{self.client.base_url}/v1/settings"
|
|
198
|
+
headers = self.client._get_auth_headers()
|
|
199
|
+
response = self.client.session.get(url, headers=headers)
|
|
200
|
+
result = self.client._handle_response(response)
|
|
201
|
+
return Settings.model_validate(result)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class LogsAdmin:
|
|
205
|
+
"""Admin client for logs endpoints."""
|
|
206
|
+
|
|
207
|
+
def __init__(self, client: VectorBridgeClient):
|
|
208
|
+
self.client = client
|
|
209
|
+
|
|
210
|
+
def list_logs(
|
|
211
|
+
self,
|
|
212
|
+
integration_name: str = None,
|
|
213
|
+
limit: int = 25,
|
|
214
|
+
last_evaluated_key: Optional[str] = None,
|
|
215
|
+
filter_key: Optional[str] = None,
|
|
216
|
+
filter_value: Optional[str] = None,
|
|
217
|
+
) -> PaginatedLogs:
|
|
218
|
+
"""
|
|
219
|
+
List logs with optional filters and pagination.
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
integration_name: The name of the Integration
|
|
223
|
+
limit: Number of logs to return
|
|
224
|
+
last_evaluated_key: Last evaluated key for pagination
|
|
225
|
+
filter_key: Logs Filter (USER or API_KEY_HASH)
|
|
226
|
+
filter_value: Filter logs by user ID or API key hash
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
PaginatedLogs with logs and pagination information
|
|
230
|
+
"""
|
|
231
|
+
if integration_name is None:
|
|
232
|
+
integration_name = self.client.integration_name
|
|
233
|
+
|
|
234
|
+
url = f"{self.client.base_url}/v1/admin/logs"
|
|
235
|
+
params = {"integration_name": integration_name, "limit": limit}
|
|
236
|
+
if last_evaluated_key:
|
|
237
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
238
|
+
if filter_key:
|
|
239
|
+
params["filter_key"] = filter_key
|
|
240
|
+
if filter_value:
|
|
241
|
+
params["filter_value"] = filter_value
|
|
242
|
+
|
|
243
|
+
headers = self.client._get_auth_headers()
|
|
244
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
245
|
+
result = self.client._handle_response(response)
|
|
246
|
+
return PaginatedLogs.model_validate(result)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
class NotificationsAdmin:
|
|
250
|
+
"""Admin client for notifications endpoints."""
|
|
251
|
+
|
|
252
|
+
def __init__(self, client: VectorBridgeClient):
|
|
253
|
+
self.client = client
|
|
254
|
+
|
|
255
|
+
def list_notifications(
|
|
256
|
+
self,
|
|
257
|
+
integration_name: str = None,
|
|
258
|
+
limit: int = 25,
|
|
259
|
+
last_evaluated_key: Optional[str] = None,
|
|
260
|
+
) -> NotificationsList:
|
|
261
|
+
"""
|
|
262
|
+
List notifications.
|
|
263
|
+
|
|
264
|
+
Args:
|
|
265
|
+
integration_name: The name of the Integration
|
|
266
|
+
limit: Number of notifications to return
|
|
267
|
+
last_evaluated_key: Last evaluated key for pagination
|
|
268
|
+
|
|
269
|
+
Returns:
|
|
270
|
+
NotificationsList with notifications and pagination information
|
|
271
|
+
"""
|
|
272
|
+
if integration_name is None:
|
|
273
|
+
integration_name = self.client.integration_name
|
|
274
|
+
|
|
275
|
+
url = f"{self.client.base_url}/v1/admin/notifications"
|
|
276
|
+
params = {"integration_name": integration_name, "limit": limit}
|
|
277
|
+
if last_evaluated_key:
|
|
278
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
279
|
+
|
|
280
|
+
headers = self.client._get_auth_headers()
|
|
281
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
282
|
+
result = self.client._handle_response(response)
|
|
283
|
+
return NotificationsList.model_validate(result)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
class UsageAdmin:
|
|
287
|
+
"""Admin client for usage endpoints."""
|
|
288
|
+
|
|
289
|
+
def __init__(self, client: VectorBridgeClient):
|
|
290
|
+
self.client = client
|
|
291
|
+
|
|
292
|
+
def list_usage(
|
|
293
|
+
self,
|
|
294
|
+
primary_key: str,
|
|
295
|
+
integration_name: str = None,
|
|
296
|
+
limit: int = 25,
|
|
297
|
+
last_evaluated_key: Optional[str] = None,
|
|
298
|
+
) -> PaginatedRequestUsages:
|
|
299
|
+
"""
|
|
300
|
+
List usage with optional filters and pagination.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
primary_key: Filter usage by organization ID, integration ID or API key hash
|
|
304
|
+
integration_name: The name of the Integration
|
|
305
|
+
limit: Number of usage records to return
|
|
306
|
+
last_evaluated_key: Last evaluated key for pagination
|
|
307
|
+
|
|
308
|
+
Returns:
|
|
309
|
+
PaginatedRequestUsages with usage records and pagination information
|
|
310
|
+
"""
|
|
311
|
+
if integration_name is None:
|
|
312
|
+
integration_name = self.client.integration_name
|
|
313
|
+
|
|
314
|
+
url = f"{self.client.base_url}/v1/admin/usage"
|
|
315
|
+
params = {
|
|
316
|
+
"primary_key": primary_key,
|
|
317
|
+
"integration_name": integration_name,
|
|
318
|
+
"limit": limit,
|
|
319
|
+
}
|
|
320
|
+
if last_evaluated_key:
|
|
321
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
322
|
+
|
|
323
|
+
headers = self.client._get_auth_headers()
|
|
324
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
325
|
+
result = self.client._handle_response(response)
|
|
326
|
+
return PaginatedRequestUsages.model_validate(result)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
class UserAdmin:
|
|
330
|
+
"""Admin client for user management endpoints."""
|
|
331
|
+
|
|
332
|
+
def __init__(self, client: VectorBridgeClient):
|
|
333
|
+
self.client = client
|
|
334
|
+
|
|
335
|
+
def get_me(self) -> UserWithIntegrations:
|
|
336
|
+
"""
|
|
337
|
+
Retrieve information about the currently authenticated user.
|
|
338
|
+
|
|
339
|
+
Returns:
|
|
340
|
+
User information including integrations
|
|
341
|
+
"""
|
|
342
|
+
url = f"{self.client.base_url}/v1/admin/user/me"
|
|
343
|
+
headers = self.client._get_auth_headers()
|
|
344
|
+
response = self.client.session.get(url, headers=headers)
|
|
345
|
+
data = self.client._handle_response(response)
|
|
346
|
+
return UserWithIntegrations.model_validate(data)
|
|
347
|
+
|
|
348
|
+
def get_users_in_my_organization(self, limit: int = 25, last_evaluated_key: Optional[str] = None) -> UsersList:
|
|
349
|
+
"""
|
|
350
|
+
Retrieve information about the users of the authenticated user's organization.
|
|
351
|
+
|
|
352
|
+
Args:
|
|
353
|
+
limit: Number of users to return
|
|
354
|
+
last_evaluated_key: Last evaluated key for pagination
|
|
355
|
+
|
|
356
|
+
Returns:
|
|
357
|
+
UsersList with users and pagination information
|
|
358
|
+
"""
|
|
359
|
+
url = f"{self.client.base_url}/v1/admin/users/my-organization"
|
|
360
|
+
params = {"limit": limit}
|
|
361
|
+
if last_evaluated_key:
|
|
362
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
363
|
+
|
|
364
|
+
headers = self.client._get_auth_headers()
|
|
365
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
366
|
+
result = self.client._handle_response(response)
|
|
367
|
+
return UsersList.model_validate(result)
|
|
368
|
+
|
|
369
|
+
def update_me(self, user_data: UserUpdate) -> User:
|
|
370
|
+
"""
|
|
371
|
+
Update details of the currently authenticated user.
|
|
372
|
+
|
|
373
|
+
Args:
|
|
374
|
+
user_data: Dictionary containing user fields to update
|
|
375
|
+
|
|
376
|
+
Returns:
|
|
377
|
+
Updated user information
|
|
378
|
+
"""
|
|
379
|
+
url = f"{self.client.base_url}/v1/admin/user/update/me"
|
|
380
|
+
headers = self.client._get_auth_headers()
|
|
381
|
+
response = self.client.session.put(url, headers=headers, json=user_data.model_dump())
|
|
382
|
+
data = self.client._handle_response(response)
|
|
383
|
+
return User.model_validate(data)
|
|
384
|
+
|
|
385
|
+
def change_password(self, old_password: str, new_password: str) -> User:
|
|
386
|
+
"""
|
|
387
|
+
Change password of the currently authenticated user.
|
|
388
|
+
|
|
389
|
+
Args:
|
|
390
|
+
old_password: Current password
|
|
391
|
+
new_password: New password
|
|
392
|
+
|
|
393
|
+
Returns:
|
|
394
|
+
Updated user information
|
|
395
|
+
"""
|
|
396
|
+
url = f"{self.client.base_url}/v1/admin/user/change-password/me"
|
|
397
|
+
data = {"old_password": old_password, "new_password": new_password}
|
|
398
|
+
headers = self.client._get_auth_headers()
|
|
399
|
+
response = self.client.session.put(url, headers=headers, json=data)
|
|
400
|
+
data = self.client._handle_response(response)
|
|
401
|
+
return User.model_validate(data)
|
|
402
|
+
|
|
403
|
+
def disable_me(self) -> None:
|
|
404
|
+
"""
|
|
405
|
+
Disable the account of the currently authenticated user.
|
|
406
|
+
"""
|
|
407
|
+
url = f"{self.client.base_url}/v1/admin/user/disable/me"
|
|
408
|
+
headers = self.client._get_auth_headers()
|
|
409
|
+
response = self.client.session.post(url, headers=headers)
|
|
410
|
+
self.client._handle_response(response)
|
|
411
|
+
|
|
412
|
+
def add_agent(self, email: str, first_name: str = "", last_name: str = "", password: str = "") -> User:
|
|
413
|
+
"""
|
|
414
|
+
Add a new agent user.
|
|
415
|
+
|
|
416
|
+
Args:
|
|
417
|
+
email: The email of the user
|
|
418
|
+
first_name: The first name of the user
|
|
419
|
+
last_name: The last name of the user
|
|
420
|
+
password: The password of the user
|
|
421
|
+
|
|
422
|
+
Returns:
|
|
423
|
+
Created user information
|
|
424
|
+
"""
|
|
425
|
+
url = f"{self.client.base_url}/v1/admin/user/add-agent"
|
|
426
|
+
params = {
|
|
427
|
+
"email": email,
|
|
428
|
+
"first_name": first_name,
|
|
429
|
+
"last_name": last_name,
|
|
430
|
+
"password": password,
|
|
431
|
+
}
|
|
432
|
+
headers = self.client._get_auth_headers()
|
|
433
|
+
response = self.client.session.post(url, headers=headers, params=params)
|
|
434
|
+
data = self.client._handle_response(response)
|
|
435
|
+
return User.model_validate(data)
|
|
436
|
+
|
|
437
|
+
def remove_agent(self, user_id: str) -> None:
|
|
438
|
+
"""
|
|
439
|
+
Remove an agent user.
|
|
440
|
+
|
|
441
|
+
Args:
|
|
442
|
+
user_id: The user to be removed
|
|
443
|
+
|
|
444
|
+
Returns:
|
|
445
|
+
None
|
|
446
|
+
"""
|
|
447
|
+
url = f"{self.client.base_url}/v1/admin/user/remove-agent/{user_id}"
|
|
448
|
+
headers = self.client._get_auth_headers()
|
|
449
|
+
response = self.client.session.post(url, headers=headers)
|
|
450
|
+
self.client._handle_response(response)
|
|
451
|
+
|
|
452
|
+
def get_user_by_id(self, user_id: str) -> Optional[User]:
|
|
453
|
+
"""
|
|
454
|
+
Retrieve user information based on their unique user ID.
|
|
455
|
+
|
|
456
|
+
Args:
|
|
457
|
+
user_id: The unique identifier of the user
|
|
458
|
+
|
|
459
|
+
Returns:
|
|
460
|
+
User information or None if not found
|
|
461
|
+
"""
|
|
462
|
+
url = f"{self.client.base_url}/v1/admin/user/id/{user_id}"
|
|
463
|
+
headers = self.client._get_auth_headers()
|
|
464
|
+
response = self.client.session.get(url, headers=headers)
|
|
465
|
+
data = self.client._handle_response(response)
|
|
466
|
+
return User.model_validate(data) if data else None
|
|
467
|
+
|
|
468
|
+
def get_user_by_email(self, email: str) -> Optional[User]:
|
|
469
|
+
"""
|
|
470
|
+
Retrieve user information based on their email address.
|
|
471
|
+
|
|
472
|
+
Args:
|
|
473
|
+
email: The email address of the user
|
|
474
|
+
|
|
475
|
+
Returns:
|
|
476
|
+
User information or None if not found
|
|
477
|
+
"""
|
|
478
|
+
url = f"{self.client.base_url}/v1/admin/user/email/{email}"
|
|
479
|
+
headers = self.client._get_auth_headers()
|
|
480
|
+
response = self.client.session.get(url, headers=headers)
|
|
481
|
+
data = self.client._handle_response(response)
|
|
482
|
+
return User.model_validate(data) if data else None
|
|
483
|
+
|
|
484
|
+
def disable_user(self, user_id: str) -> None:
|
|
485
|
+
"""
|
|
486
|
+
Disable a user account, identified by their unique user ID.
|
|
487
|
+
|
|
488
|
+
Args:
|
|
489
|
+
user_id: The unique identifier of the user whose account is to be disabled
|
|
490
|
+
"""
|
|
491
|
+
url = f"{self.client.base_url}/v1/admin/user/disable/{user_id}"
|
|
492
|
+
headers = self.client._get_auth_headers()
|
|
493
|
+
response = self.client.session.post(url, headers=headers)
|
|
494
|
+
self.client._handle_response(response)
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
class OrganizationAdmin:
|
|
498
|
+
"""Admin client for organization management endpoints."""
|
|
499
|
+
|
|
500
|
+
def __init__(self, client: VectorBridgeClient):
|
|
501
|
+
self.client = client
|
|
502
|
+
|
|
503
|
+
def get_my_organization(self) -> Organization:
|
|
504
|
+
"""
|
|
505
|
+
Retrieve detailed information about the organization linked to the currently authenticated user's account.
|
|
506
|
+
|
|
507
|
+
Returns:
|
|
508
|
+
Organization details
|
|
509
|
+
"""
|
|
510
|
+
url = f"{self.client.base_url}/v1/admin/organization/me"
|
|
511
|
+
headers = self.client._get_auth_headers()
|
|
512
|
+
response = self.client.session.get(url, headers=headers)
|
|
513
|
+
data = self.client._handle_response(response)
|
|
514
|
+
return Organization.model_validate(data)
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
class SecurityGroupsAdmin:
|
|
518
|
+
"""Admin client for security group management endpoints."""
|
|
519
|
+
|
|
520
|
+
def __init__(self, client: VectorBridgeClient):
|
|
521
|
+
self.client = client
|
|
522
|
+
|
|
523
|
+
def create_security_group(self, security_group_data: SecurityGroupCreate) -> SecurityGroup:
|
|
524
|
+
"""
|
|
525
|
+
Create a new security group.
|
|
526
|
+
|
|
527
|
+
Args:
|
|
528
|
+
organization_id: The ID of the organization
|
|
529
|
+
security_group_data: Details of the security group to create
|
|
530
|
+
|
|
531
|
+
Returns:
|
|
532
|
+
Created security group
|
|
533
|
+
"""
|
|
534
|
+
url = f"{self.client.base_url}/v1/admin/security-group/create"
|
|
535
|
+
headers = self.client._get_auth_headers()
|
|
536
|
+
response = self.client.session.post(url, headers=headers, json=security_group_data.model_dump())
|
|
537
|
+
result = self.client._handle_response(response)
|
|
538
|
+
return SecurityGroup.model_validate(result)
|
|
539
|
+
|
|
540
|
+
def update_security_group(self, group_id: str, security_group_data: SecurityGroupUpdate) -> SecurityGroup:
|
|
541
|
+
"""
|
|
542
|
+
Update an existing security group by ID.
|
|
543
|
+
|
|
544
|
+
Args:
|
|
545
|
+
group_id: The Security Group ID
|
|
546
|
+
security_group_data: Updated details for the security group
|
|
547
|
+
|
|
548
|
+
Returns:
|
|
549
|
+
Updated security group
|
|
550
|
+
"""
|
|
551
|
+
url = f"{self.client.base_url}/v1/admin/security-group/{group_id}/update"
|
|
552
|
+
headers = self.client._get_auth_headers()
|
|
553
|
+
response = self.client.session.put(url, headers=headers, json=security_group_data.model_dump())
|
|
554
|
+
result = self.client._handle_response(response)
|
|
555
|
+
return SecurityGroup.model_validate(result)
|
|
556
|
+
|
|
557
|
+
def get_security_group(self, group_id: str) -> Optional[SecurityGroup]:
|
|
558
|
+
"""
|
|
559
|
+
Retrieve details of a specific security group by ID.
|
|
560
|
+
|
|
561
|
+
Args:
|
|
562
|
+
group_id: The Security Group ID
|
|
563
|
+
|
|
564
|
+
Returns:
|
|
565
|
+
Security group details
|
|
566
|
+
"""
|
|
567
|
+
url = f"{self.client.base_url}/v1/admin/security-group/{group_id}"
|
|
568
|
+
headers = self.client._get_auth_headers()
|
|
569
|
+
response = self.client.session.get(url, headers=headers)
|
|
570
|
+
result = self.client._handle_response(response)
|
|
571
|
+
return SecurityGroup.model_validate(result) if result else None
|
|
572
|
+
|
|
573
|
+
def list_security_groups(
|
|
574
|
+
self,
|
|
575
|
+
limit: int = 10,
|
|
576
|
+
last_evaluated_key: Optional[str] = None,
|
|
577
|
+
sort_by: str = "created_at",
|
|
578
|
+
) -> PaginatedSecurityGroups:
|
|
579
|
+
"""
|
|
580
|
+
Retrieve a paginated list of all security groups for the organization.
|
|
581
|
+
|
|
582
|
+
Args:
|
|
583
|
+
limit: Number of items per page
|
|
584
|
+
last_evaluated_key: Key to continue pagination from
|
|
585
|
+
sort_by: The sort field
|
|
586
|
+
|
|
587
|
+
Returns:
|
|
588
|
+
PaginatedSecurityGroups with security groups and pagination information
|
|
589
|
+
"""
|
|
590
|
+
url = f"{self.client.base_url}/v1/admin/security-groups"
|
|
591
|
+
params = {"limit": limit, "sort_by": sort_by}
|
|
592
|
+
if last_evaluated_key:
|
|
593
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
594
|
+
|
|
595
|
+
headers = self.client._get_auth_headers()
|
|
596
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
597
|
+
result = self.client._handle_response(response)
|
|
598
|
+
return PaginatedSecurityGroups.model_validate(result)
|
|
599
|
+
|
|
600
|
+
def delete_security_group(self, group_id: str) -> None:
|
|
601
|
+
"""
|
|
602
|
+
Delete a specific security group by ID.
|
|
603
|
+
|
|
604
|
+
Args:
|
|
605
|
+
group_id: The Security Group ID
|
|
606
|
+
"""
|
|
607
|
+
url = f"{self.client.base_url}/v1/admin/security-group/{group_id}/delete"
|
|
608
|
+
headers = self.client._get_auth_headers()
|
|
609
|
+
response = self.client.session.delete(url, headers=headers)
|
|
610
|
+
if response.status_code != 204:
|
|
611
|
+
self.client._handle_response(response)
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
class IntegrationsAdmin:
|
|
615
|
+
"""Admin client for integrations management endpoints."""
|
|
616
|
+
|
|
617
|
+
def __init__(self, client: VectorBridgeClient):
|
|
618
|
+
self.client = client
|
|
619
|
+
|
|
620
|
+
def get_integrations_list(self) -> List[Integration]:
|
|
621
|
+
"""
|
|
622
|
+
Get a list of all integrations.
|
|
623
|
+
|
|
624
|
+
Returns:
|
|
625
|
+
List of integration objects
|
|
626
|
+
"""
|
|
627
|
+
url = f"{self.client.base_url}/v1/admin/integrations"
|
|
628
|
+
headers = self.client._get_auth_headers()
|
|
629
|
+
response = self.client.session.get(url, headers=headers)
|
|
630
|
+
data = self.client._handle_response(response)
|
|
631
|
+
return [Integration.model_validate(item) for item in data]
|
|
632
|
+
|
|
633
|
+
def get_integration_by_id(self, integration_id: str) -> Integration:
|
|
634
|
+
"""
|
|
635
|
+
Get integration by ID.
|
|
636
|
+
|
|
637
|
+
Args:
|
|
638
|
+
integration_id: The integration ID
|
|
639
|
+
|
|
640
|
+
Returns:
|
|
641
|
+
Integration object
|
|
642
|
+
"""
|
|
643
|
+
url = f"{self.client.base_url}/v1/admin/integration/id/{integration_id}"
|
|
644
|
+
headers = self.client._get_auth_headers()
|
|
645
|
+
response = self.client.session.get(url, headers=headers)
|
|
646
|
+
data = self.client._handle_response(response)
|
|
647
|
+
return Integration.model_validate(data)
|
|
648
|
+
|
|
649
|
+
def get_integration_by_name(self, integration_name: str = None) -> Integration:
|
|
650
|
+
"""
|
|
651
|
+
Get integration by name.
|
|
652
|
+
|
|
653
|
+
Args:
|
|
654
|
+
integration_name: The integration name
|
|
655
|
+
|
|
656
|
+
Returns:
|
|
657
|
+
Integration object
|
|
658
|
+
"""
|
|
659
|
+
if integration_name is None:
|
|
660
|
+
integration_name = self.client.integration_name
|
|
661
|
+
|
|
662
|
+
url = f"{self.client.base_url}/v1/admin/integration/name/{integration_name}"
|
|
663
|
+
headers = self.client._get_auth_headers()
|
|
664
|
+
response = self.client.session.get(url, headers=headers)
|
|
665
|
+
data = self.client._handle_response(response)
|
|
666
|
+
return Integration.model_validate(data)
|
|
667
|
+
|
|
668
|
+
def add_integration(self, integration_data: IntegrationCreate) -> Integration:
|
|
669
|
+
"""
|
|
670
|
+
Add a new integration.
|
|
671
|
+
|
|
672
|
+
Args:
|
|
673
|
+
integration_data: Integration details
|
|
674
|
+
|
|
675
|
+
Returns:
|
|
676
|
+
Created integration object
|
|
677
|
+
"""
|
|
678
|
+
url = f"{self.client.base_url}/v1/admin/integration/add"
|
|
679
|
+
headers = self.client._get_auth_headers()
|
|
680
|
+
response = self.client.session.post(url, headers=headers, json=integration_data.model_dump())
|
|
681
|
+
data = self.client._handle_response(response)
|
|
682
|
+
return Integration.model_validate(data)
|
|
683
|
+
|
|
684
|
+
def delete_integration(self, integration_name: str = None) -> List[Integration]:
|
|
685
|
+
"""
|
|
686
|
+
Delete an integration.
|
|
687
|
+
|
|
688
|
+
Args:
|
|
689
|
+
integration_name: The name of the integration to delete
|
|
690
|
+
|
|
691
|
+
Returns:
|
|
692
|
+
List of remaining integrations
|
|
693
|
+
"""
|
|
694
|
+
if integration_name is None:
|
|
695
|
+
integration_name = self.client.integration_name
|
|
696
|
+
|
|
697
|
+
url = f"{self.client.base_url}/v1/admin/integration/delete"
|
|
698
|
+
params = {"integration_name": integration_name}
|
|
699
|
+
headers = self.client._get_auth_headers()
|
|
700
|
+
response = self.client.session.delete(url, headers=headers, params=params)
|
|
701
|
+
data = self.client._handle_response(response)
|
|
702
|
+
return [Integration.model_validate(item) for item in data]
|
|
703
|
+
|
|
704
|
+
def update_integration_weaviate(
|
|
705
|
+
self,
|
|
706
|
+
weaviate_key: WeaviateKey,
|
|
707
|
+
weaviate_value: str,
|
|
708
|
+
integration_name: str = None,
|
|
709
|
+
) -> Integration:
|
|
710
|
+
"""
|
|
711
|
+
Update Integration weaviate settings.
|
|
712
|
+
|
|
713
|
+
Args:
|
|
714
|
+
weaviate_key: The Weaviate key
|
|
715
|
+
weaviate_value: The Weaviate value
|
|
716
|
+
integration_name: The name of the Integration
|
|
717
|
+
|
|
718
|
+
Returns:
|
|
719
|
+
Updated integration object
|
|
720
|
+
"""
|
|
721
|
+
if integration_name is None:
|
|
722
|
+
integration_name = self.client.integration_name
|
|
723
|
+
|
|
724
|
+
url = f"{self.client.base_url}/v1/admin/integration/edit/weaviate"
|
|
725
|
+
params = {
|
|
726
|
+
"integration_name": integration_name,
|
|
727
|
+
"weaviate_key": weaviate_key.value,
|
|
728
|
+
"weaviate_value": weaviate_value,
|
|
729
|
+
}
|
|
730
|
+
headers = self.client._get_auth_headers()
|
|
731
|
+
response = self.client.session.patch(url, headers=headers, params=params)
|
|
732
|
+
data = self.client._handle_response(response)
|
|
733
|
+
return Integration.model_validate(data)
|
|
734
|
+
|
|
735
|
+
def update_integration_published(self, published: bool, integration_name: str = None) -> Integration:
|
|
736
|
+
"""
|
|
737
|
+
Update Integration published setting.
|
|
738
|
+
|
|
739
|
+
Args:
|
|
740
|
+
published: The published value
|
|
741
|
+
integration_name: The name of the Integration
|
|
742
|
+
|
|
743
|
+
Returns:
|
|
744
|
+
Updated integration object
|
|
745
|
+
"""
|
|
746
|
+
if integration_name is None:
|
|
747
|
+
integration_name = self.client.integration_name
|
|
748
|
+
|
|
749
|
+
url = f"{self.client.base_url}/v1/admin/integration/edit/published"
|
|
750
|
+
params = {"integration_name": integration_name, "published": published}
|
|
751
|
+
headers = self.client._get_auth_headers()
|
|
752
|
+
response = self.client.session.patch(url, headers=headers, params=params)
|
|
753
|
+
data = self.client._handle_response(response)
|
|
754
|
+
return Integration.model_validate(data)
|
|
755
|
+
|
|
756
|
+
def update_integration_ai_api_key(
|
|
757
|
+
self, api_key: str, ai_provider: AIProviders, integration_name: str = None
|
|
758
|
+
) -> Integration:
|
|
759
|
+
"""
|
|
760
|
+
Update Integration AI api key.
|
|
761
|
+
|
|
762
|
+
Args:
|
|
763
|
+
api_key: The api key
|
|
764
|
+
ai_provider: The AI Provider for the model
|
|
765
|
+
integration_name: The name of the Integration
|
|
766
|
+
|
|
767
|
+
Returns:
|
|
768
|
+
Updated integration object
|
|
769
|
+
"""
|
|
770
|
+
if integration_name is None:
|
|
771
|
+
integration_name = self.client.integration_name
|
|
772
|
+
|
|
773
|
+
url = f"{self.client.base_url}/v1/admin/integration/edit/ai-api-key"
|
|
774
|
+
params = {
|
|
775
|
+
"integration_name": integration_name,
|
|
776
|
+
"api_key": api_key,
|
|
777
|
+
"ai_provider": ai_provider.value,
|
|
778
|
+
}
|
|
779
|
+
headers = self.client._get_auth_headers()
|
|
780
|
+
response = self.client.session.patch(url, headers=headers, params=params)
|
|
781
|
+
data = self.client._handle_response(response)
|
|
782
|
+
return Integration.model_validate(data)
|
|
783
|
+
|
|
784
|
+
def update_message_storage_mode(
|
|
785
|
+
self, message_storage_mode: MessageStorageMode, integration_name: str = None
|
|
786
|
+
) -> Integration:
|
|
787
|
+
"""
|
|
788
|
+
Update Integration message storage mode setting.
|
|
789
|
+
|
|
790
|
+
Args:
|
|
791
|
+
message_storage_mode: The Message Storage Mode
|
|
792
|
+
integration_name: The name of the Integration
|
|
793
|
+
|
|
794
|
+
Returns:
|
|
795
|
+
Updated integration object
|
|
796
|
+
"""
|
|
797
|
+
if integration_name is None:
|
|
798
|
+
integration_name = self.client.integration_name
|
|
799
|
+
|
|
800
|
+
url = f"{self.client.base_url}/v1/admin/integration/edit/message-storage-mode"
|
|
801
|
+
params = {
|
|
802
|
+
"integration_name": integration_name,
|
|
803
|
+
"message_storage_mode": message_storage_mode.value,
|
|
804
|
+
}
|
|
805
|
+
headers = self.client._get_auth_headers()
|
|
806
|
+
response = self.client.session.patch(url, headers=headers, params=params)
|
|
807
|
+
data = self.client._handle_response(response)
|
|
808
|
+
return Integration.model_validate(data)
|
|
809
|
+
|
|
810
|
+
def update_environment_variables(self, env_variables: Dict[str, str], integration_name: str = None) -> Integration:
|
|
811
|
+
"""
|
|
812
|
+
Update Integration environment variables.
|
|
813
|
+
|
|
814
|
+
Args:
|
|
815
|
+
env_variables: The Environment Variables
|
|
816
|
+
integration_name: The name of the Integration
|
|
817
|
+
|
|
818
|
+
Returns:
|
|
819
|
+
Updated integration object
|
|
820
|
+
"""
|
|
821
|
+
if integration_name is None:
|
|
822
|
+
integration_name = self.client.integration_name
|
|
823
|
+
|
|
824
|
+
url = f"{self.client.base_url}/v1/admin/integration/edit/environment-variables"
|
|
825
|
+
params = {"integration_name": integration_name}
|
|
826
|
+
headers = self.client._get_auth_headers()
|
|
827
|
+
response = self.client.session.patch(url, headers=headers, params=params, json=env_variables)
|
|
828
|
+
data = self.client._handle_response(response)
|
|
829
|
+
return Integration.model_validate(data)
|
|
830
|
+
|
|
831
|
+
def add_user_to_integration(
|
|
832
|
+
self,
|
|
833
|
+
user_id: str,
|
|
834
|
+
security_group_id: str,
|
|
835
|
+
integration_name: str = None,
|
|
836
|
+
) -> UsersList:
|
|
837
|
+
"""
|
|
838
|
+
Add user to the Integration by id.
|
|
839
|
+
|
|
840
|
+
Args:
|
|
841
|
+
integration_name: The integration name
|
|
842
|
+
user_id: The user id
|
|
843
|
+
security_group_id: The Security Group
|
|
844
|
+
|
|
845
|
+
Returns:
|
|
846
|
+
Users list
|
|
847
|
+
"""
|
|
848
|
+
if integration_name is None:
|
|
849
|
+
integration_name = self.client.integration_name
|
|
850
|
+
|
|
851
|
+
url = f"{self.client.base_url}/v1/admin/integration/name/{integration_name}/add-user/{user_id}"
|
|
852
|
+
params = {"security_group_id": security_group_id}
|
|
853
|
+
headers = self.client._get_auth_headers()
|
|
854
|
+
response = self.client.session.post(url, headers=headers, params=params)
|
|
855
|
+
result = self.client._handle_response(response)
|
|
856
|
+
return UsersList.model_validate(result)
|
|
857
|
+
|
|
858
|
+
def remove_user_from_integration(
|
|
859
|
+
self,
|
|
860
|
+
user_id: str,
|
|
861
|
+
integration_name: str = None,
|
|
862
|
+
) -> UsersList:
|
|
863
|
+
"""
|
|
864
|
+
Remove user from Integration.
|
|
865
|
+
|
|
866
|
+
Args:
|
|
867
|
+
integration_name: The integration name
|
|
868
|
+
user_id: The user id
|
|
869
|
+
|
|
870
|
+
Returns:
|
|
871
|
+
Users list
|
|
872
|
+
"""
|
|
873
|
+
if integration_name is None:
|
|
874
|
+
integration_name = self.client.integration_name
|
|
875
|
+
|
|
876
|
+
url = f"{self.client.base_url}/v1/admin/integration/name/{integration_name}/remove-user/{user_id}"
|
|
877
|
+
headers = self.client._get_auth_headers()
|
|
878
|
+
response = self.client.session.post(url, headers=headers)
|
|
879
|
+
result = self.client._handle_response(response)
|
|
880
|
+
return UsersList.model_validate(result)
|
|
881
|
+
|
|
882
|
+
def update_users_security_group(
|
|
883
|
+
self,
|
|
884
|
+
user_id: str,
|
|
885
|
+
security_group_id: str,
|
|
886
|
+
integration_name: str = None,
|
|
887
|
+
) -> UsersList:
|
|
888
|
+
"""
|
|
889
|
+
Update user's security group in an integration.
|
|
890
|
+
|
|
891
|
+
Args:
|
|
892
|
+
integration_name: The integration id
|
|
893
|
+
user_id: The user id
|
|
894
|
+
security_group_id: The Security Group
|
|
895
|
+
|
|
896
|
+
Returns:
|
|
897
|
+
Users list
|
|
898
|
+
"""
|
|
899
|
+
if integration_name is None:
|
|
900
|
+
integration_name = self.client.integration_name
|
|
901
|
+
|
|
902
|
+
url = (
|
|
903
|
+
f"{self.client.base_url}/v1/admin/integration/name/{integration_name}/update-users-security-group/{user_id}"
|
|
904
|
+
)
|
|
905
|
+
params = {"security_group_id": security_group_id}
|
|
906
|
+
headers = self.client._get_auth_headers()
|
|
907
|
+
response = self.client.session.post(url, headers=headers, params=params)
|
|
908
|
+
result = self.client._handle_response(response)
|
|
909
|
+
return UsersList.model_validate(result)
|
|
910
|
+
|
|
911
|
+
def get_users_from_integration(
|
|
912
|
+
self,
|
|
913
|
+
limit: int = 25,
|
|
914
|
+
integration_name: str = None,
|
|
915
|
+
last_evaluated_key: Optional[str] = None,
|
|
916
|
+
) -> UsersList:
|
|
917
|
+
"""
|
|
918
|
+
Get users in an Integration by id.
|
|
919
|
+
|
|
920
|
+
Args:
|
|
921
|
+
integration_name: The integration name
|
|
922
|
+
limit: Number of users to return
|
|
923
|
+
last_evaluated_key: Last evaluated key for pagination
|
|
924
|
+
|
|
925
|
+
Returns:
|
|
926
|
+
Users list
|
|
927
|
+
"""
|
|
928
|
+
if integration_name is None:
|
|
929
|
+
integration_name = self.client.integration_name
|
|
930
|
+
|
|
931
|
+
url = f"{self.client.base_url}/v1/admin/integration/name/{integration_name}/users"
|
|
932
|
+
params = {"limit": limit}
|
|
933
|
+
if last_evaluated_key:
|
|
934
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
935
|
+
|
|
936
|
+
headers = self.client._get_auth_headers()
|
|
937
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
938
|
+
result = self.client._handle_response(response)
|
|
939
|
+
return UsersList.model_validate(result)
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
class InstructionsAdmin:
|
|
943
|
+
"""Admin client for instructions management endpoints."""
|
|
944
|
+
|
|
945
|
+
def __init__(self, client: VectorBridgeClient):
|
|
946
|
+
self.client = client
|
|
947
|
+
|
|
948
|
+
def add_instruction(self, instruction_data: InstructionCreate, integration_name: str = None) -> Instruction:
|
|
949
|
+
"""
|
|
950
|
+
Add new Instruction to the integration.
|
|
951
|
+
|
|
952
|
+
Args:
|
|
953
|
+
instruction_data: Instruction details
|
|
954
|
+
integration_name: The name of the Integration
|
|
955
|
+
|
|
956
|
+
Returns:
|
|
957
|
+
Created instruction object
|
|
958
|
+
"""
|
|
959
|
+
if integration_name is None:
|
|
960
|
+
integration_name = self.client.integration_name
|
|
961
|
+
|
|
962
|
+
url = f"{self.client.base_url}/v1/admin/instruction/create"
|
|
963
|
+
params = {"integration_name": integration_name}
|
|
964
|
+
headers = self.client._get_auth_headers()
|
|
965
|
+
response = self.client.session.post(url, headers=headers, params=params, json=instruction_data.model_dump())
|
|
966
|
+
result = self.client._handle_response(response)
|
|
967
|
+
return Instruction.model_validate(result)
|
|
968
|
+
|
|
969
|
+
def get_instruction_by_name(self, instruction_name: str, integration_name: str = None) -> Optional[Instruction]:
|
|
970
|
+
"""
|
|
971
|
+
Get the Instruction by name.
|
|
972
|
+
|
|
973
|
+
Args:
|
|
974
|
+
instruction_name: The name of the Instruction
|
|
975
|
+
integration_name: The name of the Integration
|
|
976
|
+
|
|
977
|
+
Returns:
|
|
978
|
+
Instruction object
|
|
979
|
+
"""
|
|
980
|
+
if integration_name is None:
|
|
981
|
+
integration_name = self.client.integration_name
|
|
982
|
+
|
|
983
|
+
url = f"{self.client.base_url}/v1/admin/instruction"
|
|
984
|
+
params = {
|
|
985
|
+
"integration_name": integration_name,
|
|
986
|
+
"instruction_name": instruction_name,
|
|
987
|
+
}
|
|
988
|
+
headers = self.client._get_auth_headers()
|
|
989
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
990
|
+
result = self.client._handle_response(response)
|
|
991
|
+
return Instruction.model_validate(result) if result else None
|
|
992
|
+
|
|
993
|
+
def get_instruction_by_id(self, instruction_id: str, integration_name: str = None) -> Optional[Instruction]:
|
|
994
|
+
"""
|
|
995
|
+
Get the Instruction by ID.
|
|
996
|
+
|
|
997
|
+
Args:
|
|
998
|
+
instruction_id: The ID of the Instruction
|
|
999
|
+
integration_name: The name of the Integration
|
|
1000
|
+
|
|
1001
|
+
Returns:
|
|
1002
|
+
Instruction object
|
|
1003
|
+
"""
|
|
1004
|
+
if integration_name is None:
|
|
1005
|
+
integration_name = self.client.integration_name
|
|
1006
|
+
|
|
1007
|
+
url = f"{self.client.base_url}/v1/admin/instruction/{instruction_id}"
|
|
1008
|
+
params = {"integration_name": integration_name}
|
|
1009
|
+
headers = self.client._get_auth_headers()
|
|
1010
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1011
|
+
result = self.client._handle_response(response)
|
|
1012
|
+
return Instruction.model_validate(result) if result else None
|
|
1013
|
+
|
|
1014
|
+
def list_instructions(
|
|
1015
|
+
self,
|
|
1016
|
+
integration_name: str = None,
|
|
1017
|
+
limit: int = 10,
|
|
1018
|
+
last_evaluated_key: Optional[str] = None,
|
|
1019
|
+
sort_by: str = "created_at",
|
|
1020
|
+
) -> PaginatedInstructions:
|
|
1021
|
+
"""
|
|
1022
|
+
List Instructions for an Integration, sorted by created_at or updated_at.
|
|
1023
|
+
|
|
1024
|
+
Args:
|
|
1025
|
+
integration_name: The name of the Integration
|
|
1026
|
+
limit: The number of Instructions to retrieve
|
|
1027
|
+
last_evaluated_key: Pagination key for the next set of results
|
|
1028
|
+
sort_by: The sort field (created_at or updated_at)
|
|
1029
|
+
|
|
1030
|
+
Returns:
|
|
1031
|
+
PaginatedInstructions with instructions and pagination info
|
|
1032
|
+
"""
|
|
1033
|
+
if integration_name is None:
|
|
1034
|
+
integration_name = self.client.integration_name
|
|
1035
|
+
|
|
1036
|
+
url = f"{self.client.base_url}/v1/admin/instructions/list"
|
|
1037
|
+
params = {
|
|
1038
|
+
"integration_name": integration_name,
|
|
1039
|
+
"limit": limit,
|
|
1040
|
+
"sort_by": sort_by,
|
|
1041
|
+
}
|
|
1042
|
+
if last_evaluated_key:
|
|
1043
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
1044
|
+
|
|
1045
|
+
headers = self.client._get_auth_headers()
|
|
1046
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1047
|
+
result = self.client._handle_response(response)
|
|
1048
|
+
return PaginatedInstructions.model_validate(result)
|
|
1049
|
+
|
|
1050
|
+
def delete_instruction(self, instruction_id: str, integration_name: str = None) -> None:
|
|
1051
|
+
"""
|
|
1052
|
+
Delete Instruction from the integration.
|
|
1053
|
+
|
|
1054
|
+
Args:
|
|
1055
|
+
instruction_id: The instruction ID
|
|
1056
|
+
integration_name: The name of the Integration
|
|
1057
|
+
"""
|
|
1058
|
+
if integration_name is None:
|
|
1059
|
+
integration_name = self.client.integration_name
|
|
1060
|
+
|
|
1061
|
+
url = f"{self.client.base_url}/v1/admin/instruction/{instruction_id}/delete"
|
|
1062
|
+
params = {"integration_name": integration_name}
|
|
1063
|
+
headers = self.client._get_auth_headers()
|
|
1064
|
+
response = self.client.session.delete(url, headers=headers, params=params)
|
|
1065
|
+
self.client._handle_response(response)
|
|
1066
|
+
|
|
1067
|
+
# Many more instruction methods go here... For brevity, I'll include just a few key ones
|
|
1068
|
+
# The full implementation would include all agent, prompt, and other modification methods
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
class FunctionsAdmin:
|
|
1072
|
+
"""Admin client for functions management endpoints."""
|
|
1073
|
+
|
|
1074
|
+
def __init__(self, client: VectorBridgeClient):
|
|
1075
|
+
self.client = client
|
|
1076
|
+
|
|
1077
|
+
def add_function(self, function_data: FunctionCreate, integration_name: str = None) -> Function:
|
|
1078
|
+
"""
|
|
1079
|
+
Add new Function to the integration.
|
|
1080
|
+
|
|
1081
|
+
Args:
|
|
1082
|
+
function_data: Function details
|
|
1083
|
+
integration_name: The name of the Integration
|
|
1084
|
+
|
|
1085
|
+
Returns:
|
|
1086
|
+
Created function object
|
|
1087
|
+
"""
|
|
1088
|
+
if integration_name is None:
|
|
1089
|
+
integration_name = self.client.integration_name
|
|
1090
|
+
|
|
1091
|
+
url = f"{self.client.base_url}/v1/admin/function/create"
|
|
1092
|
+
params = {"integration_name": integration_name}
|
|
1093
|
+
headers = self.client._get_auth_headers()
|
|
1094
|
+
response = self.client.session.post(url, headers=headers, params=params, json=function_data.model_dump())
|
|
1095
|
+
result = self.client._handle_response(response)
|
|
1096
|
+
return Function.model_validate(result)
|
|
1097
|
+
|
|
1098
|
+
def get_function_by_name(self, function_name: str, integration_name: str = None) -> Function:
|
|
1099
|
+
"""
|
|
1100
|
+
Get the Function by name.
|
|
1101
|
+
|
|
1102
|
+
Args:
|
|
1103
|
+
function_name: The name of the Function
|
|
1104
|
+
integration_name: The name of the Integration
|
|
1105
|
+
|
|
1106
|
+
Returns:
|
|
1107
|
+
Function object
|
|
1108
|
+
"""
|
|
1109
|
+
if integration_name is None:
|
|
1110
|
+
integration_name = self.client.integration_name
|
|
1111
|
+
|
|
1112
|
+
url = f"{self.client.base_url}/v1/admin/function"
|
|
1113
|
+
params = {"integration_name": integration_name, "function_name": function_name}
|
|
1114
|
+
headers = self.client._get_auth_headers()
|
|
1115
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1116
|
+
result = self.client._handle_response(response)
|
|
1117
|
+
return Function.model_validate(result)
|
|
1118
|
+
|
|
1119
|
+
def get_function_by_id(self, function_id: str, integration_name: str = None) -> Function:
|
|
1120
|
+
"""
|
|
1121
|
+
Get the Function by ID.
|
|
1122
|
+
|
|
1123
|
+
Args:
|
|
1124
|
+
function_id: The ID of the Function
|
|
1125
|
+
integration_name: The name of the Integration
|
|
1126
|
+
|
|
1127
|
+
Returns:
|
|
1128
|
+
Function object
|
|
1129
|
+
"""
|
|
1130
|
+
if integration_name is None:
|
|
1131
|
+
integration_name = self.client.integration_name
|
|
1132
|
+
|
|
1133
|
+
url = f"{self.client.base_url}/v1/admin/function/{function_id}"
|
|
1134
|
+
params = {"integration_name": integration_name}
|
|
1135
|
+
headers = self.client._get_auth_headers()
|
|
1136
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1137
|
+
result = self.client._handle_response(response)
|
|
1138
|
+
return Function.model_validate(result)
|
|
1139
|
+
|
|
1140
|
+
def update_function(
|
|
1141
|
+
self,
|
|
1142
|
+
function_id: str,
|
|
1143
|
+
function_data: FunctionUpdate,
|
|
1144
|
+
integration_name: str = None,
|
|
1145
|
+
) -> Function:
|
|
1146
|
+
"""
|
|
1147
|
+
Update an existing Function.
|
|
1148
|
+
|
|
1149
|
+
Args:
|
|
1150
|
+
function_id: The ID of the Function to update
|
|
1151
|
+
function_data: Updated function details
|
|
1152
|
+
integration_name: The name of the Integration
|
|
1153
|
+
|
|
1154
|
+
Returns:
|
|
1155
|
+
Updated function object
|
|
1156
|
+
"""
|
|
1157
|
+
if integration_name is None:
|
|
1158
|
+
integration_name = self.client.integration_name
|
|
1159
|
+
|
|
1160
|
+
url = f"{self.client.base_url}/v1/admin/function/{function_id}/update"
|
|
1161
|
+
params = {"integration_name": integration_name}
|
|
1162
|
+
headers = self.client._get_auth_headers()
|
|
1163
|
+
response = self.client.session.put(url, headers=headers, params=params, json=function_data.model_dump())
|
|
1164
|
+
result = self.client._handle_response(response)
|
|
1165
|
+
return Function.model_validate(result)
|
|
1166
|
+
|
|
1167
|
+
def list_functions(
|
|
1168
|
+
self,
|
|
1169
|
+
integration_name: str = None,
|
|
1170
|
+
limit: int = 10,
|
|
1171
|
+
last_evaluated_key: Optional[str] = None,
|
|
1172
|
+
sort_by: str = "created_at",
|
|
1173
|
+
) -> PaginatedFunctions:
|
|
1174
|
+
"""
|
|
1175
|
+
List Functions for an Integration.
|
|
1176
|
+
|
|
1177
|
+
Args:
|
|
1178
|
+
integration_name: The name of the Integration
|
|
1179
|
+
limit: Number of functions to retrieve
|
|
1180
|
+
last_evaluated_key: Pagination key for the next set of results
|
|
1181
|
+
sort_by: Field to sort by (created_at or updated_at)
|
|
1182
|
+
|
|
1183
|
+
Returns:
|
|
1184
|
+
Dict with functions and pagination info
|
|
1185
|
+
"""
|
|
1186
|
+
if integration_name is None:
|
|
1187
|
+
integration_name = self.client.integration_name
|
|
1188
|
+
|
|
1189
|
+
url = f"{self.client.base_url}/v1/admin/functions/list"
|
|
1190
|
+
params = {
|
|
1191
|
+
"integration_name": integration_name,
|
|
1192
|
+
"limit": limit,
|
|
1193
|
+
"sort_by": sort_by,
|
|
1194
|
+
}
|
|
1195
|
+
if last_evaluated_key:
|
|
1196
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
1197
|
+
|
|
1198
|
+
headers = self.client._get_auth_headers()
|
|
1199
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1200
|
+
result = self.client._handle_response(response)
|
|
1201
|
+
return PaginatedFunctions.model_validate(result)
|
|
1202
|
+
|
|
1203
|
+
def list_default_functions(
|
|
1204
|
+
self,
|
|
1205
|
+
) -> PaginatedFunctions:
|
|
1206
|
+
"""
|
|
1207
|
+
List Functions for an Integration.
|
|
1208
|
+
|
|
1209
|
+
Args:
|
|
1210
|
+
integration_name: The name of the Integration
|
|
1211
|
+
limit: Number of functions to retrieve
|
|
1212
|
+
last_evaluated_key: Pagination key for the next set of results
|
|
1213
|
+
sort_by: Field to sort by (created_at or updated_at)
|
|
1214
|
+
|
|
1215
|
+
Returns:
|
|
1216
|
+
Dict with functions and pagination info
|
|
1217
|
+
"""
|
|
1218
|
+
url = f"{self.client.base_url}/v1/admin/functions/list-default"
|
|
1219
|
+
|
|
1220
|
+
headers = self.client._get_auth_headers()
|
|
1221
|
+
response = self.client.session.get(url, headers=headers)
|
|
1222
|
+
result = self.client._handle_response(response)
|
|
1223
|
+
return PaginatedFunctions.model_validate(result)
|
|
1224
|
+
|
|
1225
|
+
def delete_function(self, function_id: str, integration_name: str = None) -> None:
|
|
1226
|
+
"""
|
|
1227
|
+
Delete a function.
|
|
1228
|
+
|
|
1229
|
+
Args:
|
|
1230
|
+
function_id: The ID of the function to delete
|
|
1231
|
+
integration_name: The name of the Integration
|
|
1232
|
+
"""
|
|
1233
|
+
if integration_name is None:
|
|
1234
|
+
integration_name = self.client.integration_name
|
|
1235
|
+
|
|
1236
|
+
url = f"{self.client.base_url}/v1/admin/function/{function_id}/delete"
|
|
1237
|
+
params = {"integration_name": integration_name}
|
|
1238
|
+
headers = self.client._get_auth_headers()
|
|
1239
|
+
response = self.client.session.delete(url, headers=headers, params=params)
|
|
1240
|
+
self.client._handle_response(response)
|
|
1241
|
+
|
|
1242
|
+
def run_function(
|
|
1243
|
+
self,
|
|
1244
|
+
function_name: str,
|
|
1245
|
+
function_args: Dict[str, Any],
|
|
1246
|
+
integration_name: str = None,
|
|
1247
|
+
instruction_name: str = "default",
|
|
1248
|
+
agent_name: str = "default",
|
|
1249
|
+
) -> Any:
|
|
1250
|
+
"""
|
|
1251
|
+
Run a function.
|
|
1252
|
+
|
|
1253
|
+
Args:
|
|
1254
|
+
function_name: The name of the function to run
|
|
1255
|
+
function_args: Arguments to pass to the function
|
|
1256
|
+
integration_name: The name of the Integration
|
|
1257
|
+
instruction_name: The name of the instruction
|
|
1258
|
+
agent_name: The name of the agent
|
|
1259
|
+
|
|
1260
|
+
Returns:
|
|
1261
|
+
Function execution result
|
|
1262
|
+
"""
|
|
1263
|
+
if integration_name is None:
|
|
1264
|
+
integration_name = self.client.integration_name
|
|
1265
|
+
|
|
1266
|
+
url = f"{self.client.base_url}/v1/admin/function/{function_name}/run"
|
|
1267
|
+
params = {
|
|
1268
|
+
"integration_name": integration_name,
|
|
1269
|
+
"instruction_name": instruction_name,
|
|
1270
|
+
"agent_name": agent_name,
|
|
1271
|
+
}
|
|
1272
|
+
headers = self.client._get_auth_headers()
|
|
1273
|
+
response = self.client.session.post(url, headers=headers, params=params, json=function_args)
|
|
1274
|
+
return self.client._handle_response(response)
|
|
1275
|
+
|
|
1276
|
+
|
|
1277
|
+
class APIKeysAdmin:
|
|
1278
|
+
"""Admin client for API keys management endpoints."""
|
|
1279
|
+
|
|
1280
|
+
def __init__(self, client: VectorBridgeClient):
|
|
1281
|
+
self.client = client
|
|
1282
|
+
|
|
1283
|
+
def create_api_key(self, api_key_data: APIKeyCreate) -> APIKey:
|
|
1284
|
+
"""
|
|
1285
|
+
Create a new API key for integrations.
|
|
1286
|
+
|
|
1287
|
+
Args:
|
|
1288
|
+
api_key_data: Details for the API key to create
|
|
1289
|
+
|
|
1290
|
+
Returns:
|
|
1291
|
+
Created API key
|
|
1292
|
+
"""
|
|
1293
|
+
url = f"{self.client.base_url}/v1/admin/api_key/create"
|
|
1294
|
+
headers = self.client._get_auth_headers()
|
|
1295
|
+
response = self.client.session.post(url, headers=headers, json=api_key_data.model_dump())
|
|
1296
|
+
result = self.client._handle_response(response)
|
|
1297
|
+
return APIKey.model_validate(result)
|
|
1298
|
+
|
|
1299
|
+
def get_api_key(self, api_key: str) -> APIKey:
|
|
1300
|
+
"""
|
|
1301
|
+
Retrieve details about a specific API key.
|
|
1302
|
+
|
|
1303
|
+
Args:
|
|
1304
|
+
api_key: The API key
|
|
1305
|
+
|
|
1306
|
+
Returns:
|
|
1307
|
+
API key details
|
|
1308
|
+
"""
|
|
1309
|
+
url = f"{self.client.base_url}/v1/admin/api_key/{api_key}"
|
|
1310
|
+
headers = self.client._get_auth_headers()
|
|
1311
|
+
response = self.client.session.get(url, headers=headers)
|
|
1312
|
+
result = self.client._handle_response(response)
|
|
1313
|
+
return APIKey.model_validate(result)
|
|
1314
|
+
|
|
1315
|
+
def delete_api_key(self, api_key: str) -> None:
|
|
1316
|
+
"""
|
|
1317
|
+
Delete an API key.
|
|
1318
|
+
|
|
1319
|
+
Args:
|
|
1320
|
+
api_key: The API key to delete
|
|
1321
|
+
"""
|
|
1322
|
+
url = f"{self.client.base_url}/v1/admin/api_key/{api_key}"
|
|
1323
|
+
headers = self.client._get_auth_headers()
|
|
1324
|
+
response = self.client.session.delete(url, headers=headers)
|
|
1325
|
+
if response.status_code != 204:
|
|
1326
|
+
self.client._handle_response(response)
|
|
1327
|
+
|
|
1328
|
+
def list_api_keys(self, integration_name: Optional[str] = None) -> List[APIKey]:
|
|
1329
|
+
"""
|
|
1330
|
+
List all API keys.
|
|
1331
|
+
|
|
1332
|
+
Args:
|
|
1333
|
+
integration_name: Specifies the name of the integration module being queried
|
|
1334
|
+
|
|
1335
|
+
Returns:
|
|
1336
|
+
List of API keys
|
|
1337
|
+
"""
|
|
1338
|
+
url = f"{self.client.base_url}/v1/admin/api_keys"
|
|
1339
|
+
params = {}
|
|
1340
|
+
if integration_name:
|
|
1341
|
+
params["integration_name"] = integration_name
|
|
1342
|
+
|
|
1343
|
+
headers = self.client._get_auth_headers()
|
|
1344
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1345
|
+
results = self.client._handle_response(response)
|
|
1346
|
+
return [APIKey.model_validate(result) for result in results]
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
class ChatAdmin:
|
|
1350
|
+
"""Admin client for chat management endpoints."""
|
|
1351
|
+
|
|
1352
|
+
def __init__(self, client: VectorBridgeClient):
|
|
1353
|
+
self.client = client
|
|
1354
|
+
|
|
1355
|
+
def fetch_chats_for_my_organization(
|
|
1356
|
+
self, integration_name: str = None, limit: int = 50, offset: int = 0
|
|
1357
|
+
) -> ChatsList:
|
|
1358
|
+
"""
|
|
1359
|
+
Retrieve a list of chat sessions associated with the organization.
|
|
1360
|
+
|
|
1361
|
+
Args:
|
|
1362
|
+
integration_name: The name of the integration
|
|
1363
|
+
limit: Number of chat records to return
|
|
1364
|
+
offset: Starting point for fetching records
|
|
1365
|
+
|
|
1366
|
+
Returns:
|
|
1367
|
+
ChatsList with chats and pagination info
|
|
1368
|
+
"""
|
|
1369
|
+
if integration_name is None:
|
|
1370
|
+
integration_name = self.client.integration_name
|
|
1371
|
+
|
|
1372
|
+
url = f"{self.client.base_url}/v1/admin/chats"
|
|
1373
|
+
params = {
|
|
1374
|
+
"integration_name": integration_name,
|
|
1375
|
+
"limit": limit,
|
|
1376
|
+
"offset": offset,
|
|
1377
|
+
}
|
|
1378
|
+
headers = self.client._get_auth_headers()
|
|
1379
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1380
|
+
result = self.client._handle_response(response)
|
|
1381
|
+
return ChatsList.model_validate(result)
|
|
1382
|
+
|
|
1383
|
+
def fetch_my_chats(self, integration_name: str = None, limit: int = 50, offset: int = 0) -> ChatsList:
|
|
1384
|
+
"""
|
|
1385
|
+
Retrieve a list of chat sessions for the current user.
|
|
1386
|
+
|
|
1387
|
+
Args:
|
|
1388
|
+
integration_name: The name of the integration
|
|
1389
|
+
limit: Number of chat records to return
|
|
1390
|
+
offset: Starting point for fetching records
|
|
1391
|
+
|
|
1392
|
+
Returns:
|
|
1393
|
+
ChatsList with chats and pagination info
|
|
1394
|
+
"""
|
|
1395
|
+
if integration_name is None:
|
|
1396
|
+
integration_name = self.client.integration_name
|
|
1397
|
+
|
|
1398
|
+
url = f"{self.client.base_url}/v1/admin/chats/me"
|
|
1399
|
+
params = {
|
|
1400
|
+
"integration_name": integration_name,
|
|
1401
|
+
"limit": limit,
|
|
1402
|
+
"offset": offset,
|
|
1403
|
+
}
|
|
1404
|
+
headers = self.client._get_auth_headers()
|
|
1405
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1406
|
+
result = self.client._handle_response(response)
|
|
1407
|
+
return ChatsList.model_validate(result)
|
|
1408
|
+
|
|
1409
|
+
def delete_chat(self, user_id: str, integration_name: str = None) -> None:
|
|
1410
|
+
"""
|
|
1411
|
+
Delete a chat session between the organization and a specific user.
|
|
1412
|
+
|
|
1413
|
+
Args:
|
|
1414
|
+
user_id: The unique identifier of the user
|
|
1415
|
+
integration_name: The name of the integration
|
|
1416
|
+
"""
|
|
1417
|
+
if integration_name is None:
|
|
1418
|
+
integration_name = self.client.integration_name
|
|
1419
|
+
|
|
1420
|
+
url = f"{self.client.base_url}/v1/admin/chat/delete/{user_id}"
|
|
1421
|
+
params = {"integration_name": integration_name}
|
|
1422
|
+
headers = self.client._get_auth_headers()
|
|
1423
|
+
response = self.client.session.delete(url, headers=headers, params=params)
|
|
1424
|
+
if response.status_code != 204:
|
|
1425
|
+
self.client._handle_response(response)
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
class MessageAdmin:
|
|
1429
|
+
"""Admin client for message management endpoints."""
|
|
1430
|
+
|
|
1431
|
+
def __init__(self, client: VectorBridgeClient):
|
|
1432
|
+
self.client = client
|
|
1433
|
+
|
|
1434
|
+
def process_internal_message(
|
|
1435
|
+
self,
|
|
1436
|
+
content: str,
|
|
1437
|
+
suffix: str,
|
|
1438
|
+
integration_name: str = None,
|
|
1439
|
+
instruction_name: str = "default",
|
|
1440
|
+
function_to_call: Optional[str] = None,
|
|
1441
|
+
data: Optional[Dict[str, Any]] = None,
|
|
1442
|
+
crypto_key: Optional[str] = None,
|
|
1443
|
+
) -> StreamingResponse:
|
|
1444
|
+
"""
|
|
1445
|
+
Process an internal message and get AI response.
|
|
1446
|
+
|
|
1447
|
+
Args:
|
|
1448
|
+
content: Message content
|
|
1449
|
+
suffix: Suffix for the user_id
|
|
1450
|
+
integration_name: The name of the integration
|
|
1451
|
+
instruction_name: The name of the instruction
|
|
1452
|
+
function_to_call: Function to call (optional)
|
|
1453
|
+
data: Additional data (optional)
|
|
1454
|
+
crypto_key: Crypto key for encrypted storage (optional)
|
|
1455
|
+
|
|
1456
|
+
Returns:
|
|
1457
|
+
Stream of message objects including AI response
|
|
1458
|
+
"""
|
|
1459
|
+
if integration_name is None:
|
|
1460
|
+
integration_name = self.client.integration_name
|
|
1461
|
+
|
|
1462
|
+
url = f"{self.client.base_url}/v1/stream/admin/ai/process-internal-message/response-text"
|
|
1463
|
+
params = {
|
|
1464
|
+
"suffix": suffix,
|
|
1465
|
+
"integration_name": integration_name,
|
|
1466
|
+
"instruction_name": instruction_name,
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
if function_to_call:
|
|
1470
|
+
params["function_to_call"] = function_to_call
|
|
1471
|
+
|
|
1472
|
+
headers = self.client._get_auth_headers()
|
|
1473
|
+
if crypto_key:
|
|
1474
|
+
headers["Crypto-Key"] = crypto_key
|
|
1475
|
+
|
|
1476
|
+
message_data = {"content": content}
|
|
1477
|
+
if data:
|
|
1478
|
+
message_data["data"] = data
|
|
1479
|
+
|
|
1480
|
+
response = self.client.session.post(
|
|
1481
|
+
url,
|
|
1482
|
+
headers=headers,
|
|
1483
|
+
params=params,
|
|
1484
|
+
json=message_data,
|
|
1485
|
+
stream=True, # Enables streaming response
|
|
1486
|
+
)
|
|
1487
|
+
|
|
1488
|
+
return StreamingResponse(response)
|
|
1489
|
+
|
|
1490
|
+
def fetch_internal_messages_from_vector_db(
|
|
1491
|
+
self,
|
|
1492
|
+
suffix: str,
|
|
1493
|
+
integration_name: str = None,
|
|
1494
|
+
limit: int = 50,
|
|
1495
|
+
offset: int = 0,
|
|
1496
|
+
sort_order: str = "asc",
|
|
1497
|
+
near_text: Optional[str] = None,
|
|
1498
|
+
) -> MessagesListVectorDB:
|
|
1499
|
+
"""
|
|
1500
|
+
Retrieve internal messages from vector database.
|
|
1501
|
+
|
|
1502
|
+
Args:
|
|
1503
|
+
suffix: Suffix for the user_id
|
|
1504
|
+
integration_name: The name of the integration
|
|
1505
|
+
limit: Number of messages to return
|
|
1506
|
+
offset: Starting point for fetching records
|
|
1507
|
+
sort_order: Order to sort results (asc/desc)
|
|
1508
|
+
near_text: Text to search for semantically similar messages
|
|
1509
|
+
|
|
1510
|
+
Returns:
|
|
1511
|
+
MessagesListVectorDB with messages and pagination info
|
|
1512
|
+
"""
|
|
1513
|
+
if integration_name is None:
|
|
1514
|
+
integration_name = self.client.integration_name
|
|
1515
|
+
|
|
1516
|
+
url = f"{self.client.base_url}/v1/admin/ai/internal-messages/weaviate"
|
|
1517
|
+
params = {
|
|
1518
|
+
"suffix": suffix,
|
|
1519
|
+
"integration_name": integration_name,
|
|
1520
|
+
"limit": limit,
|
|
1521
|
+
"offset": offset,
|
|
1522
|
+
"sort_order": sort_order,
|
|
1523
|
+
}
|
|
1524
|
+
if near_text:
|
|
1525
|
+
params["near_text"] = near_text
|
|
1526
|
+
|
|
1527
|
+
headers = self.client._get_auth_headers()
|
|
1528
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1529
|
+
result = self.client._handle_response(response)
|
|
1530
|
+
return MessagesListVectorDB.model_validate(result)
|
|
1531
|
+
|
|
1532
|
+
def fetch_internal_messages_from_dynamo_db(
|
|
1533
|
+
self,
|
|
1534
|
+
suffix: str,
|
|
1535
|
+
integration_name: str = None,
|
|
1536
|
+
limit: int = 50,
|
|
1537
|
+
last_evaluated_key: Optional[str] = None,
|
|
1538
|
+
sort_order: str = "asc",
|
|
1539
|
+
crypto_key: Optional[str] = None,
|
|
1540
|
+
) -> MessagesListDynamoDB:
|
|
1541
|
+
"""
|
|
1542
|
+
Retrieve internal messages from DynamoDB.
|
|
1543
|
+
|
|
1544
|
+
Args:
|
|
1545
|
+
suffix: Suffix for the user_id
|
|
1546
|
+
integration_name: The name of the integration
|
|
1547
|
+
limit: Number of messages to return
|
|
1548
|
+
last_evaluated_key: Key for pagination
|
|
1549
|
+
sort_order: Order to sort results (asc/desc)
|
|
1550
|
+
crypto_key: Crypto key for decryption
|
|
1551
|
+
|
|
1552
|
+
Returns:
|
|
1553
|
+
MessagesListDynamoDB with messages and pagination info
|
|
1554
|
+
"""
|
|
1555
|
+
if integration_name is None:
|
|
1556
|
+
integration_name = self.client.integration_name
|
|
1557
|
+
|
|
1558
|
+
url = f"{self.client.base_url}/v1/admin/ai/internal-messages/dynamo-db"
|
|
1559
|
+
params = {
|
|
1560
|
+
"suffix": suffix,
|
|
1561
|
+
"integration_name": integration_name,
|
|
1562
|
+
"limit": limit,
|
|
1563
|
+
"sort_order": sort_order,
|
|
1564
|
+
}
|
|
1565
|
+
if last_evaluated_key:
|
|
1566
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
1567
|
+
|
|
1568
|
+
headers = self.client._get_auth_headers()
|
|
1569
|
+
if crypto_key:
|
|
1570
|
+
headers["Crypto-Key"] = crypto_key
|
|
1571
|
+
|
|
1572
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1573
|
+
result = self.client._handle_response(response)
|
|
1574
|
+
return MessagesListDynamoDB.model_validate(result)
|
|
1575
|
+
|
|
1576
|
+
|
|
1577
|
+
class AIKnowledgeAdmin:
|
|
1578
|
+
"""Admin client for AI Knowledge management endpoints."""
|
|
1579
|
+
|
|
1580
|
+
def __init__(self, client: VectorBridgeClient):
|
|
1581
|
+
self.client = client
|
|
1582
|
+
self.file_storage = FileStorageAIKnowledgeAdmin(client)
|
|
1583
|
+
self.database = DatabaseAIKnowledgeAdmin(client)
|
|
1584
|
+
|
|
1585
|
+
|
|
1586
|
+
class FileStorageAIKnowledgeAdmin:
|
|
1587
|
+
"""Admin client for AI Knowledge file storage management."""
|
|
1588
|
+
|
|
1589
|
+
def __init__(self, client: VectorBridgeClient):
|
|
1590
|
+
self.client = client
|
|
1591
|
+
|
|
1592
|
+
def create_folder(
|
|
1593
|
+
self,
|
|
1594
|
+
folder_name: str,
|
|
1595
|
+
folder_description: str,
|
|
1596
|
+
integration_name: str = None,
|
|
1597
|
+
parent_id: Optional[str] = None,
|
|
1598
|
+
tags: Optional[List[str]] = None,
|
|
1599
|
+
private: bool = False,
|
|
1600
|
+
) -> AIKnowledgeFileSystemItem:
|
|
1601
|
+
"""
|
|
1602
|
+
Create a new folder.
|
|
1603
|
+
|
|
1604
|
+
Args:
|
|
1605
|
+
folder_name: The name for the new folder
|
|
1606
|
+
folder_description: Description of the folder
|
|
1607
|
+
integration_name: The name of the Integration
|
|
1608
|
+
parent_id: Parent folder ID (None for root level)
|
|
1609
|
+
tags: List of tags for the folder
|
|
1610
|
+
private: Whether the folder is private
|
|
1611
|
+
|
|
1612
|
+
Returns:
|
|
1613
|
+
Created folder object
|
|
1614
|
+
"""
|
|
1615
|
+
if integration_name is None:
|
|
1616
|
+
integration_name = self.client.integration_name
|
|
1617
|
+
|
|
1618
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/folder/create"
|
|
1619
|
+
params = {
|
|
1620
|
+
"folder_name": folder_name,
|
|
1621
|
+
"folder_description": folder_description,
|
|
1622
|
+
"integration_name": integration_name,
|
|
1623
|
+
"private": private,
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
if parent_id:
|
|
1627
|
+
params["parent_id"] = parent_id
|
|
1628
|
+
|
|
1629
|
+
if tags:
|
|
1630
|
+
params["tags"] = tags
|
|
1631
|
+
|
|
1632
|
+
headers = self.client._get_auth_headers()
|
|
1633
|
+
response = self.client.session.post(url, headers=headers, params=params)
|
|
1634
|
+
result = self.client._handle_response(response)
|
|
1635
|
+
return AIKnowledgeFileSystemItem.model_validate(result)
|
|
1636
|
+
|
|
1637
|
+
def __get_upload_link_for_document(self, integration_name: str = None) -> Dict[str, Any]:
|
|
1638
|
+
"""
|
|
1639
|
+
Get a presigned URL for uploading a document.
|
|
1640
|
+
|
|
1641
|
+
Args:
|
|
1642
|
+
integration_name: The name of the Integration
|
|
1643
|
+
|
|
1644
|
+
Returns:
|
|
1645
|
+
Dict with upload URL and parameters
|
|
1646
|
+
"""
|
|
1647
|
+
if integration_name is None:
|
|
1648
|
+
integration_name = self.client.integration_name
|
|
1649
|
+
|
|
1650
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/file/upload-link"
|
|
1651
|
+
params = {"integration_name": integration_name}
|
|
1652
|
+
|
|
1653
|
+
headers = self.client._get_auth_headers()
|
|
1654
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1655
|
+
return self.client._handle_response(response)
|
|
1656
|
+
|
|
1657
|
+
def __process_uploaded_file(
|
|
1658
|
+
self,
|
|
1659
|
+
object_name: str,
|
|
1660
|
+
file_name: str,
|
|
1661
|
+
parent_id: Optional[str] = None,
|
|
1662
|
+
integration_name: str = None,
|
|
1663
|
+
cloud_stored: bool = True,
|
|
1664
|
+
vectorized: bool = True,
|
|
1665
|
+
content_uniqueness_check: bool = True,
|
|
1666
|
+
tags: Optional[List[str]] = None,
|
|
1667
|
+
source_documents_ids: Optional[List[str]] = None,
|
|
1668
|
+
private: bool = False,
|
|
1669
|
+
) -> AIKnowledgeFileSystemItem:
|
|
1670
|
+
"""
|
|
1671
|
+
Process an uploaded file.
|
|
1672
|
+
|
|
1673
|
+
Args:
|
|
1674
|
+
object_name: The key from the get_upload_link_for_document response
|
|
1675
|
+
file_name: The name of the file with extension
|
|
1676
|
+
parent_id: Parent folder ID
|
|
1677
|
+
integration_name: The name of the Integration
|
|
1678
|
+
cloud_stored: Store in VectorBridge storage
|
|
1679
|
+
vectorized: Vectorize the file
|
|
1680
|
+
content_uniqueness_check: Check for content uniqueness
|
|
1681
|
+
tags: List of tags for the file
|
|
1682
|
+
source_documents_ids: List of source document IDs
|
|
1683
|
+
private: Whether the file is private
|
|
1684
|
+
|
|
1685
|
+
Returns:
|
|
1686
|
+
Processed file object
|
|
1687
|
+
"""
|
|
1688
|
+
if integration_name is None:
|
|
1689
|
+
integration_name = self.client.integration_name
|
|
1690
|
+
|
|
1691
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/file/process-uploaded"
|
|
1692
|
+
params = {
|
|
1693
|
+
"object_name": object_name,
|
|
1694
|
+
"file_name": file_name,
|
|
1695
|
+
"integration_name": integration_name,
|
|
1696
|
+
"cloud_stored": cloud_stored,
|
|
1697
|
+
"vectorized": vectorized,
|
|
1698
|
+
"content_uniqueness_check": content_uniqueness_check,
|
|
1699
|
+
"private": private,
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
if parent_id:
|
|
1703
|
+
params["parent_id"] = parent_id
|
|
1704
|
+
|
|
1705
|
+
if tags:
|
|
1706
|
+
params["tags"] = tags
|
|
1707
|
+
|
|
1708
|
+
if source_documents_ids:
|
|
1709
|
+
params["source_documents_ids"] = source_documents_ids
|
|
1710
|
+
|
|
1711
|
+
headers = self.client._get_auth_headers()
|
|
1712
|
+
response = self.client.session.post(url, headers=headers, params=params)
|
|
1713
|
+
return self.client._handle_response(response)
|
|
1714
|
+
|
|
1715
|
+
def upload_file(
|
|
1716
|
+
self,
|
|
1717
|
+
file_path: str,
|
|
1718
|
+
file_name: Optional[str] = None,
|
|
1719
|
+
parent_id: Optional[str] = None,
|
|
1720
|
+
integration_name: str = None,
|
|
1721
|
+
cloud_stored: bool = True,
|
|
1722
|
+
vectorized: bool = True,
|
|
1723
|
+
content_uniqueness_check: bool = True,
|
|
1724
|
+
tags: Optional[List[str]] = None,
|
|
1725
|
+
source_documents_ids: Optional[List[str]] = None,
|
|
1726
|
+
private: bool = False,
|
|
1727
|
+
) -> AIKnowledgeFileSystemItem:
|
|
1728
|
+
"""
|
|
1729
|
+
Upload and process a file in one step.
|
|
1730
|
+
|
|
1731
|
+
Args:
|
|
1732
|
+
file_path: Path to the file to upload
|
|
1733
|
+
file_name: Name for the file (defaults to basename of file_path)
|
|
1734
|
+
parent_id: Parent folder ID
|
|
1735
|
+
integration_name: The name of the Integration
|
|
1736
|
+
cloud_stored: Store in VectorBridge storage
|
|
1737
|
+
vectorized: Vectorize the file
|
|
1738
|
+
content_uniqueness_check: Check for content uniqueness
|
|
1739
|
+
tags: List of tags for the file
|
|
1740
|
+
source_documents_ids: List of source document IDs
|
|
1741
|
+
private: Whether the file is private
|
|
1742
|
+
|
|
1743
|
+
Returns:
|
|
1744
|
+
Processed file object
|
|
1745
|
+
"""
|
|
1746
|
+
if integration_name is None:
|
|
1747
|
+
integration_name = self.client.integration_name
|
|
1748
|
+
|
|
1749
|
+
import os
|
|
1750
|
+
|
|
1751
|
+
import requests
|
|
1752
|
+
|
|
1753
|
+
if file_name is None:
|
|
1754
|
+
file_name = os.path.basename(file_path)
|
|
1755
|
+
|
|
1756
|
+
# 1. Get upload link
|
|
1757
|
+
upload_link_response = self.__get_upload_link_for_document(integration_name)
|
|
1758
|
+
upload_url = upload_link_response["url"]
|
|
1759
|
+
object_name = upload_link_response["body"]["key"]
|
|
1760
|
+
|
|
1761
|
+
# 2. Upload file to the presigned URL
|
|
1762
|
+
with open(file_path, "rb") as file:
|
|
1763
|
+
files = {"file": (file_name, file)}
|
|
1764
|
+
upload_response = requests.post(upload_url, data=upload_link_response["body"], files=files)
|
|
1765
|
+
|
|
1766
|
+
if upload_response.status_code >= 300:
|
|
1767
|
+
raise Exception(f"Error uploading file: {upload_response.text}")
|
|
1768
|
+
|
|
1769
|
+
# 3. Process the uploaded file
|
|
1770
|
+
result = self.__process_uploaded_file(
|
|
1771
|
+
object_name=object_name,
|
|
1772
|
+
file_name=file_name,
|
|
1773
|
+
parent_id=parent_id,
|
|
1774
|
+
integration_name=integration_name,
|
|
1775
|
+
cloud_stored=cloud_stored,
|
|
1776
|
+
vectorized=vectorized,
|
|
1777
|
+
content_uniqueness_check=content_uniqueness_check,
|
|
1778
|
+
tags=tags,
|
|
1779
|
+
source_documents_ids=source_documents_ids,
|
|
1780
|
+
private=private,
|
|
1781
|
+
)
|
|
1782
|
+
return AIKnowledgeFileSystemItem.model_validate(result)
|
|
1783
|
+
|
|
1784
|
+
def rename_file_or_folder(
|
|
1785
|
+
self, item_id: str, new_name: str, integration_name: str = None
|
|
1786
|
+
) -> AIKnowledgeFileSystemItem:
|
|
1787
|
+
"""
|
|
1788
|
+
Rename a file or folder.
|
|
1789
|
+
|
|
1790
|
+
Args:
|
|
1791
|
+
item_id: The ID of the file or folder to rename
|
|
1792
|
+
new_name: The new name for the file or folder
|
|
1793
|
+
integration_name: The name of the Integration
|
|
1794
|
+
|
|
1795
|
+
Returns:
|
|
1796
|
+
Updated file or folder object
|
|
1797
|
+
"""
|
|
1798
|
+
if integration_name is None:
|
|
1799
|
+
integration_name = self.client.integration_name
|
|
1800
|
+
|
|
1801
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/files-system-item/rename"
|
|
1802
|
+
params = {
|
|
1803
|
+
"item_id": item_id,
|
|
1804
|
+
"new_name": new_name,
|
|
1805
|
+
"integration_name": integration_name,
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
headers = self.client._get_auth_headers()
|
|
1809
|
+
response = self.client.session.patch(url, headers=headers, params=params)
|
|
1810
|
+
result = self.client._handle_response(response)
|
|
1811
|
+
return AIKnowledgeFileSystemItem.model_validate(result)
|
|
1812
|
+
|
|
1813
|
+
def update_file_or_folder(
|
|
1814
|
+
self,
|
|
1815
|
+
item_id: str,
|
|
1816
|
+
integration_name: str = None,
|
|
1817
|
+
is_starred: Optional[bool] = None,
|
|
1818
|
+
tags: Optional[List[str]] = None,
|
|
1819
|
+
) -> AIKnowledgeFileSystemItem:
|
|
1820
|
+
"""
|
|
1821
|
+
Update a file or folder's properties.
|
|
1822
|
+
|
|
1823
|
+
Args:
|
|
1824
|
+
item_id: The ID of the file or folder to update
|
|
1825
|
+
integration_name: The name of the Integration
|
|
1826
|
+
is_starred: Whether the file or folder is starred
|
|
1827
|
+
tags: List of tags for the file or folder
|
|
1828
|
+
|
|
1829
|
+
Returns:
|
|
1830
|
+
Updated file or folder object
|
|
1831
|
+
"""
|
|
1832
|
+
if integration_name is None:
|
|
1833
|
+
integration_name = self.client.integration_name
|
|
1834
|
+
|
|
1835
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/files-system-item/update"
|
|
1836
|
+
params = {"item_id": item_id, "integration_name": integration_name}
|
|
1837
|
+
|
|
1838
|
+
if is_starred is not None:
|
|
1839
|
+
params["is_starred"] = is_starred
|
|
1840
|
+
if tags is not None:
|
|
1841
|
+
params["tags"] = tags
|
|
1842
|
+
|
|
1843
|
+
headers = self.client._get_auth_headers()
|
|
1844
|
+
response = self.client.session.patch(url, headers=headers, params=params)
|
|
1845
|
+
result = self.client._handle_response(response)
|
|
1846
|
+
return AIKnowledgeFileSystemItem.model_validate(result)
|
|
1847
|
+
|
|
1848
|
+
def delete_file_or_folder(self, item_id: str, integration_name: str = None) -> None:
|
|
1849
|
+
"""
|
|
1850
|
+
Delete a file or folder.
|
|
1851
|
+
|
|
1852
|
+
Args:
|
|
1853
|
+
item_id: The ID of the file or folder to delete
|
|
1854
|
+
integration_name: The name of the Integration
|
|
1855
|
+
"""
|
|
1856
|
+
if integration_name is None:
|
|
1857
|
+
integration_name = self.client.integration_name
|
|
1858
|
+
|
|
1859
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/file-system-item/delete"
|
|
1860
|
+
params = {"item_id": item_id, "integration_name": integration_name}
|
|
1861
|
+
|
|
1862
|
+
headers = self.client._get_auth_headers()
|
|
1863
|
+
response = self.client.session.delete(url, headers=headers, params=params)
|
|
1864
|
+
self.client._handle_response(response)
|
|
1865
|
+
|
|
1866
|
+
def get_file_or_folder(self, item_id: str, integration_name: str = None) -> AIKnowledgeFileSystemItem:
|
|
1867
|
+
"""
|
|
1868
|
+
Get details of a file or folder.
|
|
1869
|
+
|
|
1870
|
+
Args:
|
|
1871
|
+
item_id: The ID of the file or folder
|
|
1872
|
+
integration_name: The name of the Integration
|
|
1873
|
+
|
|
1874
|
+
Returns:
|
|
1875
|
+
File or folder object
|
|
1876
|
+
"""
|
|
1877
|
+
if integration_name is None:
|
|
1878
|
+
integration_name = self.client.integration_name
|
|
1879
|
+
|
|
1880
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/files-system-item/get"
|
|
1881
|
+
params = {"item_id": item_id, "integration_name": integration_name}
|
|
1882
|
+
|
|
1883
|
+
headers = self.client._get_auth_headers()
|
|
1884
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1885
|
+
result = self.client._handle_response(response)
|
|
1886
|
+
return AIKnowledgeFileSystemItem.model_validate(result)
|
|
1887
|
+
|
|
1888
|
+
def get_file_or_folder_path(self, item_id: str, integration_name: str = None) -> List[AIKnowledgeFileSystemItem]:
|
|
1889
|
+
"""
|
|
1890
|
+
Get the path of a file or folder.
|
|
1891
|
+
|
|
1892
|
+
Args:
|
|
1893
|
+
item_id: The ID of the file or folder
|
|
1894
|
+
integration_name: The name of the Integration
|
|
1895
|
+
|
|
1896
|
+
Returns:
|
|
1897
|
+
List of path components as objects
|
|
1898
|
+
"""
|
|
1899
|
+
if integration_name is None:
|
|
1900
|
+
integration_name = self.client.integration_name
|
|
1901
|
+
|
|
1902
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/files-system-item/get-path"
|
|
1903
|
+
params = {"item_id": item_id, "integration_name": integration_name}
|
|
1904
|
+
|
|
1905
|
+
headers = self.client._get_auth_headers()
|
|
1906
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1907
|
+
results = self.client._handle_response(response)
|
|
1908
|
+
return [AIKnowledgeFileSystemItem.model_validate(result) for result in results]
|
|
1909
|
+
|
|
1910
|
+
def list_files_and_folders(
|
|
1911
|
+
self,
|
|
1912
|
+
filters: AIKnowledgeFileSystemFilters = AIKnowledgeFileSystemFilters(),
|
|
1913
|
+
integration_name: str = None,
|
|
1914
|
+
) -> AIKnowledgeFileSystemItemsList:
|
|
1915
|
+
"""
|
|
1916
|
+
List files and folders.
|
|
1917
|
+
|
|
1918
|
+
Args:
|
|
1919
|
+
filters: Dictionary of filter parameters
|
|
1920
|
+
integration_name: The name of the Integration
|
|
1921
|
+
|
|
1922
|
+
Returns:
|
|
1923
|
+
Dictionary with items, pagination info, etc.
|
|
1924
|
+
"""
|
|
1925
|
+
if integration_name is None:
|
|
1926
|
+
integration_name = self.client.integration_name
|
|
1927
|
+
|
|
1928
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/files-system-item/list"
|
|
1929
|
+
params = {"integration_name": integration_name}
|
|
1930
|
+
|
|
1931
|
+
headers = self.client._get_auth_headers()
|
|
1932
|
+
response = self.client.session.post(
|
|
1933
|
+
url,
|
|
1934
|
+
headers=headers,
|
|
1935
|
+
params=params,
|
|
1936
|
+
json=filters.to_serializible_non_empty_dict(),
|
|
1937
|
+
)
|
|
1938
|
+
result = self.client._handle_response(response)
|
|
1939
|
+
return AIKnowledgeFileSystemItemsList.model_validate(result)
|
|
1940
|
+
|
|
1941
|
+
def count_files_and_folders(
|
|
1942
|
+
self, parents: List[str], integration_name: str = None
|
|
1943
|
+
) -> FileSystemItemAggregatedCount:
|
|
1944
|
+
"""
|
|
1945
|
+
Count files and folders.
|
|
1946
|
+
|
|
1947
|
+
Args:
|
|
1948
|
+
parents: List of parent folder IDs
|
|
1949
|
+
integration_name: The name of the Integration
|
|
1950
|
+
|
|
1951
|
+
Returns:
|
|
1952
|
+
Dictionary with count information
|
|
1953
|
+
"""
|
|
1954
|
+
if integration_name is None:
|
|
1955
|
+
integration_name = self.client.integration_name
|
|
1956
|
+
|
|
1957
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/files-system-item/count"
|
|
1958
|
+
params = {"parents": parents, "integration_name": integration_name}
|
|
1959
|
+
|
|
1960
|
+
headers = self.client._get_auth_headers()
|
|
1961
|
+
response = self.client.session.post(url, headers=headers, params=params)
|
|
1962
|
+
result = self.client._handle_response(response)
|
|
1963
|
+
return FileSystemItemAggregatedCount.model_validate(result)
|
|
1964
|
+
|
|
1965
|
+
def get_download_link_for_document(
|
|
1966
|
+
self, item_id: str, expiration_seconds: int = 60, integration_name: str = None
|
|
1967
|
+
) -> str:
|
|
1968
|
+
"""
|
|
1969
|
+
Get a download link for a file.
|
|
1970
|
+
|
|
1971
|
+
Args:
|
|
1972
|
+
item_id: The ID of the file
|
|
1973
|
+
expiration_seconds: Time in seconds for the link to remain valid
|
|
1974
|
+
integration_name: The name of the Integration
|
|
1975
|
+
|
|
1976
|
+
Returns:
|
|
1977
|
+
Download URL as a string
|
|
1978
|
+
"""
|
|
1979
|
+
if integration_name is None:
|
|
1980
|
+
integration_name = self.client.integration_name
|
|
1981
|
+
|
|
1982
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/file/download-link"
|
|
1983
|
+
params = {
|
|
1984
|
+
"item_id": item_id,
|
|
1985
|
+
"expiration_seconds": expiration_seconds,
|
|
1986
|
+
"integration_name": integration_name,
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
headers = self.client._get_auth_headers()
|
|
1990
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
1991
|
+
return self.client._handle_response(response)
|
|
1992
|
+
|
|
1993
|
+
def grant_or_revoke_user_access(
|
|
1994
|
+
self,
|
|
1995
|
+
item_id: str,
|
|
1996
|
+
user_id: str,
|
|
1997
|
+
has_access: bool,
|
|
1998
|
+
access_type: FileAccessType = FileAccessType.READ,
|
|
1999
|
+
integration_name: str = None,
|
|
2000
|
+
) -> Union[None, AIKnowledgeFileSystemItem]:
|
|
2001
|
+
"""
|
|
2002
|
+
Grant or revoke user access to a file or folder.
|
|
2003
|
+
|
|
2004
|
+
Args:
|
|
2005
|
+
item_id: The ID of the file or folder
|
|
2006
|
+
user_id: The ID of the user
|
|
2007
|
+
has_access: Whether to grant (True) or revoke (False) access
|
|
2008
|
+
access_type: Type of access ("READ" or "WRITE")
|
|
2009
|
+
integration_name: The name of the Integration
|
|
2010
|
+
|
|
2011
|
+
Returns:
|
|
2012
|
+
Updated file or folder object
|
|
2013
|
+
"""
|
|
2014
|
+
if integration_name is None:
|
|
2015
|
+
integration_name = self.client.integration_name
|
|
2016
|
+
|
|
2017
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/files-system-item/grant-revoke-access/user"
|
|
2018
|
+
params = {
|
|
2019
|
+
"item_id": item_id,
|
|
2020
|
+
"user_id": user_id,
|
|
2021
|
+
"has_access": has_access,
|
|
2022
|
+
"access_type": access_type,
|
|
2023
|
+
"integration_name": integration_name,
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
headers = self.client._get_auth_headers()
|
|
2027
|
+
response = self.client.session.post(url, headers=headers, params=params)
|
|
2028
|
+
result = self.client._handle_response(response)
|
|
2029
|
+
return AIKnowledgeFileSystemItem.model_validate(result) if result else None
|
|
2030
|
+
|
|
2031
|
+
def grant_or_revoke_security_group_access(
|
|
2032
|
+
self,
|
|
2033
|
+
item_id: str,
|
|
2034
|
+
group_id: str,
|
|
2035
|
+
has_access: bool,
|
|
2036
|
+
access_type: str = "READ",
|
|
2037
|
+
integration_name: str = None,
|
|
2038
|
+
) -> Union[None, AIKnowledgeFileSystemItem]:
|
|
2039
|
+
"""
|
|
2040
|
+
Grant or revoke security group access to a file or folder.
|
|
2041
|
+
|
|
2042
|
+
Args:
|
|
2043
|
+
item_id: The ID of the file or folder
|
|
2044
|
+
group_id: The ID of the security group
|
|
2045
|
+
has_access: Whether to grant (True) or revoke (False) access
|
|
2046
|
+
access_type: Type of access ("READ" or "WRITE")
|
|
2047
|
+
integration_name: The name of the Integration
|
|
2048
|
+
|
|
2049
|
+
Returns:
|
|
2050
|
+
Updated file or folder object
|
|
2051
|
+
"""
|
|
2052
|
+
if integration_name is None:
|
|
2053
|
+
integration_name = self.client.integration_name
|
|
2054
|
+
|
|
2055
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/files-system-item/grant-revoke-access/security-group"
|
|
2056
|
+
params = {
|
|
2057
|
+
"item_id": item_id,
|
|
2058
|
+
"group_id": group_id,
|
|
2059
|
+
"has_access": has_access,
|
|
2060
|
+
"access_type": access_type,
|
|
2061
|
+
"integration_name": integration_name,
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
headers = self.client._get_auth_headers()
|
|
2065
|
+
response = self.client.session.post(url, headers=headers, params=params)
|
|
2066
|
+
result = self.client._handle_response(response)
|
|
2067
|
+
return AIKnowledgeFileSystemItem.model_validate(result) if result else None
|
|
2068
|
+
|
|
2069
|
+
|
|
2070
|
+
class DatabaseAIKnowledgeAdmin:
|
|
2071
|
+
"""Admin client for AI Knowledge database management."""
|
|
2072
|
+
|
|
2073
|
+
def __init__(self, client: VectorBridgeClient):
|
|
2074
|
+
self.client = client
|
|
2075
|
+
|
|
2076
|
+
def process_content(
|
|
2077
|
+
self,
|
|
2078
|
+
content_data: AIKnowledgeCreate,
|
|
2079
|
+
schema_name: str,
|
|
2080
|
+
unique_identifier: str,
|
|
2081
|
+
integration_name: str = None,
|
|
2082
|
+
content_uniqueness_check: bool = True,
|
|
2083
|
+
) -> Dict[str, Any]:
|
|
2084
|
+
"""
|
|
2085
|
+
Process content for updating or inserting.
|
|
2086
|
+
|
|
2087
|
+
Args:
|
|
2088
|
+
content_data: Content data
|
|
2089
|
+
schema_name: The name of the Vector DB Schema
|
|
2090
|
+
unique_identifier: The unique identifier of the content entity
|
|
2091
|
+
integration_name: The name of the Integration
|
|
2092
|
+
content_uniqueness_check: Check for content uniqueness
|
|
2093
|
+
|
|
2094
|
+
Returns:
|
|
2095
|
+
Processed content object
|
|
2096
|
+
"""
|
|
2097
|
+
if integration_name is None:
|
|
2098
|
+
integration_name = self.client.integration_name
|
|
2099
|
+
|
|
2100
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/content/upsert"
|
|
2101
|
+
params = {
|
|
2102
|
+
"integration_name": integration_name,
|
|
2103
|
+
"content_uniqueness_check": content_uniqueness_check,
|
|
2104
|
+
"schema_name": schema_name,
|
|
2105
|
+
"unique_identifier": unique_identifier,
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
headers = self.client._get_auth_headers()
|
|
2109
|
+
response = self.client.session.post(url, headers=headers, params=params, json=content_data.model_dump())
|
|
2110
|
+
return self.client._handle_response(response)
|
|
2111
|
+
|
|
2112
|
+
def update_item(
|
|
2113
|
+
self,
|
|
2114
|
+
item_data: Dict[str, Any],
|
|
2115
|
+
schema_name: str,
|
|
2116
|
+
item_id: str,
|
|
2117
|
+
integration_name: str = None,
|
|
2118
|
+
) -> None:
|
|
2119
|
+
"""
|
|
2120
|
+
Update an item.
|
|
2121
|
+
|
|
2122
|
+
Args:
|
|
2123
|
+
item_data: Item data to update
|
|
2124
|
+
schema_name: The name of the Vector DB Schema
|
|
2125
|
+
item_id: The ID of the content chunk
|
|
2126
|
+
integration_name: The name of the Integration
|
|
2127
|
+
"""
|
|
2128
|
+
if integration_name is None:
|
|
2129
|
+
integration_name = self.client.integration_name
|
|
2130
|
+
|
|
2131
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/content/update_item"
|
|
2132
|
+
params = {
|
|
2133
|
+
"integration_name": integration_name,
|
|
2134
|
+
"schema_name": schema_name,
|
|
2135
|
+
"item_id": item_id,
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
headers = self.client._get_auth_headers()
|
|
2139
|
+
response = self.client.session.post(url, headers=headers, params=params, json=item_data)
|
|
2140
|
+
self.client._handle_response(response)
|
|
2141
|
+
|
|
2142
|
+
def get_content(
|
|
2143
|
+
self, schema_name: str, unique_identifier: str, integration_name: str = None
|
|
2144
|
+
) -> List[Dict[str, Any]]:
|
|
2145
|
+
"""
|
|
2146
|
+
Get content by unique identifier.
|
|
2147
|
+
|
|
2148
|
+
Args:
|
|
2149
|
+
schema_name: The name of the Vector DB Schema
|
|
2150
|
+
unique_identifier: The unique identifier of the content entity
|
|
2151
|
+
integration_name: The name of the Integration
|
|
2152
|
+
|
|
2153
|
+
Returns:
|
|
2154
|
+
List of content objects
|
|
2155
|
+
"""
|
|
2156
|
+
if integration_name is None:
|
|
2157
|
+
integration_name = self.client.integration_name
|
|
2158
|
+
|
|
2159
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/content"
|
|
2160
|
+
params = {
|
|
2161
|
+
"integration_name": integration_name,
|
|
2162
|
+
"schema_name": schema_name,
|
|
2163
|
+
"unique_identifier": unique_identifier,
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
headers = self.client._get_auth_headers()
|
|
2167
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
2168
|
+
return self.client._handle_response(response)
|
|
2169
|
+
|
|
2170
|
+
def get_content_list(
|
|
2171
|
+
self, filters: Dict[str, Any], schema_name: str, integration_name: str = None
|
|
2172
|
+
) -> AIKnowledgeList:
|
|
2173
|
+
"""
|
|
2174
|
+
Get a list of content.
|
|
2175
|
+
|
|
2176
|
+
Args:
|
|
2177
|
+
filters: Content filters
|
|
2178
|
+
schema_name: The name of the Vector DB Schema
|
|
2179
|
+
integration_name: The name of the Integration
|
|
2180
|
+
|
|
2181
|
+
Returns:
|
|
2182
|
+
Dict with content items and pagination info
|
|
2183
|
+
"""
|
|
2184
|
+
if integration_name is None:
|
|
2185
|
+
integration_name = self.client.integration_name
|
|
2186
|
+
|
|
2187
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/content/list"
|
|
2188
|
+
params = {"integration_name": integration_name, "schema_name": schema_name}
|
|
2189
|
+
|
|
2190
|
+
headers = self.client._get_auth_headers()
|
|
2191
|
+
response = self.client.session.post(url, headers=headers, params=params, json=filters)
|
|
2192
|
+
result = self.client._handle_response(response)
|
|
2193
|
+
return AIKnowledgeList.model_validate(result)
|
|
2194
|
+
|
|
2195
|
+
def delete_content(self, schema_name: str, unique_identifier: str, integration_name: str = None) -> None:
|
|
2196
|
+
"""
|
|
2197
|
+
Delete content by unique identifier.
|
|
2198
|
+
|
|
2199
|
+
Args:
|
|
2200
|
+
schema_name: The name of the Vector DB Schema
|
|
2201
|
+
unique_identifier: The unique identifier of the content entity
|
|
2202
|
+
integration_name: The name of the Integration
|
|
2203
|
+
"""
|
|
2204
|
+
if integration_name is None:
|
|
2205
|
+
integration_name = self.client.integration_name
|
|
2206
|
+
|
|
2207
|
+
url = f"{self.client.base_url}/v1/admin/ai-knowledge/content/delete"
|
|
2208
|
+
params = {
|
|
2209
|
+
"integration_name": integration_name,
|
|
2210
|
+
"schema_name": schema_name,
|
|
2211
|
+
"unique_identifier": unique_identifier,
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
headers = self.client._get_auth_headers()
|
|
2215
|
+
response = self.client.session.delete(url, headers=headers, params=params)
|
|
2216
|
+
if response.status_code != 204:
|
|
2217
|
+
self.client._handle_response(response)
|
|
2218
|
+
|
|
2219
|
+
|
|
2220
|
+
# class DatabaseAdmin:
|
|
2221
|
+
# """Admin client for vector database management endpoints."""
|
|
2222
|
+
#
|
|
2223
|
+
# def __init__(self, client: VectorBridgeClient):
|
|
2224
|
+
# self.client = client
|
|
2225
|
+
# self.state = DatabaseStateAdmin(client)
|
|
2226
|
+
# self.changeset = DatabaseChangesetAdmin(client)
|
|
2227
|
+
#
|
|
2228
|
+
#
|
|
2229
|
+
# class DatabaseStateAdmin:
|
|
2230
|
+
# """Admin client for vector database state management."""
|
|
2231
|
+
#
|
|
2232
|
+
# def __init__(self, client: VectorBridgeClient):
|
|
2233
|
+
# self.client = client
|
|
2234
|
+
#
|
|
2235
|
+
# def apply_schemas_changes(
|
|
2236
|
+
# self,
|
|
2237
|
+
# integration_name: str = "default"
|
|
2238
|
+
# ) -> List[Dict[str, Any]]:
|
|
2239
|
+
# """
|
|
2240
|
+
# Apply VectorDB schemas changes.
|
|
2241
|
+
#
|
|
2242
|
+
# Args:
|
|
2243
|
+
# integration_name: The name of the Integration
|
|
2244
|
+
#
|
|
2245
|
+
# Returns:
|
|
2246
|
+
# List of schema states
|
|
2247
|
+
# """
|
|
2248
|
+
# url = f"{self.client.base_url}/v1/admin/vector-db/schemas/apply-changes"
|
|
2249
|
+
# params = {"integration_name": integration_name}
|
|
2250
|
+
#
|
|
2251
|
+
# headers = self.client._get_auth_headers()
|
|
2252
|
+
# response = self.client.session.post(url, headers=headers, params=params)
|
|
2253
|
+
# return self.client._handle_response(response)
|
|
2254
|
+
#
|
|
2255
|
+
# def discard_schemas_changes(
|
|
2256
|
+
# self,
|
|
2257
|
+
# integration_name: str = "default"
|
|
2258
|
+
# ) -> List[Dict[str, Any]]:
|
|
2259
|
+
# """
|
|
2260
|
+
# Discard VectorDB schemas changes.
|
|
2261
|
+
#
|
|
2262
|
+
# Args:
|
|
2263
|
+
# integration_name: The name of the Integration
|
|
2264
|
+
#
|
|
2265
|
+
# Returns:
|
|
2266
|
+
# List of schema states
|
|
2267
|
+
# """
|
|
2268
|
+
# url = f"{self.client.base_url}/v1/admin/vector-db/schemas/discard-changes"
|
|
2269
|
+
# params = {"integration_name": integration_name}
|
|
2270
|
+
#
|
|
2271
|
+
# headers = self.client._get_auth_headers()
|
|
2272
|
+
# response = self.client.session.post(url, headers=headers, params=params)
|
|
2273
|
+
# return self.client._handle_response(response)
|
|
2274
|
+
#
|
|
2275
|
+
#
|
|
2276
|
+
# class DatabaseChangesetAdmin:
|
|
2277
|
+
# """Admin client for vector database changeset management."""
|
|
2278
|
+
#
|
|
2279
|
+
# def __init__(self, client: VectorBridgeClient):
|
|
2280
|
+
# self.client = client
|
|
2281
|
+
#
|
|
2282
|
+
# def get_changeset_diff(
|
|
2283
|
+
# self,
|
|
2284
|
+
# integration_name: str = "default"
|
|
2285
|
+
# ) -> List[Dict[str, Any]]:
|
|
2286
|
+
# """
|
|
2287
|
+
# Get the changeset diff.
|
|
2288
|
+
#
|
|
2289
|
+
# Args:
|
|
2290
|
+
# integration_name: The name of the Integration
|
|
2291
|
+
#
|
|
2292
|
+
# Returns:
|
|
2293
|
+
# List of schema states with diffs
|
|
2294
|
+
# """
|
|
2295
|
+
# url = f"{self.client.base_url}/v1/admin/vector-db/changeset/diff"
|
|
2296
|
+
# params = {"integration_name": integration_name}
|
|
2297
|
+
#
|
|
2298
|
+
# headers = self.client._get_auth_headers()
|
|
2299
|
+
# response = self.client.session.get(url, headers=headers, params=params)
|
|
2300
|
+
# return self.client._handle_response(response)
|
|
2301
|
+
#
|
|
2302
|
+
# def add_schema(
|
|
2303
|
+
# self,
|
|
2304
|
+
# schema_data: Dict[str, str],
|
|
2305
|
+
# integration_name: str = "default"
|
|
2306
|
+
# ) -> List[Dict[str, Any]]:
|
|
2307
|
+
# """
|
|
2308
|
+
# Add creation of a new Schema to the changeset.
|
|
2309
|
+
#
|
|
2310
|
+
# Args:
|
|
2311
|
+
# schema_data: Schema details
|
|
2312
|
+
# integration_name: The name of the Integration
|
|
2313
|
+
#
|
|
2314
|
+
# Returns:
|
|
2315
|
+
# List of schema states
|
|
2316
|
+
# """
|
|
2317
|
+
# url = f"{self.client.base_url}/v1/admin/vector-db/changeset/schema/add"
|
|
2318
|
+
# params = {"integration_name": integration_name}
|
|
2319
|
+
#
|
|
2320
|
+
# headers = self.client._get_auth_headers()
|
|
2321
|
+
# response = self.client.session.post(
|
|
2322
|
+
# url,
|
|
2323
|
+
# headers=headers,
|
|
2324
|
+
# params=params,
|
|
2325
|
+
# json=schema_data
|
|
2326
|
+
# )
|
|
2327
|
+
# return self.client._handle_response(response)
|
|
2328
|
+
|
|
2329
|
+
|
|
2330
|
+
class QueryAdmin:
|
|
2331
|
+
"""Admin client for vector query endpoints."""
|
|
2332
|
+
|
|
2333
|
+
def __init__(self, client: VectorBridgeClient):
|
|
2334
|
+
self.client = client
|
|
2335
|
+
|
|
2336
|
+
def run_search_query(
|
|
2337
|
+
self,
|
|
2338
|
+
vector_schema: str,
|
|
2339
|
+
query_kwargs: Dict[str, Any],
|
|
2340
|
+
integration_name: str = None,
|
|
2341
|
+
) -> Any:
|
|
2342
|
+
"""
|
|
2343
|
+
Run a vector search query.
|
|
2344
|
+
|
|
2345
|
+
Args:
|
|
2346
|
+
vector_schema: The schema to be queried
|
|
2347
|
+
query_kwargs: Query parameters
|
|
2348
|
+
integration_name: The name of the Integration
|
|
2349
|
+
|
|
2350
|
+
Returns:
|
|
2351
|
+
Search results
|
|
2352
|
+
"""
|
|
2353
|
+
if integration_name is None:
|
|
2354
|
+
integration_name = self.client.integration_name
|
|
2355
|
+
|
|
2356
|
+
url = f"{self.client.base_url}/v1/admin/vector-query/search/run"
|
|
2357
|
+
params = {"vector_schema": vector_schema, "integration_name": integration_name}
|
|
2358
|
+
|
|
2359
|
+
headers = self.client._get_auth_headers()
|
|
2360
|
+
response = self.client.session.post(url, headers=headers, params=params, json=query_kwargs)
|
|
2361
|
+
return self.client._handle_response(response)
|
|
2362
|
+
|
|
2363
|
+
def run_find_similar_query(
|
|
2364
|
+
self,
|
|
2365
|
+
vector_schema: str,
|
|
2366
|
+
query_kwargs: Dict[str, Any],
|
|
2367
|
+
integration_name: str = None,
|
|
2368
|
+
) -> Any:
|
|
2369
|
+
"""
|
|
2370
|
+
Run a vector similarity query.
|
|
2371
|
+
|
|
2372
|
+
Args:
|
|
2373
|
+
vector_schema: The schema to be queried
|
|
2374
|
+
query_kwargs: Query parameters {"uuid" <uuid of the chunk>}
|
|
2375
|
+
integration_name: The name of the Integration
|
|
2376
|
+
|
|
2377
|
+
Returns:
|
|
2378
|
+
Search results
|
|
2379
|
+
"""
|
|
2380
|
+
if integration_name is None:
|
|
2381
|
+
integration_name = self.client.integration_name
|
|
2382
|
+
|
|
2383
|
+
url = f"{self.client.base_url}/v1/admin/vector-query/find-similar/run"
|
|
2384
|
+
params = {"vector_schema": vector_schema, "integration_name": integration_name}
|
|
2385
|
+
|
|
2386
|
+
headers = self.client._get_auth_headers()
|
|
2387
|
+
response = self.client.session.post(url, headers=headers, params=params, json=query_kwargs)
|
|
2388
|
+
return self.client._handle_response(response)
|
|
2389
|
+
|
|
2390
|
+
|
|
2391
|
+
class AIClient:
|
|
2392
|
+
"""User client for AI endpoints that require an API key."""
|
|
2393
|
+
|
|
2394
|
+
def __init__(self, client: VectorBridgeClient):
|
|
2395
|
+
self.client = client
|
|
2396
|
+
|
|
2397
|
+
def set_current_agent(
|
|
2398
|
+
self,
|
|
2399
|
+
user_id: str,
|
|
2400
|
+
agent_name: str,
|
|
2401
|
+
integration_name: str = None,
|
|
2402
|
+
instruction_name: str = "default",
|
|
2403
|
+
) -> Chat:
|
|
2404
|
+
"""
|
|
2405
|
+
Set the current agent.
|
|
2406
|
+
|
|
2407
|
+
Args:
|
|
2408
|
+
user_id: User ID
|
|
2409
|
+
agent_name: The agent to set
|
|
2410
|
+
api_key: API key for authentication
|
|
2411
|
+
integration_name: The name of the Integration
|
|
2412
|
+
instruction_name: The name of the instruction
|
|
2413
|
+
|
|
2414
|
+
Returns:
|
|
2415
|
+
Chat object
|
|
2416
|
+
"""
|
|
2417
|
+
if integration_name is None:
|
|
2418
|
+
integration_name = self.client.integration_name
|
|
2419
|
+
|
|
2420
|
+
url = f"{self.client.base_url}/v1/ai/agent/set"
|
|
2421
|
+
params = {
|
|
2422
|
+
"user_id": user_id,
|
|
2423
|
+
"integration_name": integration_name,
|
|
2424
|
+
"instruction_name": instruction_name,
|
|
2425
|
+
"agent_name": agent_name,
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2429
|
+
response = self.client.session.patch(url, headers=headers, params=params)
|
|
2430
|
+
result = self.client._handle_response(response)
|
|
2431
|
+
return Chat.model_validate(result)
|
|
2432
|
+
|
|
2433
|
+
def set_core_knowledge(self, user_id: str, core_knowledge: Dict[str, Any], integration_name: str = None) -> Chat:
|
|
2434
|
+
"""
|
|
2435
|
+
Set the core knowledge.
|
|
2436
|
+
|
|
2437
|
+
Args:
|
|
2438
|
+
user_id: User ID
|
|
2439
|
+
core_knowledge: The core knowledge to set
|
|
2440
|
+
integration_name: The name of the Integration
|
|
2441
|
+
|
|
2442
|
+
Returns:
|
|
2443
|
+
Chat object
|
|
2444
|
+
"""
|
|
2445
|
+
if integration_name is None:
|
|
2446
|
+
integration_name = self.client.integration_name
|
|
2447
|
+
|
|
2448
|
+
url = f"{self.client.base_url}/v1/ai/core-knowledge/set"
|
|
2449
|
+
params = {"user_id": user_id, "integration_name": integration_name}
|
|
2450
|
+
|
|
2451
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2452
|
+
response = self.client.session.patch(url, headers=headers, params=params, json=core_knowledge)
|
|
2453
|
+
result = self.client._handle_response(response)
|
|
2454
|
+
return Chat.model_validate(result)
|
|
2455
|
+
|
|
2456
|
+
|
|
2457
|
+
class AIMessageClient:
|
|
2458
|
+
"""User client for message endpoints that require an API key."""
|
|
2459
|
+
|
|
2460
|
+
def __init__(self, client: VectorBridgeClient):
|
|
2461
|
+
self.client = client
|
|
2462
|
+
|
|
2463
|
+
def process_message_stream(
|
|
2464
|
+
self,
|
|
2465
|
+
content: str,
|
|
2466
|
+
user_id: str,
|
|
2467
|
+
integration_name: str = None,
|
|
2468
|
+
instruction_name: str = "default",
|
|
2469
|
+
function_to_call: Optional[str] = None,
|
|
2470
|
+
data: Optional[Dict[str, Any]] = None,
|
|
2471
|
+
crypto_key: Optional[str] = None,
|
|
2472
|
+
) -> StreamingResponse:
|
|
2473
|
+
"""
|
|
2474
|
+
Process a message and get streaming AI response.
|
|
2475
|
+
|
|
2476
|
+
Args:
|
|
2477
|
+
content: Message content
|
|
2478
|
+
user_id: User ID (anything to identify a chat with a user)
|
|
2479
|
+
integration_name: The name of the integration
|
|
2480
|
+
instruction_name: The name of the instruction
|
|
2481
|
+
function_to_call: Function to call (optional)
|
|
2482
|
+
data: Additional data (optional)
|
|
2483
|
+
crypto_key: Crypto key for encrypted storage (optional)
|
|
2484
|
+
|
|
2485
|
+
Returns:
|
|
2486
|
+
Stream of message objects including AI response
|
|
2487
|
+
"""
|
|
2488
|
+
if integration_name is None:
|
|
2489
|
+
integration_name = self.client.integration_name
|
|
2490
|
+
|
|
2491
|
+
url = f"{self.client.base_url}/v1/stream/ai/process-message/response-text"
|
|
2492
|
+
params = {
|
|
2493
|
+
"user_id": user_id,
|
|
2494
|
+
"integration_name": integration_name,
|
|
2495
|
+
"instruction_name": instruction_name,
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
if function_to_call:
|
|
2499
|
+
params["function_to_call"] = function_to_call
|
|
2500
|
+
|
|
2501
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2502
|
+
if crypto_key:
|
|
2503
|
+
headers["Crypto-Key"] = crypto_key
|
|
2504
|
+
|
|
2505
|
+
message_data = {"content": content}
|
|
2506
|
+
if data:
|
|
2507
|
+
message_data["data"] = data
|
|
2508
|
+
|
|
2509
|
+
response = self.client.session.post(url, headers=headers, params=params, json=message_data, stream=True)
|
|
2510
|
+
if response.status_code >= 400:
|
|
2511
|
+
self.client._handle_response(response) # This should raise an appropriate exception
|
|
2512
|
+
|
|
2513
|
+
return StreamingResponse(response)
|
|
2514
|
+
|
|
2515
|
+
def process_message_json(
|
|
2516
|
+
self,
|
|
2517
|
+
content: str,
|
|
2518
|
+
response_structure_definition: BaseModel,
|
|
2519
|
+
user_id: str,
|
|
2520
|
+
integration_name: str = None,
|
|
2521
|
+
instruction_name: str = "default",
|
|
2522
|
+
available_functions: Optional[List[str]] = None,
|
|
2523
|
+
function_to_call: Optional[str] = None,
|
|
2524
|
+
data: Optional[Dict[str, Any]] = None,
|
|
2525
|
+
crypto_key: Optional[str] = None,
|
|
2526
|
+
) -> BaseModel:
|
|
2527
|
+
"""
|
|
2528
|
+
Process a message and get AI response as structured JSON.
|
|
2529
|
+
|
|
2530
|
+
Args:
|
|
2531
|
+
content: Message content
|
|
2532
|
+
response_structure_definition: Structure definition for the response
|
|
2533
|
+
user_id: User ID
|
|
2534
|
+
integration_name: The name of the integration
|
|
2535
|
+
instruction_name: The name of the instruction
|
|
2536
|
+
available_functions: Override the functions accessible to AI
|
|
2537
|
+
function_to_call: Function to call (optional)
|
|
2538
|
+
data: Additional data (optional)
|
|
2539
|
+
crypto_key: Crypto key for encrypted storage (optional)
|
|
2540
|
+
|
|
2541
|
+
Returns:
|
|
2542
|
+
JSON response from AI
|
|
2543
|
+
"""
|
|
2544
|
+
if integration_name is None:
|
|
2545
|
+
integration_name = self.client.integration_name
|
|
2546
|
+
|
|
2547
|
+
url = f"{self.client.base_url}/v1/ai/process-message/response-json"
|
|
2548
|
+
params = {
|
|
2549
|
+
"user_id": user_id,
|
|
2550
|
+
"integration_name": integration_name,
|
|
2551
|
+
"instruction_name": instruction_name,
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
if available_functions:
|
|
2555
|
+
params["available_functions"] = available_functions
|
|
2556
|
+
|
|
2557
|
+
if function_to_call:
|
|
2558
|
+
params["function_to_call"] = function_to_call
|
|
2559
|
+
|
|
2560
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2561
|
+
if crypto_key:
|
|
2562
|
+
headers["Crypto-Key"] = crypto_key
|
|
2563
|
+
|
|
2564
|
+
model_json_schema = response_structure_definition.model_json_schema()
|
|
2565
|
+
|
|
2566
|
+
message_data = {
|
|
2567
|
+
"content": content,
|
|
2568
|
+
"response_structure_definition": model_json_schema,
|
|
2569
|
+
}
|
|
2570
|
+
if data:
|
|
2571
|
+
message_data["data"] = data
|
|
2572
|
+
|
|
2573
|
+
response = self.client.session.post(url, headers=headers, params=params, json=message_data)
|
|
2574
|
+
result = self.client._handle_response(response)
|
|
2575
|
+
return response_structure_definition.model_validate(result)
|
|
2576
|
+
|
|
2577
|
+
def fetch_messages_from_vector_db(
|
|
2578
|
+
self,
|
|
2579
|
+
user_id: str,
|
|
2580
|
+
integration_name: str = None,
|
|
2581
|
+
limit: int = 50,
|
|
2582
|
+
offset: int = 0,
|
|
2583
|
+
sort_order: SortOrder = SortOrder.DESCENDING,
|
|
2584
|
+
near_text: Optional[str] = None,
|
|
2585
|
+
) -> MessagesListVectorDB:
|
|
2586
|
+
"""
|
|
2587
|
+
Retrieve messages from vector database.
|
|
2588
|
+
|
|
2589
|
+
Args:
|
|
2590
|
+
user_id: User ID
|
|
2591
|
+
integration_name: The name of the integration
|
|
2592
|
+
limit: Number of messages to return
|
|
2593
|
+
offset: Starting point for fetching records
|
|
2594
|
+
sort_order: Order to sort results (asc/desc)
|
|
2595
|
+
near_text: Text to search for semantically similar messages
|
|
2596
|
+
|
|
2597
|
+
Returns:
|
|
2598
|
+
MessagesListVectorDB with messages and pagination info
|
|
2599
|
+
"""
|
|
2600
|
+
if integration_name is None:
|
|
2601
|
+
integration_name = self.client.integration_name
|
|
2602
|
+
|
|
2603
|
+
url = f"{self.client.base_url}/v1/ai/messages/weaviate"
|
|
2604
|
+
params = {
|
|
2605
|
+
"user_id": user_id,
|
|
2606
|
+
"integration_name": integration_name,
|
|
2607
|
+
"limit": limit,
|
|
2608
|
+
"offset": offset,
|
|
2609
|
+
"sort_order": sort_order.value,
|
|
2610
|
+
}
|
|
2611
|
+
if near_text:
|
|
2612
|
+
params["near_text"] = near_text
|
|
2613
|
+
|
|
2614
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2615
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
2616
|
+
result = self.client._handle_response(response)
|
|
2617
|
+
return MessagesListVectorDB.model_validate(result)
|
|
2618
|
+
|
|
2619
|
+
def fetch_messages_from_dynamo_db(
|
|
2620
|
+
self,
|
|
2621
|
+
user_id: str,
|
|
2622
|
+
integration_name: str = None,
|
|
2623
|
+
limit: int = 50,
|
|
2624
|
+
last_evaluated_key: Optional[str] = None,
|
|
2625
|
+
sort_order: SortOrder = SortOrder.DESCENDING,
|
|
2626
|
+
crypto_key: Optional[str] = None,
|
|
2627
|
+
) -> MessagesListDynamoDB:
|
|
2628
|
+
"""
|
|
2629
|
+
Retrieve messages from DynamoDB.
|
|
2630
|
+
|
|
2631
|
+
Args:
|
|
2632
|
+
user_id: User ID
|
|
2633
|
+
integration_name: The name of the integration
|
|
2634
|
+
limit: Number of messages to return
|
|
2635
|
+
last_evaluated_key: Key for pagination
|
|
2636
|
+
sort_order: Order to sort results (asc/desc)
|
|
2637
|
+
crypto_key: Crypto key for decryption
|
|
2638
|
+
|
|
2639
|
+
Returns:
|
|
2640
|
+
Dict with messages and pagination info
|
|
2641
|
+
"""
|
|
2642
|
+
if integration_name is None:
|
|
2643
|
+
integration_name = self.client.integration_name
|
|
2644
|
+
|
|
2645
|
+
url = f"{self.client.base_url}/v1/ai/messages/dynamo-db"
|
|
2646
|
+
params = {
|
|
2647
|
+
"user_id": user_id,
|
|
2648
|
+
"integration_name": integration_name,
|
|
2649
|
+
"limit": limit,
|
|
2650
|
+
"sort_order": sort_order.value,
|
|
2651
|
+
}
|
|
2652
|
+
if last_evaluated_key:
|
|
2653
|
+
params["last_evaluated_key"] = last_evaluated_key
|
|
2654
|
+
|
|
2655
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2656
|
+
if crypto_key:
|
|
2657
|
+
headers["Crypto-Key"] = crypto_key
|
|
2658
|
+
|
|
2659
|
+
response = self.client.session.get(url, headers=headers, params=params)
|
|
2660
|
+
result = self.client._handle_response(response)
|
|
2661
|
+
return MessagesListDynamoDB.model_validate(result)
|
|
2662
|
+
|
|
2663
|
+
|
|
2664
|
+
class FunctionClient:
|
|
2665
|
+
"""User client for function endpoints that require an API key."""
|
|
2666
|
+
|
|
2667
|
+
def __init__(self, client: VectorBridgeClient):
|
|
2668
|
+
self.client = client
|
|
2669
|
+
|
|
2670
|
+
def run_function(
|
|
2671
|
+
self,
|
|
2672
|
+
function_name: str,
|
|
2673
|
+
function_args: Dict[str, Any],
|
|
2674
|
+
integration_name: str = None,
|
|
2675
|
+
instruction_name: str = "default",
|
|
2676
|
+
agent_name: str = "default",
|
|
2677
|
+
) -> Any:
|
|
2678
|
+
"""
|
|
2679
|
+
Run a function.
|
|
2680
|
+
|
|
2681
|
+
Args:
|
|
2682
|
+
function_name: The name of the function to run
|
|
2683
|
+
function_args: Arguments to pass to the function
|
|
2684
|
+
integration_name: The name of the Integration
|
|
2685
|
+
instruction_name: The name of the instruction
|
|
2686
|
+
agent_name: The name of the agent
|
|
2687
|
+
|
|
2688
|
+
Returns:
|
|
2689
|
+
Function execution result
|
|
2690
|
+
"""
|
|
2691
|
+
if integration_name is None:
|
|
2692
|
+
integration_name = self.client.integration_name
|
|
2693
|
+
|
|
2694
|
+
url = f"{self.client.base_url}/v1/function/{function_name}/run"
|
|
2695
|
+
params = {
|
|
2696
|
+
"integration_name": integration_name,
|
|
2697
|
+
"instruction_name": instruction_name,
|
|
2698
|
+
"agent_name": agent_name,
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2701
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2702
|
+
response = self.client.session.post(url, headers=headers, params=params, json=function_args)
|
|
2703
|
+
return self.client._handle_response(response)
|
|
2704
|
+
|
|
2705
|
+
|
|
2706
|
+
class QueryClient:
|
|
2707
|
+
"""User client for query endpoints that require an API key."""
|
|
2708
|
+
|
|
2709
|
+
def __init__(self, client: VectorBridgeClient):
|
|
2710
|
+
self.client = client
|
|
2711
|
+
|
|
2712
|
+
def run_search_query(
|
|
2713
|
+
self,
|
|
2714
|
+
vector_schema: str,
|
|
2715
|
+
query_kwargs: Dict[str, Any],
|
|
2716
|
+
integration_name: str = None,
|
|
2717
|
+
) -> Any:
|
|
2718
|
+
"""
|
|
2719
|
+
Run a vector search query.
|
|
2720
|
+
|
|
2721
|
+
Args:
|
|
2722
|
+
vector_schema: The schema to be queried
|
|
2723
|
+
query_kwargs: Query parameters
|
|
2724
|
+
integration_name: The name of the Integration
|
|
2725
|
+
|
|
2726
|
+
Returns:
|
|
2727
|
+
Search results
|
|
2728
|
+
"""
|
|
2729
|
+
if integration_name is None:
|
|
2730
|
+
integration_name = self.client.integration_name
|
|
2731
|
+
|
|
2732
|
+
url = f"{self.client.base_url}/v1/vector-query/search/run"
|
|
2733
|
+
params = {"vector_schema": vector_schema, "integration_name": integration_name}
|
|
2734
|
+
|
|
2735
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2736
|
+
response = self.client.session.post(url, headers=headers, params=params, json=query_kwargs)
|
|
2737
|
+
return self.client._handle_response(response)
|
|
2738
|
+
|
|
2739
|
+
def run_find_similar_query(
|
|
2740
|
+
self,
|
|
2741
|
+
vector_schema: str,
|
|
2742
|
+
query_kwargs: Dict[str, Any],
|
|
2743
|
+
integration_name: str = None,
|
|
2744
|
+
) -> Any:
|
|
2745
|
+
"""
|
|
2746
|
+
Run a vector similarity query.
|
|
2747
|
+
|
|
2748
|
+
Args:
|
|
2749
|
+
vector_schema: The schema to be queried
|
|
2750
|
+
query_kwargs: Query parameters
|
|
2751
|
+
integration_name: The name of the Integration
|
|
2752
|
+
|
|
2753
|
+
Returns:
|
|
2754
|
+
Search results
|
|
2755
|
+
"""
|
|
2756
|
+
if integration_name is None:
|
|
2757
|
+
integration_name = self.client.integration_name
|
|
2758
|
+
url = f"{self.client.base_url}/v1/vector-query/find-similar/run"
|
|
2759
|
+
params = {"vector_schema": vector_schema, "integration_name": integration_name}
|
|
2760
|
+
|
|
2761
|
+
headers = self.client._get_api_key_headers(self.client.api_key)
|
|
2762
|
+
response = self.client.session.post(url, headers=headers, params=params, json=query_kwargs)
|
|
2763
|
+
return self.client._handle_response(response)
|