Spaces:
Running
Running
Refactor API client initialization and add comprehensive API configuration settings
Browse files- app.py +4 -1
- config/settings.py +16 -0
- test_endpoint.py +32 -0
app.py
CHANGED
|
@@ -235,7 +235,10 @@ def initialize_client(model_id=None):
|
|
| 235 |
|
| 236 |
client = InferenceClient(
|
| 237 |
model_id,
|
| 238 |
-
token=
|
|
|
|
|
|
|
|
|
|
| 239 |
)
|
| 240 |
return client
|
| 241 |
|
|
|
|
| 235 |
|
| 236 |
client = InferenceClient(
|
| 237 |
model_id,
|
| 238 |
+
token=API_CONFIG["token"],
|
| 239 |
+
endpoint=API_CONFIG["inference_endpoint"],
|
| 240 |
+
headers=API_CONFIG["headers"],
|
| 241 |
+
timeout=API_CONFIG["timeout"]
|
| 242 |
)
|
| 243 |
return client
|
| 244 |
|
config/settings.py
CHANGED
|
@@ -5,6 +5,18 @@ HF_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
|
| 5 |
if not HF_TOKEN:
|
| 6 |
raise ValueError("HUGGINGFACE_TOKEN not found in environment variables")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Dataset configuration
|
| 9 |
DATASET_ID = "Rulga/status-law-knowledge-base"
|
| 10 |
CHAT_HISTORY_PATH = "chat_history"
|
|
@@ -111,6 +123,10 @@ MODELS = {
|
|
| 111 |
}
|
| 112 |
}
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
# Default model
|
| 115 |
DEFAULT_MODEL = "llama-7b" # Changed from "zephyr-7b" to "llama-7b"
|
| 116 |
ACTIVE_MODEL = MODELS[DEFAULT_MODEL]
|
|
|
|
| 5 |
if not HF_TOKEN:
|
| 6 |
raise ValueError("HUGGINGFACE_TOKEN not found in environment variables")
|
| 7 |
|
| 8 |
+
# API Configuration
|
| 9 |
+
API_CONFIG = {
|
| 10 |
+
"inference_endpoint": os.getenv("HF_INFERENCE_ENDPOINT", "https://api-inference.huggingface.co"),
|
| 11 |
+
"token": HF_TOKEN,
|
| 12 |
+
"is_paid_tier": True, # или False в зависимости от вашего плана
|
| 13 |
+
"timeout": 30,
|
| 14 |
+
"headers": {
|
| 15 |
+
"X-Use-Cache": "false",
|
| 16 |
+
"Content-Type": "application/json"
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
# Dataset configuration
|
| 21 |
DATASET_ID = "Rulga/status-law-knowledge-base"
|
| 22 |
CHAT_HISTORY_PATH = "chat_history"
|
|
|
|
| 123 |
}
|
| 124 |
}
|
| 125 |
|
| 126 |
+
# Update MODELS configuration
|
| 127 |
+
for model in MODELS.values():
|
| 128 |
+
model["endpoint"] = API_CONFIG["inference_endpoint"]
|
| 129 |
+
|
| 130 |
# Default model
|
| 131 |
DEFAULT_MODEL = "llama-7b" # Changed from "zephyr-7b" to "llama-7b"
|
| 132 |
ACTIVE_MODEL = MODELS[DEFAULT_MODEL]
|
test_endpoint.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import HfApi, InferenceClient
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Ваш текущий токен
|
| 5 |
+
token = os.getenv("HUGGINGFACE_TOKEN")
|
| 6 |
+
|
| 7 |
+
# Проверка типа доступа
|
| 8 |
+
api = HfApi(token=token)
|
| 9 |
+
try:
|
| 10 |
+
# Проверяем информацию об аккаунте
|
| 11 |
+
user_info = api.whoami()
|
| 12 |
+
print("Account type:", user_info.get("type"))
|
| 13 |
+
print("Plan:", user_info.get("plan"))
|
| 14 |
+
|
| 15 |
+
# Проверяем доступные эндпоинты
|
| 16 |
+
endpoints = api.list_endpoints()
|
| 17 |
+
print("\nAvailable endpoints:")
|
| 18 |
+
for endpoint in endpoints:
|
| 19 |
+
print(f"- {endpoint.name}: {endpoint.url}")
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"Error checking endpoints: {e}")
|
| 22 |
+
|
| 23 |
+
# Проверяем текущий клиент
|
| 24 |
+
client = InferenceClient(
|
| 25 |
+
"HuggingFaceH4/zephyr-7b-beta", # или ваша текущая модель
|
| 26 |
+
token=token
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Проверяем тип подключения
|
| 30 |
+
print("\nClient information:")
|
| 31 |
+
print("API Base URL:", client.api_url)
|
| 32 |
+
print("Headers:", client.headers)
|