Skip to content

Commit 4224bc1

Browse files
feat: add ecs jit sdk
1 parent 594eda0 commit 4224bc1

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/uipath/platform/context_grounding/_context_grounding_service.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import uuid
12
from pathlib import Path
23
from typing import Annotated, Any, Dict, List, Optional, Tuple, Union
34

@@ -33,11 +34,13 @@
3334
)
3435
from .context_grounding_index import ContextGroundingIndex
3536
from .context_grounding_payloads import (
37+
AttachmentsDataSource,
3638
BucketDataSource,
3739
BucketSourceConfig,
3840
ConfluenceDataSource,
3941
ConfluenceSourceConfig,
4042
CreateIndexPayload,
43+
CreateJitIndexPayload,
4144
DropboxDataSource,
4245
DropboxSourceConfig,
4346
GoogleDriveDataSource,
@@ -398,6 +401,32 @@ def create_index(
398401

399402
return ContextGroundingIndex.model_validate(response.json())
400403

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+
401430
@resource_override(resource_type="index")
402431
@traced(name="contextgrounding_create_index", run_type="uipath")
403432
async def create_index_async(
@@ -1197,6 +1226,41 @@ def _create_spec(
11971226
},
11981227
)
11991228

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+
12001264
def _build_data_source(self, source: SourceConfig) -> Dict[str, Any]:
12011265
"""Build data source configuration from typed source config.
12021266

src/uipath/platform/context_grounding/context_grounding_payloads.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Payload models for context grounding index creation and configuration."""
22

33
import re
4+
import uuid
45
from typing import Any, Dict, Literal, Optional, Union
56

67
from pydantic import BaseModel, ConfigDict, Field, model_validator
@@ -82,6 +83,10 @@ class ConfluenceDataSource(DataSourceBase):
8283
space_id: str = Field(alias="spaceId", description="Space ID")
8384

8485

86+
class AttachmentsDataSource(BaseModel):
87+
attachments: list[uuid.UUID] = Field(description="List of attachment ids")
88+
89+
8590
class Indexer(BaseModel):
8691
"""Configuration for periodic indexing of data sources."""
8792

@@ -136,6 +141,17 @@ class CreateIndexPayload(BaseModel):
136141
model_config = ConfigDict(populate_by_name=True)
137142

138143

144+
class CreateJitIndexPayload(BaseModel):
145+
""" """
146+
147+
usage: str = Field(description="Index usage")
148+
data_source: Dict[str, Any] = Field(
149+
alias="dataSource", description="Data source configuration"
150+
)
151+
152+
model_config = ConfigDict(populate_by_name=True)
153+
154+
139155
# user-facing source configuration models
140156
class BaseSourceConfig(BaseModel):
141157
"""Base configuration for all source types."""

0 commit comments

Comments
 (0)