This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
forked from onyx-dot-app/onyx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move api key to non-ee * finalize previous migration * move token rate limit to non-ee * general cleanup * update * update * finalize * finalize * ensure callable * k
- Loading branch information
Showing
39 changed files
with
362 additions
and
258 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def name_sync_external_doc_permissions_task( | ||
cc_pair_id: int, tenant_id: str | None = None | ||
) -> str: | ||
return f"sync_external_doc_permissions_task__{cc_pair_id}" |
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 |
---|---|---|
|
@@ -493,3 +493,13 @@ | |
# Super Users | ||
SUPER_USERS = json.loads(os.environ.get("SUPER_USERS", '["[email protected]"]')) | ||
SUPER_CLOUD_API_KEY = os.environ.get("SUPER_CLOUD_API_KEY", "api_key") | ||
|
||
|
||
##### | ||
# API Key Configs | ||
##### | ||
# refers to the rounds described here: https://passlib.readthedocs.io/en/stable/lib/passlib.hash.sha256_crypt.html | ||
_API_KEY_HASH_ROUNDS_RAW = os.environ.get("API_KEY_HASH_ROUNDS") | ||
API_KEY_HASH_ROUNDS = ( | ||
int(_API_KEY_HASH_ROUNDS_RAW) if _API_KEY_HASH_ROUNDS_RAW else None | ||
) |
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,111 @@ | ||
from collections.abc import Sequence | ||
|
||
from sqlalchemy import select | ||
from sqlalchemy.orm import Session | ||
|
||
from danswer.configs.constants import TokenRateLimitScope | ||
from danswer.db.models import TokenRateLimit | ||
from danswer.db.models import TokenRateLimit__UserGroup | ||
from danswer.server.token_rate_limits.models import TokenRateLimitArgs | ||
|
||
|
||
def fetch_all_user_token_rate_limits( | ||
db_session: Session, | ||
enabled_only: bool = False, | ||
ordered: bool = True, | ||
) -> Sequence[TokenRateLimit]: | ||
query = select(TokenRateLimit).where( | ||
TokenRateLimit.scope == TokenRateLimitScope.USER | ||
) | ||
|
||
if enabled_only: | ||
query = query.where(TokenRateLimit.enabled.is_(True)) | ||
|
||
if ordered: | ||
query = query.order_by(TokenRateLimit.created_at.desc()) | ||
|
||
return db_session.scalars(query).all() | ||
|
||
|
||
def fetch_all_global_token_rate_limits( | ||
db_session: Session, | ||
enabled_only: bool = False, | ||
ordered: bool = True, | ||
) -> Sequence[TokenRateLimit]: | ||
query = select(TokenRateLimit).where( | ||
TokenRateLimit.scope == TokenRateLimitScope.GLOBAL | ||
) | ||
|
||
if enabled_only: | ||
query = query.where(TokenRateLimit.enabled.is_(True)) | ||
|
||
if ordered: | ||
query = query.order_by(TokenRateLimit.created_at.desc()) | ||
|
||
token_rate_limits = db_session.scalars(query).all() | ||
return token_rate_limits | ||
|
||
|
||
def insert_user_token_rate_limit( | ||
db_session: Session, | ||
token_rate_limit_settings: TokenRateLimitArgs, | ||
) -> TokenRateLimit: | ||
token_limit = TokenRateLimit( | ||
enabled=token_rate_limit_settings.enabled, | ||
token_budget=token_rate_limit_settings.token_budget, | ||
period_hours=token_rate_limit_settings.period_hours, | ||
scope=TokenRateLimitScope.USER, | ||
) | ||
db_session.add(token_limit) | ||
db_session.commit() | ||
|
||
return token_limit | ||
|
||
|
||
def insert_global_token_rate_limit( | ||
db_session: Session, | ||
token_rate_limit_settings: TokenRateLimitArgs, | ||
) -> TokenRateLimit: | ||
token_limit = TokenRateLimit( | ||
enabled=token_rate_limit_settings.enabled, | ||
token_budget=token_rate_limit_settings.token_budget, | ||
period_hours=token_rate_limit_settings.period_hours, | ||
scope=TokenRateLimitScope.GLOBAL, | ||
) | ||
db_session.add(token_limit) | ||
db_session.commit() | ||
|
||
return token_limit | ||
|
||
|
||
def update_token_rate_limit( | ||
db_session: Session, | ||
token_rate_limit_id: int, | ||
token_rate_limit_settings: TokenRateLimitArgs, | ||
) -> TokenRateLimit: | ||
token_limit = db_session.get(TokenRateLimit, token_rate_limit_id) | ||
if token_limit is None: | ||
raise ValueError(f"TokenRateLimit with id '{token_rate_limit_id}' not found") | ||
|
||
token_limit.enabled = token_rate_limit_settings.enabled | ||
token_limit.token_budget = token_rate_limit_settings.token_budget | ||
token_limit.period_hours = token_rate_limit_settings.period_hours | ||
db_session.commit() | ||
|
||
return token_limit | ||
|
||
|
||
def delete_token_rate_limit( | ||
db_session: Session, | ||
token_rate_limit_id: int, | ||
) -> None: | ||
token_limit = db_session.get(TokenRateLimit, token_rate_limit_id) | ||
if token_limit is None: | ||
raise ValueError(f"TokenRateLimit with id '{token_rate_limit_id}' not found") | ||
|
||
db_session.query(TokenRateLimit__UserGroup).filter( | ||
TokenRateLimit__UserGroup.rate_limit_id == token_rate_limit_id | ||
).delete() | ||
|
||
db_session.delete(token_limit) | ||
db_session.commit() |
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
File renamed without changes.
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.