|
| 1 | +import uuid |
1 | 2 | from pathlib import Path |
2 | 3 | from typing import Annotated, Any, Dict, List, Optional, Tuple, Union |
3 | 4 |
|
|
33 | 34 | ) |
34 | 35 | from .context_grounding_index import ContextGroundingIndex |
35 | 36 | from .context_grounding_payloads import ( |
| 37 | + AttachmentsDataSource, |
36 | 38 | BucketDataSource, |
37 | 39 | BucketSourceConfig, |
38 | 40 | ConfluenceDataSource, |
39 | 41 | ConfluenceSourceConfig, |
40 | 42 | CreateIndexPayload, |
| 43 | + CreateJitIndexPayload, |
41 | 44 | DropboxDataSource, |
42 | 45 | DropboxSourceConfig, |
43 | 46 | GoogleDriveDataSource, |
@@ -398,6 +401,32 @@ def create_index( |
398 | 401 |
|
399 | 402 | return ContextGroundingIndex.model_validate(response.json()) |
400 | 403 |
|
| 404 | + @resource_override(resource_type="index") |
| 405 | + @traced(name="contextgrounding_create_jit_index", run_type="uipath") |
| 406 | + def create_jit_index( |
| 407 | + self, |
| 408 | + usage: str, |
| 409 | + attachments: list[uuid.UUID], |
| 410 | + folder_key: Optional[str] = None, |
| 411 | + folder_path: Optional[str] = None, |
| 412 | + ) -> ContextGroundingIndex: |
| 413 | + """Create a new context jit grounding index.""" |
| 414 | + spec = self._create_jit_spec( |
| 415 | + usage, |
| 416 | + attachments, |
| 417 | + folder_path=folder_path, |
| 418 | + folder_key=folder_key, |
| 419 | + ) |
| 420 | + |
| 421 | + response = self.request( |
| 422 | + spec.method, |
| 423 | + spec.endpoint, |
| 424 | + json=spec.json, |
| 425 | + headers=spec.headers, |
| 426 | + ) |
| 427 | + |
| 428 | + return ContextGroundingIndex.model_validate(response.json()) |
| 429 | + |
401 | 430 | @resource_override(resource_type="index") |
402 | 431 | @traced(name="contextgrounding_create_index", run_type="uipath") |
403 | 432 | async def create_index_async( |
@@ -1197,6 +1226,41 @@ def _create_spec( |
1197 | 1226 | }, |
1198 | 1227 | ) |
1199 | 1228 |
|
| 1229 | + def _create_jit_spec( |
| 1230 | + self, |
| 1231 | + usage: str, |
| 1232 | + attachments: list[uuid.UUID] = None, |
| 1233 | + folder_key: Optional[str] = None, |
| 1234 | + folder_path: Optional[str] = None, |
| 1235 | + ) -> RequestSpec: |
| 1236 | + """Create request spec for index creation.""" |
| 1237 | + folder_key = self._resolve_folder_key(folder_key, folder_path) |
| 1238 | + |
| 1239 | + data_source_dict = self._build_jit_data_source(attachments) |
| 1240 | + |
| 1241 | + payload = CreateJitIndexPayload( |
| 1242 | + usage=usage, |
| 1243 | + data_source=data_source_dict, |
| 1244 | + ) |
| 1245 | + |
| 1246 | + return RequestSpec( |
| 1247 | + method="POST", |
| 1248 | + endpoint=Endpoint("/ecs_/v2/indexes/createephemeral"), |
| 1249 | + json=payload.model_dump(by_alias=True, exclude_none=True), |
| 1250 | + headers={ |
| 1251 | + **header_folder(folder_key, None), |
| 1252 | + }, |
| 1253 | + ) |
| 1254 | + |
| 1255 | + def _build_jit_data_source(self, attachments: list[uuid.UUID]) -> Dict[str, Any]: |
| 1256 | + data_source: AttachmentsDataSource |
| 1257 | + data_source = AttachmentsDataSource(attachments=attachments) |
| 1258 | + return data_source.model_dump( |
| 1259 | + by_alias=True, |
| 1260 | + exclude_none=True, |
| 1261 | + mode="json", |
| 1262 | + ) |
| 1263 | + |
1200 | 1264 | def _build_data_source(self, source: SourceConfig) -> Dict[str, Any]: |
1201 | 1265 | """Build data source configuration from typed source config. |
1202 | 1266 |
|
|
0 commit comments