diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 34c6374..de5ea37 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -45,6 +45,8 @@ const fetchSettings = async () => { } } +const showAd = computed(() => !isMobile.value && settings.value.ad_client); + onMounted(async () => { await fetchSettings(); if (!isMobile.value && settings.value.ad_client) { @@ -59,14 +61,14 @@ onMounted(async () => { - - -
+ + +
- +
@@ -98,7 +102,7 @@ onMounted(async () => {
-
+
diff --git a/src/chatgpt_router.py b/src/chatgpt_router.py index adf0c63..fbd6f3b 100644 --- a/src/chatgpt_router.py +++ b/src/chatgpt_router.py @@ -35,14 +35,15 @@ async def divination( real_ip = get_real_ipaddr(request) # rate limit when not login - if not user: - max_reqs, time_window_seconds = settings.rate_limit - check_rate_limit(real_ip, time_window_seconds, max_reqs) - else: - max_reqs, time_window_seconds = settings.user_rate_limit - check_rate_limit( - f"{user.login_type}:{user.user_name}", time_window_seconds, max_reqs - ) + if settings.enable_rate_limit: + if not user: + max_reqs, time_window_seconds = settings.rate_limit + check_rate_limit(real_ip, time_window_seconds, max_reqs) + else: + max_reqs, time_window_seconds = settings.user_rate_limit + check_rate_limit( + f"{user.login_type}:{user.user_name}", time_window_seconds, max_reqs + ) _logger.info( f"Request from {real_ip}, " diff --git a/src/config.py b/src/config.py index dd071d7..e33679f 100644 --- a/src/config.py +++ b/src/config.py @@ -11,6 +11,7 @@ class Settings(BaseSettings): api_key: str = Field(default="sk-xxx", exclude=True) api_base: str = "https://api.openai.com/v1" model: str = "gpt-3.5-turbo" + enable_rate_limit: bool = True # rate limit xxx request per xx seconds rate_limit: Tuple[int, int] = (60, 60 * 60) user_rate_limit: Tuple[int, int] = (600, 60 * 60) diff --git a/src/models.py b/src/models.py index 9fbef89..6cc6fe4 100644 --- a/src/models.py +++ b/src/models.py @@ -9,6 +9,8 @@ class SettingsInfo(BaseModel): user_rate_limit: str ad_client: str = "" ad_slot: str = "" + enable_login: bool = False + enable_rate_limit: bool = False class OauthBody(BaseModel): diff --git a/src/user_router.py b/src/user_router.py index 4bdb8d5..3aa9576 100644 --- a/src/user_router.py +++ b/src/user_router.py @@ -32,6 +32,8 @@ async def info(user: Optional[User] = Depends(get_user)): ad_slot=settings.ad_slot, rate_limit=settings.get_human_rate_limit(), user_rate_limit=settings.get_human_user_rate_limit(), + enable_login=bool(settings.github_client_id), + enable_rate_limit=settings.enable_rate_limit )