File size: 11,818 Bytes
546720a
 
 
 
 
 
 
9bc18d3
546720a
 
 
 
 
 
 
 
 
 
 
 
667244c
546720a
667244c
 
9f8a30b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
667244c
 
 
9f8a30b
667244c
 
 
 
9f8a30b
667244c
 
9f8a30b
 
 
 
 
7adef4f
9f8a30b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
667244c
9f8a30b
667244c
 
 
 
 
 
 
 
9f8a30b
 
 
 
 
 
 
667244c
 
 
9f8a30b
 
 
 
667244c
 
 
9f8a30b
 
 
 
 
667244c
 
9f8a30b
 
 
 
 
 
667244c
9f8a30b
667244c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f8a30b
 
 
 
 
 
 
 
 
 
 
 
667244c
9f8a30b
667244c
 
 
 
 
 
 
 
 
 
 
 
 
9f8a30b
 
 
667244c
 
 
 
 
 
9f8a30b
667244c
 
9f8a30b
 
 
 
 
 
667244c
9f8a30b
667244c
 
9f8a30b
667244c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f8a30b
 
 
 
 
 
 
 
 
 
667244c
 
 
 
 
 
 
 
 
9f8a30b
667244c
9f8a30b
 
 
 
 
 
 
 
 
 
 
 
 
667244c
 
546720a
 
 
 
 
 
9bc18d3
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
<!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 rel="stylesheet" type="text/css" href="/static/style.css">
</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>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>Response:</h4>
                <pre><code class="language-json">{
                    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
                    "token_type": "bearer",
                    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
                }</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>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="generate">
                <h3>4. Generate Endpoint</h3>
                <p><span class="method">POST</span><span class="endpoint-url">/generate</span></p>
                <p>This endpoint is used to generate text based on a query. It requires a valid access token and supports optional streaming.</p>
        
                <h4>cURL Request:</h4>
                <pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/generate?stream=true' \
                 -H "Content-Type: application/json" \
                 -H "Authorization: Bearer your-access-token" \
                 -d '{"query": "test query"}'</code></pre>
        
                <h4>Response:</h4>
                <pre><code class="language-json">{
                    "content": "Generated response text based on the query."
                }</code></pre>
        
                <h4>Streaming Response:</h4>
                <pre><code class="language-json">
                data: {"content": "First streamed response chunk"}
                data: {"content": "Second streamed response chunk"}
                </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: Register</h3>
                <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>
            </div>
        
            <div class="endpoint">
                <h3>Step 2: 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=testuser&password=testpassword'</code></pre>
            </div>
        
            <div class="endpoint">
                <h3>Step 3: Generate</h3>
                <pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/generate?stream=true' \
                 -H "Content-Type: application/json" \
                 -H "Authorization: Bearer your-access-token" \
                 -d '{"query": "test query"}'</code></pre>
            </div>
        
            <div class="endpoint">
                <h3>Step 4: 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 register(self, username: str, password: str):
                """Registers a new user."""
                url = f"{API_BASE_URL}/register"
                payload = {"username": username, "password": password}
                headers = {"Content-Type": "application/json"}
        
                response = requests.post(url, json=payload, headers=headers)
                if response.status_code == 200:
                    print("✅ Registration successful!")
                else:
                    raise Exception(f"⚠️ Registration failed: {response.text}")
        
            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 generate(self, query: str, stream: bool = False):
                """Generates content based on query."""
                url = f"{API_BASE_URL}/generate?stream={str(stream).lower()}"
                payload = {"query": query}
                headers = {
                    "Content-Type": "application/json",
                    "Authorization": f"Bearer {self.access_token}",
                }
        
                response = requests.post(url, json=payload, headers=headers, stream=stream)
        
                if response.status_code == 200:
                    if stream:
                        for line in response.iter_lines():
                            if line:
                                print(json.loads(line.decode("utf-8")).get("content"))
                    else:
                        return response.json()
                else:
                    raise Exception(f"⚠️ Request failed: {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: Register
            client.register("testuser", "testpassword")
        
            # Step 2: Login
            client.login("testuser", "testpassword")
        
            # Step 3: Generate response
            response = client.generate("test query", stream=True)
            if response:
                print(f"✅ Response: {response}")
        
            # Step 4: Refresh Token
            client.refresh_token()
        
        except Exception as e:
            print(f"⚠️ Error: {e}")
                </code></pre>
            </div>
        
            <h3>Example Responses:</h3>
            <pre><code class="language-json">{
                "access_token": "your-access-token",
                "refresh_token": "your-refresh-token",
                "token_type": "bearer"
            }</code></pre>
        
            <pre><code class="language-json">{
                "content": "Generated response text based on the query."
            }</code></pre>
        
            <pre><code class="language-json">
            data: {"content": "First streamed response chunk"}
            data: {"content": "Second streamed response chunk"}
            </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="/static/script.js"></script>
</body>
</html>