Spaces:
Running
Running
Refactor settings.py: Simplify API configuration for free tier and remove account type checks
Browse files- config/settings.py +9 -40
config/settings.py
CHANGED
|
@@ -42,12 +42,13 @@ if not HF_TOKEN:
|
|
| 42 |
|
| 43 |
# API Configuration
|
| 44 |
API_CONFIG = {
|
| 45 |
-
"inference_endpoint":
|
| 46 |
"token": HF_TOKEN,
|
| 47 |
-
"is_paid_tier":
|
| 48 |
"timeout": 15,
|
|
|
|
| 49 |
"headers": {
|
| 50 |
-
"X-Use-Cache": "
|
| 51 |
"Content-Type": "application/json",
|
| 52 |
"Authorization": f"Bearer {HF_TOKEN}"
|
| 53 |
}
|
|
@@ -55,47 +56,15 @@ API_CONFIG = {
|
|
| 55 |
|
| 56 |
def check_account_type():
|
| 57 |
"""
|
| 58 |
-
|
| 59 |
Returns:
|
| 60 |
tuple: (is_pro: bool, account_type: str)
|
| 61 |
"""
|
| 62 |
-
|
| 63 |
-
api = HfApi(token=HF_TOKEN)
|
| 64 |
-
user_info = api.whoami()
|
| 65 |
-
account_type = user_info.get("type", "free")
|
| 66 |
-
plan = user_info.get("plan", "free")
|
| 67 |
-
|
| 68 |
-
is_pro = any([
|
| 69 |
-
plan.lower() == "pro",
|
| 70 |
-
account_type.lower() == "pro",
|
| 71 |
-
"pro" in str(user_info).lower()
|
| 72 |
-
])
|
| 73 |
-
|
| 74 |
-
return is_pro, account_type
|
| 75 |
-
except Exception as e:
|
| 76 |
-
logger.warning(f"Failed to check account type: {e}")
|
| 77 |
-
return False, "free"
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
IS_PRO_ACCOUNT, ACCOUNT_TYPE =
|
| 81 |
-
|
| 82 |
-
# Adjust API configuration based on account type
|
| 83 |
-
API_CONFIG.update({
|
| 84 |
-
"is_paid_tier": IS_PRO_ACCOUNT,
|
| 85 |
-
"timeout": 30 if IS_PRO_ACCOUNT else 15,
|
| 86 |
-
"max_retries": 3 if IS_PRO_ACCOUNT else 1
|
| 87 |
-
})
|
| 88 |
-
|
| 89 |
-
# Define available models based on account type
|
| 90 |
-
PRO_ONLY_MODELS = ["llama-7b", "mistral-7b"]
|
| 91 |
-
FREE_MODELS = ["zephyr-7b"]
|
| 92 |
-
|
| 93 |
-
# Filter available models based on account type
|
| 94 |
-
if not IS_PRO_ACCOUNT:
|
| 95 |
-
# Remove pro-only models from MODELS dict
|
| 96 |
-
MODELS = {k: v for k, v in MODELS.items() if k not in PRO_ONLY_MODELS}
|
| 97 |
-
# Set default model to a free one
|
| 98 |
-
DEFAULT_MODEL = "zephyr-7b"
|
| 99 |
|
| 100 |
# Dataset configuration
|
| 101 |
DATASET_ID = "Rulga/status-law-knowledge-base"
|
|
|
|
| 42 |
|
| 43 |
# API Configuration
|
| 44 |
API_CONFIG = {
|
| 45 |
+
"inference_endpoint": "https://api-inference.huggingface.co",
|
| 46 |
"token": HF_TOKEN,
|
| 47 |
+
"is_paid_tier": False, # Принудительно устанавливаем бесплатный режим
|
| 48 |
"timeout": 15,
|
| 49 |
+
"max_retries": 1,
|
| 50 |
"headers": {
|
| 51 |
+
"X-Use-Cache": "true", # Включаем кэширование для бесплатного тарифа
|
| 52 |
"Content-Type": "application/json",
|
| 53 |
"Authorization": f"Bearer {HF_TOKEN}"
|
| 54 |
}
|
|
|
|
| 56 |
|
| 57 |
def check_account_type():
|
| 58 |
"""
|
| 59 |
+
Simplified account check for free tier
|
| 60 |
Returns:
|
| 61 |
tuple: (is_pro: bool, account_type: str)
|
| 62 |
"""
|
| 63 |
+
return False, "free"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
# Устанавливаем базовые настройки для free tier
|
| 66 |
+
IS_PRO_ACCOUNT, ACCOUNT_TYPE = False, "free"
|
| 67 |
+
DEFAULT_MODEL = "zephyr-7b" # Устанавливаем дефолтную бесплатную модель
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# Dataset configuration
|
| 70 |
DATASET_ID = "Rulga/status-law-knowledge-base"
|