-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
43 lines (31 loc) · 1.22 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import logging
from typing import Tuple
from pydantic import Field
from pydantic_settings import BaseSettings
_logger = logging.getLogger(__name__)
class Settings(BaseSettings):
api_key: str = Field(default="sk-xxx", exclude=True)
api_base: str = "https://api.xiaoai.plus/v1"
model: str = "gpt-3.5-turbo"
enable_rate_limit: bool = False
# rate limit xxx request per xx seconds
rate_limit: Tuple[int, int] = (60, 60 * 60)
user_rate_limit: Tuple[int, int] = (600, 60 * 60)
github_client_id: str = ""
github_client_secret: str = Field(default="", exclude=True)
jwt_secret: str = Field(default="secret", exclude=True)
ad_client: str = ""
ad_slot: str = ""
## Database
database_url: str = ""
def get_human_rate_limit(self) -> str:
max_reqs, time_window_seconds = self.rate_limit
# convert to human readable format
return f"{max_reqs}req/{time_window_seconds}seconds"
def get_human_user_rate_limit(self) -> str:
max_reqs, time_window_seconds = self.user_rate_limit
# convert to human readable format
return f"{max_reqs}req/{time_window_seconds}seconds"
class Config:
env_file = ".env"
settings = Settings()