chore: 添加虚拟环境到仓库
- 添加 backend_service/venv 虚拟环境 - 包含所有Python依赖包 - 注意:虚拟环境约393MB,包含12655个文件
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from abc import abstractmethod
|
||||
from typing import Awaitable, Callable, TypeVar, Any
|
||||
from chromadb.config import Component, System
|
||||
|
||||
T = TypeVar("T", bound=Callable[..., Any])
|
||||
A = TypeVar("A", bound=Awaitable[Any])
|
||||
|
||||
|
||||
class RateLimitEnforcer(Component):
|
||||
"""
|
||||
Rate limit enforcer.
|
||||
|
||||
Implemented as a wrapper around server functions to block requests if rate limits are exceeded.
|
||||
"""
|
||||
|
||||
def __init__(self, system: System) -> None:
|
||||
super().__init__(system)
|
||||
|
||||
@abstractmethod
|
||||
def rate_limit(self, func: T) -> T:
|
||||
pass
|
||||
|
||||
|
||||
class AsyncRateLimitEnforcer(Component):
|
||||
"""
|
||||
Rate limit enforcer.
|
||||
|
||||
Implemented as a wrapper around async functions to block requests if rate limits are exceeded.
|
||||
"""
|
||||
|
||||
def __init__(self, system: System) -> None:
|
||||
super().__init__(system)
|
||||
|
||||
@abstractmethod
|
||||
def rate_limit(self, func: A) -> A:
|
||||
pass
|
||||
@@ -0,0 +1,42 @@
|
||||
from overrides import override
|
||||
from typing import Any, Awaitable, Callable, TypeVar
|
||||
from functools import wraps
|
||||
|
||||
from chromadb.rate_limit import RateLimitEnforcer
|
||||
from chromadb.config import System
|
||||
|
||||
T = TypeVar("T", bound=Callable[..., Any])
|
||||
A = TypeVar("A", bound=Awaitable[Any])
|
||||
|
||||
|
||||
class SimpleRateLimitEnforcer(RateLimitEnforcer):
|
||||
"""
|
||||
A naive implementation of a rate limit enforcer that allows all requests.
|
||||
"""
|
||||
|
||||
def __init__(self, system: System) -> None:
|
||||
super().__init__(system)
|
||||
|
||||
@override
|
||||
def rate_limit(self, func: T) -> T:
|
||||
@wraps(func)
|
||||
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper # type: ignore
|
||||
|
||||
|
||||
class SimpleAsyncRateLimitEnforcer(RateLimitEnforcer):
|
||||
"""
|
||||
A naive implementation of a rate limit enforcer that allows all requests.
|
||||
"""
|
||||
|
||||
def __init__(self, system: System) -> None:
|
||||
super().__init__(system)
|
||||
|
||||
@override
|
||||
def rate_limit(self, func: A) -> A:
|
||||
@wraps(func)
|
||||
async def wrapper(*args: Any, **kwargs: Any) -> Any:
|
||||
return await func(*args, **kwargs)
|
||||
return wrapper # type: ignore
|
||||
Reference in New Issue
Block a user