Skip to content

Commit

Permalink
feat: add get_permission_info to resource reader mixin + readers (run…
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanuelCampos authored Nov 14, 2024
1 parent c31f7c0 commit 023697e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
16 changes: 16 additions & 0 deletions llama-index-core/llama_index/core/readers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ async def alist_resources(self, *args: Any, **kwargs: Any) -> List[str]:
"""
return self.list_resources(*args, **kwargs)

def get_permission_info(self, resource_id: str, *args: Any, **kwargs: Any) -> Dict:
"""
Get a dictionary of information about the permissions of a specific resource.
"""
raise NotImplementedError(
f"{self.__class__.__name__} does not provide get_permission_info method currently"
)

async def aget_permission_info(
self, resource_id: str, *args: Any, **kwargs: Any
) -> Dict:
"""
Get a dictionary of information about the permissions of a specific resource asynchronously.
"""
return self.get_permission_info(resource_id, *args, **kwargs)

@abstractmethod
def get_resource_info(self, resource_id: str, *args: Any, **kwargs: Any) -> Dict:
"""
Expand Down
2 changes: 1 addition & 1 deletion llama-index-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ name = "llama-index-core"
packages = [{include = "llama_index"}]
readme = "README.md"
repository = "https://github.com/run-llama/llama_index"
version = "0.11.23"
version = "0.11.24"

[tool.poetry.dependencies]
SQLAlchemy = {extras = ["asyncio"], version = ">=1.4.49"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,21 @@ def load_data(
f"An error occurred while loading the data: {e}", exc_info=True
)

def get_permission_info(self, resource_id: str, *args: Any, **kwargs: Any) -> Dict:
payloads = self._get_downloaded_files_metadata(
file_paths=[resource_id], *args, **kwargs
)

item = next(
payload.resource_info
for payload in payloads
if payload.resource_info["file_path"] == resource_id
)

access_token = self._authenticate_with_msal()

return self._get_permissions_info(item, self.userprincipalname, access_token)

def _get_permissions_info(
self, item: Dict[str, Any], userprincipalname: str, access_token: str
) -> Dict[str, Any]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ license = "MIT"
maintainers = ["godwin3737"]
name = "llama-index-readers-microsoft-onedrive"
readme = "README.md"
version = "0.2.2"
version = "0.2.3"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,27 @@ def _get_item_from_path(self, input_file: Path) -> Dict[str, Any]:

return response.json()

def get_permission_info(self, resource_id: str, **kwargs) -> Dict:
"""
Get a dictionary of information about the permissions of a specific resource.
"""
try:
item = self._get_item_from_path(Path(resource_id))
return self._get_permissions_info(item)
except Exception as exp:
logger.error(
"An error occurred while fetching file information from SharePoint: %s",
exp,
)
raise

def get_resource_info(self, resource_id: str, **kwargs) -> Dict:
"""
Retrieves metadata for a specified file in SharePoint without downloading it.
Args:
input_file (Path): The path of the file in SharePoint. The path should include
the SharePoint site name and the folder path. e.g. "site_name/folder_path/file_name".
the SharePoint site name and the folder path. e.g. "site_name/folder_path/file_name".
"""
try:
item = self._get_item_from_path(Path(resource_id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ license = "MIT"
maintainers = ["arun-soliton"]
name = "llama-index-readers-microsoft-sharepoint"
readme = "README.md"
version = "0.4.0"
version = "0.4.1"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down

0 comments on commit 023697e

Please sign in to comment.