-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add provider/action filtering and hybrid BM25 + TF-IDF search #37
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
Changes from 1 commit
5244f05
7f9a72a
ed36324
e747ce4
472a35c
fdcea15
9a921e3
49c8eec
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -60,6 +60,7 @@ def __init__( | |||||
| self.api_key: str = api_key_value | ||||||
| self.account_id = account_id | ||||||
| self.base_url = base_url | ||||||
| self._account_ids: list[str] = [] | ||||||
|
|
||||||
| def _parse_parameters(self, parameters: list[dict[str, Any]]) -> dict[str, dict[str, str]]: | ||||||
| """Parse OpenAPI parameters into tool properties | ||||||
|
|
@@ -109,6 +110,119 @@ def _matches_filter(self, tool_name: str, filter_pattern: str | list[str]) -> bo | |||||
|
|
||||||
| return matches_positive and not matches_negative | ||||||
|
|
||||||
| def set_accounts(self, account_ids: list[str]) -> StackOneToolSet: | ||||||
| """Set account IDs for filtering tools | ||||||
|
|
||||||
| Args: | ||||||
| account_ids: List of account IDs to filter tools by | ||||||
|
|
||||||
| Returns: | ||||||
| This toolset instance for chaining | ||||||
| """ | ||||||
| self._account_ids = account_ids | ||||||
| return self | ||||||
|
|
||||||
| def _filter_by_provider(self, tool_name: str, providers: list[str]) -> bool: | ||||||
| """Check if a tool name matches any of the provider filters | ||||||
|
|
||||||
| Args: | ||||||
| tool_name: Name of the tool to check | ||||||
| providers: List of provider names (case-insensitive) | ||||||
|
|
||||||
| Returns: | ||||||
| True if the tool matches any provider, False otherwise | ||||||
| """ | ||||||
| # Extract provider from tool name (assuming format: provider_action) | ||||||
| provider = tool_name.split("_")[0].lower() | ||||||
|
||||||
| provider_set = {p.lower() for p in providers} | ||||||
| return provider in provider_set | ||||||
|
|
||||||
| def _filter_by_action(self, tool_name: str, actions: list[str]) -> bool: | ||||||
| """Check if a tool name matches any of the action patterns | ||||||
|
|
||||||
| Args: | ||||||
| tool_name: Name of the tool to check | ||||||
| actions: List of action patterns (supports glob patterns) | ||||||
|
|
||||||
| Returns: | ||||||
| True if the tool matches any action pattern, False otherwise | ||||||
| """ | ||||||
| return any(fnmatch.fnmatch(tool_name, pattern) for pattern in actions) | ||||||
|
|
||||||
| def fetch_tools( | ||||||
| self, | ||||||
| *, | ||||||
| account_ids: list[str] | None = None, | ||||||
| providers: list[str] | None = None, | ||||||
| actions: list[str] | None = None, | ||||||
| ) -> Tools: | ||||||
| """Fetch tools with optional filtering by account IDs, providers, and actions | ||||||
|
|
||||||
| Args: | ||||||
| account_ids: Optional list of account IDs to filter by. | ||||||
| If not provided, uses accounts set via set_accounts() | ||||||
| providers: Optional list of provider names (e.g., ['hibob', 'bamboohr']). | ||||||
| Case-insensitive matching. | ||||||
| actions: Optional list of action patterns with glob support | ||||||
| (e.g., ['*_list_employees', 'hibob_create_employees']) | ||||||
|
|
||||||
| Returns: | ||||||
| Collection of tools matching the filter criteria | ||||||
|
|
||||||
| Raises: | ||||||
| ToolsetLoadError: If there is an error loading the tools | ||||||
|
|
||||||
| Examples: | ||||||
| # Filter by account IDs | ||||||
| tools = toolset.fetch_tools(account_ids=['123', '456']) | ||||||
|
|
||||||
| # Filter by providers | ||||||
| tools = toolset.fetch_tools(providers=['hibob', 'bamboohr']) | ||||||
|
|
||||||
| # Filter by actions with glob patterns | ||||||
| tools = toolset.fetch_tools(actions=['*_list_employees']) | ||||||
|
|
||||||
| # Combine filters | ||||||
| tools = toolset.fetch_tools( | ||||||
| account_ids=['123'], | ||||||
| providers=['hibob'], | ||||||
| actions=['*_list_*'] | ||||||
| ) | ||||||
|
|
||||||
| # Use set_accounts() for account filtering | ||||||
| toolset.set_accounts(['123', '456']) | ||||||
| tools = toolset.fetch_tools() | ||||||
| """ | ||||||
| try: | ||||||
| # Use account IDs from options, or fall back to instance state | ||||||
| effective_account_ids = account_ids or self._account_ids | ||||||
|
||||||
| effective_account_ids = account_ids or self._account_ids | |
| effective_account_ids = account_ids if account_ids is not None else self._account_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type annotation
Anyis too broad for the__iter__method. It should returnIterator[StackOneTool]for better type safety and IDE support. Addfrom collections.abc import Iteratorto the imports and update the return type.