Spaces:
Runtime error
Runtime error
File size: 18,405 Bytes
546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a 667244c 546720a |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LLM Host API Documentation</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet" />
<link href="style.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<nav class="sidebar">
<div class="logo">
🔗 LLM Host API
</div>
<div class="nav-items">
<!-- Navigation items will be populated by JavaScript -->
</div>
</nav>
<main class="content">
<h1>LLM Host API</h1>
<section id="endpoints">
<h2>Endpoints</h2>
<div class="endpoint" id="register">
<h3>1. Register Endpoint</h3>
<p><span class="method">POST</span><span class="endpoint-url">/register</span></p>
<p>This endpoint is used to register the username and password.</p>
<h4>cURL Request:</h4>
<pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/register' \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"password": "testpassword"
}'</code></pre>
<h4>Python Implementation:</h4>
<pre><code class="language-python">
import requests
import json
class RegisterResponse:
"""Class to handle API response"""
def __init__(self, message, user):
self.message = message
self.user = user
@classmethod
def from_json(cls, json_data):
return cls(
message=json_data.get("message"),
user=json_data.get("user")
)
def register(username: str, password: str):
"""Sends a POST request to register a new user."""
url = "https://humblebeeai-llm-host.hf.space/register"
headers = {"Content-Type": "application/json"}
payload = {"username": username, "password": password}
try:
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
return RegisterResponse.from_json(response.json())
else:
raise Exception(f"Failed to register: {response.text}")
except requests.exceptions.RequestException as e:
raise Exception(f"Network error: {e}")
# Example usage
try:
result = register("testuser", "testpassword")
print(f"✅ Registration successful! User: {result.user}, Message: {result.message}")
except Exception as e:
print(f"⚠️ Error: {e}")
</code></pre>
<h4>Response:</h4>
<pre><code class="language-json">{"message":"User registered successfully","user":"bahodir"}</code></pre>
</div>
<div class="endpoint" id="login">
<h3>2. Login Endpoint</h3>
<p><span class="method">POST</span><span class="endpoint-url">/login</span></p>
<p>This endpoint is used to authenticate a user and retrieve an access token.</p>
<h4>cURL Request:</h4>
<pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/login' \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'username=testuser&password=testpassword'</code></pre>
<h4>Python Implementation:</h4>
<pre><code class="language-python">
import requests
class LoginResponse:
"""Class to handle API login response"""
def __init__(self, access_token, refresh_token, token_type):
self.access_token = access_token
self.refresh_token = refresh_token
self.token_type = token_type
@classmethod
def from_json(cls, json_data):
return cls(
access_token=json_data.get("access_token"),
refresh_token=json_data.get("refresh_token"),
token_type=json_data.get("token_type"),
)
def login(username: str, password: str):
"""Sends a POST request to authenticate a user."""
url = "https://humblebeeai-llm-host.hf.space/login"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
payload = {"username": username, "password": password}
try:
response = requests.post(url, data=payload, headers=headers)
if response.status_code == 200:
return LoginResponse.from_json(response.json())
else:
raise Exception(f"Failed to login: {response.text}")
except requests.exceptions.RequestException as e:
raise Exception(f"Network error: {e}")
# Example usage
try:
result = login("testuser", "testpassword")
print(f"✅ Login successful! Access Token: {result.access_token}")
except Exception as e:
print(f"⚠️ Error: {e}")
</code></pre>
<h4>Response:</h4>
<pre><code class="language-json">{ "access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0dXNlciIsImV4cCI6MTczOTE3Nzg5N30.jUfB7vHA4HGrpDiI08cpKGR7s3DOVrchhpf5yBz0hCc",
"token_type":"bearer",
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0dXNlciIsImV4cCI6MTczOTc4MDg5N30.L9_5hGR_lUskUINccE51fOA1-8NOgmQ2bjBK3iMS-K8"}</code></pre>
</div>
<div class="endpoint" id="refresh">
<h3>3. Refresh Token Endpoint</h3>
<p><span class="method">POST</span><span class="endpoint-url">/refresh</span></p>
<p>This endpoint is used to refresh the access token using a valid refresh token.</p>
<h4>cURL Request:</h4>
<pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/refresh' \
-H "Content-Type: application/json" \
-d '{"refresh_token": "your-refresh-token"}'</code></pre>
<h4>Python Implementation:</h4>
<pre><code class="language-python">
import requests
import json
class RefreshResponse:
"""Class to handle API refresh response"""
def __init__(self, access_token, refresh_token, token_type):
self.access_token = access_token
self.refresh_token = refresh_token
self.token_type = token_type
@classmethod
def from_json(cls, json_data):
return cls(
access_token=json_data.get("access_token"),
refresh_token=json_data.get("refresh_token"),
token_type=json_data.get("token_type"),
)
def refresh_token(refresh_token: str):
"""Sends a POST request to refresh the access token."""
url = "https://humblebeeai-llm-host.hf.space/refresh"
headers = {"Content-Type": "application/json"}
payload = {"refresh_token": refresh_token}
try:
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
return RefreshResponse.from_json(response.json())
else:
raise Exception(f"Failed to refresh token: {response.text}")
except requests.exceptions.RequestException as e:
raise Exception(f"Network error: {e}")
# Example usage
try:
result = refresh_token("your-refresh-token")
print(f"✅ Token refreshed! New Access Token: {result.access_token}")
except Exception as e:
print(f"⚠️ Error: {e}")
</code></pre>
<h4>Response:</h4>
<pre><code class="language-json">{
"access_token": "new-access-token",
"refresh_token": "your-refresh-token",
"token_type": "bearer"
}</code></pre>
</div>
<div class="endpoint" id="search">
<h3>4. Search Endpoint</h3>
<p><span class="method">POST</span><span class="endpoint-url">/search</span></p>
<p>This endpoint is used to send a search query and retrieve results. It requires a valid access token.</p>
<h4>cURL Request:</h4>
<pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/search' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-access-token" \
-d '{"query": "test query"}'</code></pre>
<h4>Python Implementation:</h4>
<pre><code class="language-python">
import requests
import json
class SearchResult:
"""Class to handle search results"""
def __init__(self, text, similarity, model_type):
self.text = text
self.similarity = similarity
self.model_type = model_type
@classmethod
def from_json(cls, json_data):
return cls(
text=json_data.get("text"),
similarity=json_data.get("similarity"),
model_type=json_data.get("model_type"),
)
def search(query: str, access_token: str):
"""Sends a search query and retrieves results."""
url = "https://humblebeeai-llm-host.hf.space/search"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}"
}
payload = {"query": query}
try:
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
json_list = response.json()
return [SearchResult.from_json(item) for item in json_list]
else:
raise Exception(f"Search failed: {response.text}")
except requests.exceptions.RequestException as e:
raise Exception(f"Network error: {e}")
# Example usage
try:
results = search("test query", "your-access-token")
for result in results:
print(f"✅ Found: {result.text} (Similarity: {result.similarity}, Model: {result.model_type})")
except Exception as e:
print(f"⚠️ Error: {e}")
</code></pre>
<h4>Response:</h4>
<pre><code class="language-json">
response based on query
</code></pre>
</div>
</section>
<section id="workflow">
<h2>Workflow Example</h2>
<p>Here's a complete workflow demonstrating how to use the API:</p>
<h3>cURL Implementation</h3>
<div class="endpoint">
<h3>Step 1: Login</h3>
<pre><code class="language-bash">curl -X POST https://humblebeeai-llm-host.hf.space/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'username=user123&password=password123'</code></pre>
</div>
<div class="endpoint">
<h3>Step 2: Search</h3>
<pre><code class="language-bash">curl -X POST https://humblebeeai-llm-host.hf.space/search \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-access-token" \
-d '{"query": "test query"}'</code></pre>
</div>
<div class="endpoint">
<h3>Step 3: Refresh Token</h3>
<pre><code class="language-bash">curl -X POST https://humblebeeai-llm-host.hf.space/refresh \
-H "Content-Type: application/json" \
-d '{"refresh_token": "your-refresh-token"}'</code></pre>
</div>
<h3>Python Implementation</h3>
<div class="endpoint">
<h4>Complete Python Example</h4>
<pre><code class="language-python">
import requests
import json
API_BASE_URL = "https://humblebeeai-llm-host.hf.space"
class APIClient:
"""Handles the full API workflow"""
def __init__(self):
self.access_token = None
self.refresh_token = None
def login(self, username: str, password: str):
"""Authenticates the user and retrieves tokens"""
url = f"{API_BASE_URL}/login"
payload = {"username": username, "password": password}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=payload, headers=headers)
if response.status_code == 200:
tokens = response.json()
self.access_token = tokens.get("access_token")
self.refresh_token = tokens.get("refresh_token")
print(f"✅ Login successful! Token: {self.access_token}")
else:
raise Exception(f"⚠️ Login failed: {response.text}")
def search(self, query: str):
"""Performs a search query"""
url = f"{API_BASE_URL}/search"
payload = {"query": query}
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {self.access_token}",
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
results = response.json()
print("✅ Search results:", results)
return results
else:
raise Exception(f"⚠️ Search failed: {response.text}")
def save_data(self, items: list):
"""Saves retrieved data"""
url = f"{API_BASE_URL}/save"
payload = {"items": items}
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {self.access_token}",
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
print("✅ Data saved successfully!")
else:
raise Exception(f"⚠️ Failed to save data: {response.text}")
def refresh_token(self):
"""Refreshes access token"""
url = f"{API_BASE_URL}/refresh"
payload = {"refresh_token": self.refresh_token}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
tokens = response.json()
self.access_token = tokens.get("access_token")
print(f"✅ Token refreshed! New Token: {self.access_token}")
else:
raise Exception(f"⚠️ Token refresh failed: {response.text}")
# Example Usage
client = APIClient()
try:
# Step 1: Login
client.login("user123", "password123")
# Step 2: Perform Search
search_results = client.search("test query")
# Step 3: Save Data (assuming we got some results)
if search_results:
save_items = [
{
"user_type": "user",
"username": "user123",
"query": "test query",
"retrieved_text": search_results[0]["text"],
"model_type": search_results[0]["model_type"],
"reaction": "positive",
}
]
client.save_data(save_items)
# Step 4: Refresh Token
client.refresh_token()
except Exception as e:
print(f"⚠️ Error: {e}")
</code></pre>
</div>
<h4>Response:</h4>
<pre><code class="language-json">{
"access_token": "your-access-token",
"refresh_token": "your-refresh-token",
"token_type": "bearer",
}</code></pre>
</section>
</main>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-bash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-json.min.js"></script>
<script src="script.js"></script>
</body>
</html> |