-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
184 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Dict, Optional | ||
from pydantic import BaseModel | ||
|
||
from .base import Provider, ProviderConfig | ||
|
||
|
||
class RoleLimits(BaseModel): | ||
max_files: Optional[int] = None | ||
max_chunks: Optional[int] = None | ||
max_queries: Optional[int] = None | ||
max_queries_window: Optional[int] = None | ||
|
||
|
||
class UserManagementConfig(ProviderConfig): | ||
default_role: str = "default" | ||
roles: Dict[str, RoleLimits] = { | ||
"default": RoleLimits(), | ||
"basic": RoleLimits( | ||
max_files=1000, | ||
max_chunks=10000, | ||
max_queries=1000, | ||
max_queries_window=1440, | ||
), | ||
} | ||
|
||
@property | ||
def supported_providers(self) -> list[str]: | ||
return ["r2r"] | ||
|
||
def validate_config(self) -> None: | ||
if not self.default_role in self.roles: | ||
raise ValueError( | ||
f"Default role '{self.default_role}' not found in roles configuration" | ||
) | ||
|
||
def get_role_limits(self, role: str) -> RoleLimits: | ||
if role not in self.roles: | ||
return self.roles[self.default_role] | ||
return self.roles[role] | ||
|
||
|
||
class UserManagementProvider(Provider, ABC): | ||
def __init__(self, config: UserManagementConfig): | ||
if not isinstance(config, UserManagementConfig): | ||
raise ValueError( | ||
"UserManagementProvider must be initialized with a UserManagementConfig" | ||
) | ||
print(f"UserManagementProvider config: {config}") | ||
super().__init__(config) | ||
self.config: UserManagementConfig = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.