-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add system resources resolution support #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| from pathlib import Path | ||
| from typing import Annotated, Any, Dict, List, Optional, Tuple, Union | ||
| from typing import Annotated, Any, Dict, List, Optional, Tuple, Union, cast | ||
|
|
||
| import httpx | ||
| from pydantic import Field, TypeAdapter | ||
|
|
||
| from ..._utils import Endpoint, RequestSpec, header_folder, resource_override | ||
| from ..._utils._bindings import ( | ||
| GenericResourceOverwrite, | ||
| ResourceOverwrite, | ||
| SystemResourceOverwrite, | ||
| ) | ||
| from ..._utils._ssl_context import get_httpx_client_kwargs | ||
| from ..._utils.constants import ( | ||
| LLMV4_REQUEST, | ||
|
|
@@ -964,7 +969,16 @@ async def start_deep_rag_async( | |
|
|
||
| return DeepRagCreationResponse.model_validate(response.json()) | ||
|
|
||
| @resource_override(resource_type="index") | ||
| @resource_override( | ||
| resource_type="index", | ||
| identifiers_resolver_callable=lambda overwrite: cast( | ||
| dict[type[ResourceOverwrite], tuple[str, str]], | ||
| { | ||
| GenericResourceOverwrite: ("name", "folder_path"), | ||
| SystemResourceOverwrite: ("name", "folder_key"), | ||
| }, | ||
| ).get(type(overwrite), ("name", "folder_path")), | ||
| ) | ||
radu-mocanu marked this conversation as resolved.
Show resolved
Hide resolved
radu-mocanu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @traced(name="contextgrounding_search", run_type="uipath") | ||
| def search( | ||
| self, | ||
|
|
@@ -990,10 +1004,6 @@ def search( | |
| List[ContextGroundingQueryResponse]: A list of search results, each containing | ||
| relevant contextual information and metadata. | ||
| """ | ||
| index = self.retrieve(name, folder_key=folder_key, folder_path=folder_path) | ||
| if index and index.in_progress_ingestion(): | ||
| raise IngestionInProgressException(index_name=name) | ||
|
|
||
| spec = self._search_spec( | ||
| name, | ||
| query, | ||
|
|
@@ -1013,7 +1023,16 @@ def search( | |
| response.json() | ||
| ) | ||
|
|
||
| @resource_override(resource_type="index") | ||
| @resource_override( | ||
| resource_type="index", | ||
| identifiers_resolver_callable=lambda overwrite: cast( | ||
| dict[type[ResourceOverwrite], tuple[str, str]], | ||
| { | ||
| GenericResourceOverwrite: ("name", "folder_path"), | ||
| SystemResourceOverwrite: ("name", "folder_key"), | ||
| }, | ||
| ).get(type(overwrite), ("name", "folder_path")), | ||
| ) | ||
| @traced(name="contextgrounding_search", run_type="uipath") | ||
| async def search_async( | ||
| self, | ||
|
|
@@ -1039,13 +1058,6 @@ async def search_async( | |
| List[ContextGroundingQueryResponse]: A list of search results, each containing | ||
| relevant contextual information and metadata. | ||
| """ | ||
| index = self.retrieve( | ||
| name, | ||
| folder_key=folder_key, | ||
| folder_path=folder_path, | ||
| ) | ||
| if index and index.in_progress_ingestion(): | ||
| raise IngestionInProgressException(index_name=name) | ||
| spec = self._search_spec( | ||
| name, | ||
| query, | ||
|
|
@@ -1191,6 +1203,60 @@ async def delete_index_async( | |
| headers=spec.headers, | ||
| ) | ||
|
|
||
| async def _resolve_system_index_async( | ||
| self, | ||
| name: str, | ||
| **kwargs, | ||
| ) -> SystemResourceOverwrite | None: | ||
| """Asynchronously retrieve context grounding system index by its name. | ||
| Args: | ||
| name (str): The name of the context index to retrieve. | ||
| Returns: | ||
| SystemResourceOverwrite: The index name and folder key, if found. | ||
| """ | ||
| spec = self._retrieve_system_index_spec( | ||
| name, | ||
| ) | ||
|
|
||
| response = ( | ||
| await self.request_async( | ||
| spec.method, | ||
| spec.endpoint, | ||
| params=spec.params, | ||
| headers=spec.headers, | ||
| ) | ||
| ).json() | ||
| try: | ||
| context_grounding_index = next( | ||
| ContextGroundingIndex.model_validate(item) | ||
| for item in response["value"] | ||
| if item["name"] == name | ||
| ) | ||
| except StopIteration: | ||
| return None | ||
|
|
||
| assert context_grounding_index.name is not None | ||
| assert context_grounding_index.folder_key is not None | ||
radu-mocanu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return SystemResourceOverwrite( | ||
| resource_type="index", | ||
| name=context_grounding_index.name, | ||
| folder_key=context_grounding_index.folder_key, | ||
| ) | ||
radu-mocanu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def _retrieve_system_index_spec( | ||
| self, | ||
| name: str, | ||
| ) -> RequestSpec: | ||
| return RequestSpec( | ||
| method="GET", | ||
| endpoint=Endpoint("/ecs_/v2/indexes/AllSystemIndexes"), | ||
| params={"$filter": f"Name eq '{name}'"}, | ||
|
||
| ) | ||
|
|
||
| def _ingest_spec( | ||
| self, | ||
| key: str, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.