Update hf.js
Browse files
hf.js
CHANGED
|
@@ -6,11 +6,11 @@ const app = express();
|
|
| 6 |
|
| 7 |
app.use(morgan('dev'));
|
| 8 |
|
| 9 |
-
//
|
| 10 |
const proxyUrl = process.env.PROXY || '';
|
| 11 |
-
console.log(`Proxy configuration: ${proxyUrl ? '
|
| 12 |
|
| 13 |
-
//
|
| 14 |
let proxyConfig = null;
|
| 15 |
if (proxyUrl) {
|
| 16 |
try {
|
|
@@ -24,7 +24,7 @@ if (proxyUrl) {
|
|
| 24 |
} : undefined
|
| 25 |
};
|
| 26 |
|
| 27 |
-
//
|
| 28 |
const maskedConfig = {
|
| 29 |
...proxyConfig,
|
| 30 |
auth: proxyConfig.auth ? {
|
|
@@ -38,7 +38,7 @@ if (proxyUrl) {
|
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
-
//
|
| 42 |
app.get('/hf/v1/models', (req, res) => {
|
| 43 |
const models = {
|
| 44 |
"object": "list",
|
|
@@ -169,7 +169,7 @@ app.get('/hf/v1/models', (req, res) => {
|
|
| 169 |
"created": 1706745938,
|
| 170 |
"owned_by": "cursor"
|
| 171 |
},
|
| 172 |
-
//
|
| 173 |
{
|
| 174 |
"id": "claude-3.7-sonnet",
|
| 175 |
"object": "model",
|
|
@@ -187,13 +187,13 @@ app.get('/hf/v1/models', (req, res) => {
|
|
| 187 |
res.json(models);
|
| 188 |
});
|
| 189 |
|
| 190 |
-
//
|
| 191 |
app.use('/hf/v1/chat/completions', createProxyMiddleware({
|
| 192 |
target: 'http://localhost:3010/v1/chat/completions',
|
| 193 |
changeOrigin: true,
|
| 194 |
-
//
|
| 195 |
proxy: proxyConfig,
|
| 196 |
-
//
|
| 197 |
onError: (err, req, res) => {
|
| 198 |
console.error('Proxy error:', err);
|
| 199 |
res.status(500).send('Proxy error occurred: ' + err.message);
|
|
@@ -215,92 +215,728 @@ app.get('/', (req, res) => {
|
|
| 215 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 216 |
<title>Cursor To OpenAI</title>
|
| 217 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
body {
|
| 219 |
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 220 |
-
|
|
|
|
|
|
|
| 221 |
margin: 0 auto;
|
| 222 |
padding: 20px;
|
| 223 |
line-height: 1.6;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
.container {
|
| 226 |
-
background:
|
| 227 |
border-radius: 10px;
|
| 228 |
-
padding:
|
| 229 |
-
box-shadow: 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
.info-item {
|
| 232 |
-
margin-bottom:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
}
|
|
|
|
| 234 |
.status {
|
| 235 |
-
background: ${proxyConfig ? '
|
| 236 |
-
padding:
|
| 237 |
-
border-radius:
|
| 238 |
-
margin
|
| 239 |
-
border: 1px solid ${proxyConfig ? '
|
| 240 |
}
|
|
|
|
| 241 |
.models-container {
|
| 242 |
margin-top: 20px;
|
| 243 |
-
border-top: 1px solid
|
| 244 |
padding-top: 20px;
|
| 245 |
}
|
|
|
|
| 246 |
.model-list {
|
| 247 |
display: grid;
|
| 248 |
-
grid-template-columns: repeat(auto-fill, minmax(
|
| 249 |
-
gap:
|
| 250 |
margin-top: 15px;
|
| 251 |
}
|
|
|
|
| 252 |
.model-item {
|
| 253 |
-
background:
|
| 254 |
-
padding:
|
| 255 |
-
border-radius:
|
| 256 |
font-size: 0.9em;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
}
|
| 258 |
</style>
|
| 259 |
</head>
|
| 260 |
<body>
|
| 261 |
<div class="container">
|
| 262 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
<div class="info-item">
|
| 264 |
-
<strong
|
| 265 |
</div>
|
| 266 |
<div class="info-item">
|
| 267 |
-
<strong
|
| 268 |
</div>
|
| 269 |
<div class="info-item">
|
| 270 |
-
<strong
|
| 271 |
</div>
|
|
|
|
| 272 |
<div class="status">
|
| 273 |
-
<strong
|
| 274 |
-
${proxyConfig ? `<p
|
| 275 |
</div>
|
| 276 |
|
| 277 |
<div class="models-container">
|
| 278 |
-
<h3
|
| 279 |
-
<div id="model-list" class="model-list"
|
| 280 |
</div>
|
| 281 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
const url = new URL(window.location.href);
|
| 284 |
const link = url.protocol + '//' + url.host + '/hf/v1';
|
| 285 |
document.getElementById('endpoint-url').textContent = link;
|
| 286 |
|
| 287 |
-
//
|
| 288 |
fetch('/hf/v1/models')
|
| 289 |
.then(response => response.json())
|
| 290 |
.then(data => {
|
| 291 |
const modelListEl = document.getElementById('model-list');
|
| 292 |
modelListEl.innerHTML = '';
|
| 293 |
|
|
|
|
|
|
|
|
|
|
| 294 |
data.data.forEach(model => {
|
| 295 |
const modelEl = document.createElement('div');
|
| 296 |
modelEl.className = 'model-item';
|
| 297 |
modelEl.textContent = model.id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
modelListEl.appendChild(modelEl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
});
|
| 300 |
})
|
| 301 |
.catch(err => {
|
| 302 |
-
document.getElementById('model-list').textContent = '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
</script>
|
| 305 |
</body>
|
| 306 |
</html>
|
|
@@ -312,4 +948,4 @@ const port = process.env.HF_PORT || 7860;
|
|
| 312 |
app.listen(port, () => {
|
| 313 |
console.log(`HF Proxy server is running at PORT: ${port}`);
|
| 314 |
console.log(`Proxy status: ${proxyConfig ? 'Enabled' : 'Disabled'}`);
|
| 315 |
-
});
|
|
|
|
| 6 |
|
| 7 |
app.use(morgan('dev'));
|
| 8 |
|
| 9 |
+
// Get proxy configuration from environment variables
|
| 10 |
const proxyUrl = process.env.PROXY || '';
|
| 11 |
+
console.log(`Proxy configuration: ${proxyUrl ? 'Configured' : 'Not configured'}`);
|
| 12 |
|
| 13 |
+
// Parse proxy URL
|
| 14 |
let proxyConfig = null;
|
| 15 |
if (proxyUrl) {
|
| 16 |
try {
|
|
|
|
| 24 |
} : undefined
|
| 25 |
};
|
| 26 |
|
| 27 |
+
// Print proxy configuration (with masked password)
|
| 28 |
const maskedConfig = {
|
| 29 |
...proxyConfig,
|
| 30 |
auth: proxyConfig.auth ? {
|
|
|
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
+
// Add models list API
|
| 42 |
app.get('/hf/v1/models', (req, res) => {
|
| 43 |
const models = {
|
| 44 |
"object": "list",
|
|
|
|
| 169 |
"created": 1706745938,
|
| 170 |
"owned_by": "cursor"
|
| 171 |
},
|
| 172 |
+
// New models
|
| 173 |
{
|
| 174 |
"id": "claude-3.7-sonnet",
|
| 175 |
"object": "model",
|
|
|
|
| 187 |
res.json(models);
|
| 188 |
});
|
| 189 |
|
| 190 |
+
// Configure proxy middleware
|
| 191 |
app.use('/hf/v1/chat/completions', createProxyMiddleware({
|
| 192 |
target: 'http://localhost:3010/v1/chat/completions',
|
| 193 |
changeOrigin: true,
|
| 194 |
+
// Add proxy configuration
|
| 195 |
proxy: proxyConfig,
|
| 196 |
+
// Add error handling
|
| 197 |
onError: (err, req, res) => {
|
| 198 |
console.error('Proxy error:', err);
|
| 199 |
res.status(500).send('Proxy error occurred: ' + err.message);
|
|
|
|
| 215 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 216 |
<title>Cursor To OpenAI</title>
|
| 217 |
<style>
|
| 218 |
+
:root {
|
| 219 |
+
--bg-primary: #ffffff;
|
| 220 |
+
--bg-secondary: #f9f9f9;
|
| 221 |
+
--bg-tertiary: #f0f0f0;
|
| 222 |
+
--text-primary: #333333;
|
| 223 |
+
--text-secondary: #666666;
|
| 224 |
+
--border-color: #e0e0e0;
|
| 225 |
+
--accent-color: #5D5CDE;
|
| 226 |
+
--accent-light: #7D7CED;
|
| 227 |
+
--success-bg: #e1f5e1;
|
| 228 |
+
--success-border: #c3e6cb;
|
| 229 |
+
--warning-bg: #fff3cd;
|
| 230 |
+
--warning-border: #ffeeba;
|
| 231 |
+
--code-bg: #f5f5f5;
|
| 232 |
+
--shadow-color: rgba(0,0,0,0.1);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
[data-theme="dark"] {
|
| 236 |
+
--bg-primary: #181818;
|
| 237 |
+
--bg-secondary: #222222;
|
| 238 |
+
--bg-tertiary: #2a2a2a;
|
| 239 |
+
--text-primary: #e0e0e0;
|
| 240 |
+
--text-secondary: #b0b0b0;
|
| 241 |
+
--border-color: #444444;
|
| 242 |
+
--accent-color: #7D7CED;
|
| 243 |
+
--accent-light: #8D8CF0;
|
| 244 |
+
--success-bg: #1e3a1e;
|
| 245 |
+
--success-border: #2a5a2a;
|
| 246 |
+
--warning-bg: #3a3018;
|
| 247 |
+
--warning-border: #5a4820;
|
| 248 |
+
--code-bg: #2d2d2d;
|
| 249 |
+
--shadow-color: rgba(0,0,0,0.3);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
* {
|
| 253 |
+
box-sizing: border-box;
|
| 254 |
+
margin: 0;
|
| 255 |
+
padding: 0;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
body {
|
| 259 |
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 260 |
+
color: var(--text-primary);
|
| 261 |
+
background-color: var(--bg-primary);
|
| 262 |
+
max-width: 1200px;
|
| 263 |
margin: 0 auto;
|
| 264 |
padding: 20px;
|
| 265 |
line-height: 1.6;
|
| 266 |
+
transition: background-color 0.3s, color 0.3s;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
h1, h2, h3, h4 {
|
| 270 |
+
margin-top: 1.5rem;
|
| 271 |
+
margin-bottom: 1rem;
|
| 272 |
+
color: var(--text-primary);
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
p {
|
| 276 |
+
margin-bottom: 1rem;
|
| 277 |
}
|
| 278 |
+
|
| 279 |
+
a {
|
| 280 |
+
color: var(--accent-color);
|
| 281 |
+
text-decoration: none;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
a:hover {
|
| 285 |
+
color: var(--accent-light);
|
| 286 |
+
text-decoration: underline;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
.container {
|
| 290 |
+
background: var(--bg-secondary);
|
| 291 |
border-radius: 10px;
|
| 292 |
+
padding: 30px;
|
| 293 |
+
box-shadow: 0 4px 16px var(--shadow-color);
|
| 294 |
+
margin-bottom: 30px;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
.header {
|
| 298 |
+
display: flex;
|
| 299 |
+
justify-content: space-between;
|
| 300 |
+
align-items: center;
|
| 301 |
+
margin-bottom: 20px;
|
| 302 |
+
padding-bottom: 20px;
|
| 303 |
+
border-bottom: 1px solid var(--border-color);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
.theme-toggle {
|
| 307 |
+
display: flex;
|
| 308 |
+
align-items: center;
|
| 309 |
}
|
| 310 |
+
|
| 311 |
+
.theme-toggle-label {
|
| 312 |
+
margin-right: 10px;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
.switch {
|
| 316 |
+
position: relative;
|
| 317 |
+
display: inline-block;
|
| 318 |
+
width: 50px;
|
| 319 |
+
height: 24px;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
.switch input {
|
| 323 |
+
opacity: 0;
|
| 324 |
+
width: 0;
|
| 325 |
+
height: 0;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
.slider {
|
| 329 |
+
position: absolute;
|
| 330 |
+
cursor: pointer;
|
| 331 |
+
top: 0;
|
| 332 |
+
left: 0;
|
| 333 |
+
right: 0;
|
| 334 |
+
bottom: 0;
|
| 335 |
+
background-color: var(--bg-tertiary);
|
| 336 |
+
transition: .4s;
|
| 337 |
+
border-radius: 24px;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
.slider:before {
|
| 341 |
+
position: absolute;
|
| 342 |
+
content: "";
|
| 343 |
+
height: 16px;
|
| 344 |
+
width: 16px;
|
| 345 |
+
left: 4px;
|
| 346 |
+
bottom: 4px;
|
| 347 |
+
background-color: var(--accent-color);
|
| 348 |
+
transition: .4s;
|
| 349 |
+
border-radius: 50%;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
input:checked + .slider {
|
| 353 |
+
background-color: var(--accent-light);
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
input:checked + .slider:before {
|
| 357 |
+
transform: translateX(26px);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
.info-item {
|
| 361 |
+
margin-bottom: 16px;
|
| 362 |
+
padding: 10px;
|
| 363 |
+
background: var(--bg-secondary);
|
| 364 |
+
border-radius: 6px;
|
| 365 |
+
border: 1px solid var(--border-color);
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
.info-item strong {
|
| 369 |
+
display: block;
|
| 370 |
+
margin-bottom: 5px;
|
| 371 |
}
|
| 372 |
+
|
| 373 |
.status {
|
| 374 |
+
background: ${proxyConfig ? 'var(--success-bg)' : 'var(--warning-bg)'};
|
| 375 |
+
padding: 15px;
|
| 376 |
+
border-radius: 8px;
|
| 377 |
+
margin: 20px 0;
|
| 378 |
+
border: 1px solid ${proxyConfig ? 'var(--success-border)' : 'var(--warning-border)'};
|
| 379 |
}
|
| 380 |
+
|
| 381 |
.models-container {
|
| 382 |
margin-top: 20px;
|
| 383 |
+
border-top: 1px solid var(--border-color);
|
| 384 |
padding-top: 20px;
|
| 385 |
}
|
| 386 |
+
|
| 387 |
.model-list {
|
| 388 |
display: grid;
|
| 389 |
+
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
| 390 |
+
gap: 12px;
|
| 391 |
margin-top: 15px;
|
| 392 |
}
|
| 393 |
+
|
| 394 |
.model-item {
|
| 395 |
+
background: var(--bg-tertiary);
|
| 396 |
+
padding: 10px 15px;
|
| 397 |
+
border-radius: 6px;
|
| 398 |
font-size: 0.9em;
|
| 399 |
+
transition: all 0.2s;
|
| 400 |
+
cursor: pointer;
|
| 401 |
+
border: 1px solid var(--border-color);
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
.model-item:hover {
|
| 405 |
+
transform: translateY(-2px);
|
| 406 |
+
box-shadow: 0 4px 8px var(--shadow-color);
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
.guide-section {
|
| 410 |
+
margin-top: 40px;
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
.step {
|
| 414 |
+
margin-bottom: 20px;
|
| 415 |
+
padding: 15px;
|
| 416 |
+
background: var(--bg-secondary);
|
| 417 |
+
border-radius: 8px;
|
| 418 |
+
border-left: 4px solid var(--accent-color);
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
.step h3 {
|
| 422 |
+
margin-top: 0;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
.code-block {
|
| 426 |
+
background: var(--code-bg);
|
| 427 |
+
border-radius: 6px;
|
| 428 |
+
padding: 15px;
|
| 429 |
+
margin: 15px 0;
|
| 430 |
+
overflow-x: auto;
|
| 431 |
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
|
| 432 |
+
font-size: 14px;
|
| 433 |
+
line-height: 1.5;
|
| 434 |
+
border: 1px solid var(--border-color);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
.tab-container {
|
| 438 |
+
margin-top: 20px;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
.tabs {
|
| 442 |
+
display: flex;
|
| 443 |
+
border-bottom: 1px solid var(--border-color);
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
.tab {
|
| 447 |
+
padding: 10px 20px;
|
| 448 |
+
cursor: pointer;
|
| 449 |
+
background: var(--bg-secondary);
|
| 450 |
+
border: 1px solid var(--border-color);
|
| 451 |
+
border-bottom: none;
|
| 452 |
+
border-radius: 6px 6px 0 0;
|
| 453 |
+
margin-right: 5px;
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
.tab.active {
|
| 457 |
+
background: var(--accent-color);
|
| 458 |
+
color: white;
|
| 459 |
+
border-color: var(--accent-color);
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
.tab-content {
|
| 463 |
+
display: none;
|
| 464 |
+
padding: 20px;
|
| 465 |
+
background: var(--bg-secondary);
|
| 466 |
+
border: 1px solid var(--border-color);
|
| 467 |
+
border-top: none;
|
| 468 |
+
border-radius: 0 0 6px 6px;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
.tab-content.active {
|
| 472 |
+
display: block;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
.api-tester {
|
| 476 |
+
margin-top: 30px;
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
.form-group {
|
| 480 |
+
margin-bottom: 15px;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
.form-group label {
|
| 484 |
+
display: block;
|
| 485 |
+
margin-bottom: 5px;
|
| 486 |
+
font-weight: bold;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
.form-control {
|
| 490 |
+
width: 100%;
|
| 491 |
+
padding: 10px;
|
| 492 |
+
border: 1px solid var(--border-color);
|
| 493 |
+
border-radius: 4px;
|
| 494 |
+
background: var(--bg-primary);
|
| 495 |
+
color: var(--text-primary);
|
| 496 |
+
font-size: 16px;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
textarea.form-control {
|
| 500 |
+
min-height: 100px;
|
| 501 |
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
.btn {
|
| 505 |
+
padding: 10px 20px;
|
| 506 |
+
background: var(--accent-color);
|
| 507 |
+
color: white;
|
| 508 |
+
border: none;
|
| 509 |
+
border-radius: 4px;
|
| 510 |
+
cursor: pointer;
|
| 511 |
+
font-size: 16px;
|
| 512 |
+
transition: background 0.2s;
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
.btn:hover {
|
| 516 |
+
background: var(--accent-light);
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
.response-container {
|
| 520 |
+
margin-top: 20px;
|
| 521 |
+
padding: 15px;
|
| 522 |
+
background: var(--bg-secondary);
|
| 523 |
+
border-radius: 6px;
|
| 524 |
+
border: 1px solid var(--border-color);
|
| 525 |
+
max-height: 300px;
|
| 526 |
+
overflow-y: auto;
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
@media (max-width: 768px) {
|
| 530 |
+
.container {
|
| 531 |
+
padding: 20px;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
.model-list {
|
| 535 |
+
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
| 536 |
+
}
|
| 537 |
}
|
| 538 |
</style>
|
| 539 |
</head>
|
| 540 |
<body>
|
| 541 |
<div class="container">
|
| 542 |
+
<div class="header">
|
| 543 |
+
<h1>Cursor To OpenAI Server</h1>
|
| 544 |
+
<div class="theme-toggle">
|
| 545 |
+
<span class="theme-toggle-label">Dark Mode</span>
|
| 546 |
+
<label class="switch">
|
| 547 |
+
<input type="checkbox" id="theme-toggle">
|
| 548 |
+
<span class="slider"></span>
|
| 549 |
+
</label>
|
| 550 |
+
</div>
|
| 551 |
+
</div>
|
| 552 |
+
|
| 553 |
<div class="info-item">
|
| 554 |
+
<strong>Chat Source:</strong> Custom (OpenAI Compatible)
|
| 555 |
</div>
|
| 556 |
<div class="info-item">
|
| 557 |
+
<strong>Custom Endpoint (Base URL):</strong> <span id="endpoint-url"></span>
|
| 558 |
</div>
|
| 559 |
<div class="info-item">
|
| 560 |
+
<strong>Custom API Key:</strong> [Cursor Cookie in format user_...]
|
| 561 |
</div>
|
| 562 |
+
|
| 563 |
<div class="status">
|
| 564 |
+
<strong>Proxy Status:</strong> ${proxyConfig ? 'Enabled' : 'Disabled'}
|
| 565 |
+
${proxyConfig ? `<p>Proxy Server: ${proxyConfig.host}:${proxyConfig.port}</p>` : ''}
|
| 566 |
</div>
|
| 567 |
|
| 568 |
<div class="models-container">
|
| 569 |
+
<h3>Supported Models</h3>
|
| 570 |
+
<div id="model-list" class="model-list">Loading...</div>
|
| 571 |
</div>
|
| 572 |
</div>
|
| 573 |
+
|
| 574 |
+
<div class="container guide-section">
|
| 575 |
+
<h2>Complete Guide to Cursor API Integration</h2>
|
| 576 |
+
|
| 577 |
+
<div class="tab-container">
|
| 578 |
+
<div class="tabs">
|
| 579 |
+
<div class="tab active" data-tab="setup">Setup</div>
|
| 580 |
+
<div class="tab" data-tab="auth">Authentication</div>
|
| 581 |
+
<div class="tab" data-tab="usage">Usage Examples</div>
|
| 582 |
+
<div class="tab" data-tab="test">API Tester</div>
|
| 583 |
+
</div>
|
| 584 |
+
|
| 585 |
+
<div class="tab-content active" id="setup">
|
| 586 |
+
<h3>Setting Up Cursor API Connection</h3>
|
| 587 |
+
|
| 588 |
+
<div class="step">
|
| 589 |
+
<h3>Step 1: Install the Required Dependencies</h3>
|
| 590 |
+
<p>Make sure you have Node.js installed, then install the necessary packages:</p>
|
| 591 |
+
<div class="code-block">
|
| 592 |
+
npm install axios
|
| 593 |
+
</div>
|
| 594 |
+
</div>
|
| 595 |
+
|
| 596 |
+
<div class="step">
|
| 597 |
+
<h3>Step 2: Configure Your Environment</h3>
|
| 598 |
+
<p>Set up your environment with the Cursor API endpoint:</p>
|
| 599 |
+
<div class="code-block">
|
| 600 |
+
const CURSOR_API_URL = "http://localhost:7860/hf/v1"; // Or your server URL
|
| 601 |
+
</div>
|
| 602 |
+
</div>
|
| 603 |
+
|
| 604 |
+
<div class="step">
|
| 605 |
+
<h3>Step 3: Create a Helper Function</h3>
|
| 606 |
+
<p>Create a helper function to interact with the API:</p>
|
| 607 |
+
<div class="code-block">
|
| 608 |
+
const axios = require('axios');
|
| 609 |
+
|
| 610 |
+
async function queryCursorAPI(model, messages, options = {}) {
|
| 611 |
+
try {
|
| 612 |
+
const response = await axios.post(`${CURSOR_API_URL}/chat/completions`, {
|
| 613 |
+
model: model,
|
| 614 |
+
messages: messages,
|
| 615 |
+
temperature: options.temperature || 0.7,
|
| 616 |
+
max_tokens: options.max_tokens,
|
| 617 |
+
stream: options.stream || false
|
| 618 |
+
}, {
|
| 619 |
+
headers: {
|
| 620 |
+
'Content-Type': 'application/json',
|
| 621 |
+
'Authorization': `Bearer ${YOUR_API_KEY}` // Your Cursor cookie
|
| 622 |
+
}
|
| 623 |
+
});
|
| 624 |
+
|
| 625 |
+
return response.data;
|
| 626 |
+
} catch (error) {
|
| 627 |
+
console.error('Error querying Cursor API:', error.response?.data || error.message);
|
| 628 |
+
throw error;
|
| 629 |
+
}
|
| 630 |
+
}
|
| 631 |
+
</div>
|
| 632 |
+
</div>
|
| 633 |
+
</div>
|
| 634 |
+
|
| 635 |
+
<div class="tab-content" id="auth">
|
| 636 |
+
<h3>Authentication with Cursor API</h3>
|
| 637 |
+
|
| 638 |
+
<div class="step">
|
| 639 |
+
<h3>Step 1: Obtain Your Cursor Cookie</h3>
|
| 640 |
+
<p>To authenticate with the Cursor API, you need to extract your Cursor cookie:</p>
|
| 641 |
+
<ol>
|
| 642 |
+
<li>Log in to <a href="https://cursor.so" target="_blank">Cursor.so</a></li>
|
| 643 |
+
<li>Open Developer Tools (F12 or Right-click → Inspect)</li>
|
| 644 |
+
<li>Go to the Application tab</li>
|
| 645 |
+
<li>Under Storage, select Cookies</li>
|
| 646 |
+
<li>Find the cookie that starts with <code>user_...</code></li>
|
| 647 |
+
<li>Copy this value - this is your API key</li>
|
| 648 |
+
</ol>
|
| 649 |
+
</div>
|
| 650 |
+
|
| 651 |
+
<div class="step">
|
| 652 |
+
<h3>Step 2: Use the Cookie as Your API Key</h3>
|
| 653 |
+
<p>Include your Cursor cookie in the Authorization header:</p>
|
| 654 |
+
<div class="code-block">
|
| 655 |
+
headers: {
|
| 656 |
+
'Content-Type': 'application/json',
|
| 657 |
+
'Authorization': 'Bearer user_your_cookie_value_here'
|
| 658 |
+
}
|
| 659 |
+
</div>
|
| 660 |
+
<p class="warning">Important: Treat your Cursor cookie as a secret. Never share it publicly or include it in client-side code.</p>
|
| 661 |
+
</div>
|
| 662 |
+
|
| 663 |
+
<div class="step">
|
| 664 |
+
<h3>Step 3: Test Authentication</h3>
|
| 665 |
+
<p>Verify your authentication is working:</p>
|
| 666 |
+
<div class="code-block">
|
| 667 |
+
async function testAuth() {
|
| 668 |
+
try {
|
| 669 |
+
const response = await queryCursorAPI('claude-3.5-sonnet', [
|
| 670 |
+
{ role: 'user', content: 'Hello, can you hear me?' }
|
| 671 |
+
]);
|
| 672 |
+
console.log('Authentication successful!', response.choices[0].message.content);
|
| 673 |
+
} catch (error) {
|
| 674 |
+
console.error('Authentication failed:', error);
|
| 675 |
+
}
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
testAuth();
|
| 679 |
+
</div>
|
| 680 |
+
</div>
|
| 681 |
+
</div>
|
| 682 |
+
|
| 683 |
+
<div class="tab-content" id="usage">
|
| 684 |
+
<h3>Cursor API Usage Examples</h3>
|
| 685 |
+
|
| 686 |
+
<div class="step">
|
| 687 |
+
<h3>Basic Text Completion</h3>
|
| 688 |
+
<div class="code-block">
|
| 689 |
+
const messages = [
|
| 690 |
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
| 691 |
+
{ role: 'user', content: 'What is the capital of France?' }
|
| 692 |
+
];
|
| 693 |
+
|
| 694 |
+
const response = await queryCursorAPI('claude-3.5-sonnet', messages);
|
| 695 |
+
console.log(response.choices[0].message.content);
|
| 696 |
+
</div>
|
| 697 |
+
</div>
|
| 698 |
+
|
| 699 |
+
<div class="step">
|
| 700 |
+
<h3>Streaming Response</h3>
|
| 701 |
+
<div class="code-block">
|
| 702 |
+
const axios = require('axios');
|
| 703 |
+
|
| 704 |
+
async function streamResponse(model, messages) {
|
| 705 |
+
try {
|
| 706 |
+
const response = await axios.post(`${CURSOR_API_URL}/chat/completions`, {
|
| 707 |
+
model: model,
|
| 708 |
+
messages: messages,
|
| 709 |
+
stream: true
|
| 710 |
+
}, {
|
| 711 |
+
headers: {
|
| 712 |
+
'Content-Type': 'application/json',
|
| 713 |
+
'Authorization': `Bearer ${YOUR_API_KEY}`
|
| 714 |
+
},
|
| 715 |
+
responseType: 'stream'
|
| 716 |
+
});
|
| 717 |
+
|
| 718 |
+
response.data.on('data', chunk => {
|
| 719 |
+
const lines = chunk.toString().split('\\n').filter(line => line.trim() !== '');
|
| 720 |
+
|
| 721 |
+
for (const line of lines) {
|
| 722 |
+
if (line.includes('[DONE]')) return;
|
| 723 |
+
|
| 724 |
+
if (line.startsWith('data:')) {
|
| 725 |
+
const jsonStr = line.replace('data:', '').trim();
|
| 726 |
+
try {
|
| 727 |
+
const json = JSON.parse(jsonStr);
|
| 728 |
+
if (json.choices?.[0]?.delta?.content) {
|
| 729 |
+
process.stdout.write(json.choices[0].delta.content);
|
| 730 |
+
}
|
| 731 |
+
} catch (e) {
|
| 732 |
+
// Skip invalid JSON
|
| 733 |
+
}
|
| 734 |
+
}
|
| 735 |
+
}
|
| 736 |
+
});
|
| 737 |
+
|
| 738 |
+
} catch (error) {
|
| 739 |
+
console.error('Streaming error:', error);
|
| 740 |
+
}
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
// Usage
|
| 744 |
+
streamResponse('gpt-4o', [{ role: 'user', content: 'Write a short story about a robot.' }]);
|
| 745 |
+
</div>
|
| 746 |
+
</div>
|
| 747 |
+
|
| 748 |
+
<div class="step">
|
| 749 |
+
<h3>Using Different Models</h3>
|
| 750 |
+
<p>You can use any model from the supported models list:</p>
|
| 751 |
+
<div class="code-block">
|
| 752 |
+
// Using Claude 3.7 Sonnet
|
| 753 |
+
const claudeResponse = await queryCursorAPI('claude-3.7-sonnet', [
|
| 754 |
+
{ role: 'user', content: 'Explain quantum computing briefly.' }
|
| 755 |
+
]);
|
| 756 |
+
|
| 757 |
+
// Using GPT-4o
|
| 758 |
+
const gptResponse = await queryCursorAPI('gpt-4o', [
|
| 759 |
+
{ role: 'user', content: 'What are the benefits of clean energy?' }
|
| 760 |
+
]);
|
| 761 |
+
|
| 762 |
+
// Using the "thinking" variant for complex reasoning
|
| 763 |
+
const thinkingResponse = await queryCursorAPI('claude-3.7-sonnet-thinking', [
|
| 764 |
+
{ role: 'user', content: 'Solve this math problem: If a² + b² = 25 and ab = 12, what is a + b?' }
|
| 765 |
+
]);
|
| 766 |
+
</div>
|
| 767 |
+
</div>
|
| 768 |
+
|
| 769 |
+
<div class="step">
|
| 770 |
+
<h3>Setting Custom Parameters</h3>
|
| 771 |
+
<div class="code-block">
|
| 772 |
+
const response = await queryCursorAPI('gpt-4', [
|
| 773 |
+
{ role: 'user', content: 'Generate a creative story idea.' }
|
| 774 |
+
], {
|
| 775 |
+
temperature: 0.9, // Higher creativity
|
| 776 |
+
max_tokens: 500 // Limit response length
|
| 777 |
+
});
|
| 778 |
+
</div>
|
| 779 |
+
</div>
|
| 780 |
+
</div>
|
| 781 |
+
|
| 782 |
+
<div class="tab-content" id="test">
|
| 783 |
+
<h3>Cursor API Tester</h3>
|
| 784 |
+
<p>Use this tool to test API calls directly from the browser:</p>
|
| 785 |
+
|
| 786 |
+
<div class="api-tester">
|
| 787 |
+
<div class="form-group">
|
| 788 |
+
<label for="api-key">API Key (Cursor Cookie)</label>
|
| 789 |
+
<input type="password" id="api-key" class="form-control" placeholder="user_...">
|
| 790 |
+
</div>
|
| 791 |
+
|
| 792 |
+
<div class="form-group">
|
| 793 |
+
<label for="model-select">Model</label>
|
| 794 |
+
<select id="model-select" class="form-control">
|
| 795 |
+
<option value="claude-3.7-sonnet">claude-3.7-sonnet</option>
|
| 796 |
+
<option value="gpt-4o">gpt-4o</option>
|
| 797 |
+
<option value="claude-3.5-sonnet">claude-3.5-sonnet</option>
|
| 798 |
+
<option value="gpt-4">gpt-4</option>
|
| 799 |
+
</select>
|
| 800 |
+
</div>
|
| 801 |
+
|
| 802 |
+
<div class="form-group">
|
| 803 |
+
<label for="prompt-input">Prompt</label>
|
| 804 |
+
<textarea id="prompt-input" class="form-control" placeholder="Enter your prompt here...">Hello, can you introduce yourself?</textarea>
|
| 805 |
+
</div>
|
| 806 |
+
|
| 807 |
+
<div class="form-group">
|
| 808 |
+
<label for="temperature">Temperature</label>
|
| 809 |
+
<input type="range" id="temperature" class="form-control" min="0" max="1" step="0.1" value="0.7">
|
| 810 |
+
<span id="temperature-value">0.7</span>
|
| 811 |
+
</div>
|
| 812 |
+
|
| 813 |
+
<button id="submit-api" class="btn">Send Request</button>
|
| 814 |
+
|
| 815 |
+
<div class="response-container">
|
| 816 |
+
<pre id="api-response">Response will appear here...</pre>
|
| 817 |
+
</div>
|
| 818 |
+
</div>
|
| 819 |
+
</div>
|
| 820 |
+
</div>
|
| 821 |
+
</div>
|
| 822 |
+
|
| 823 |
<script>
|
| 824 |
+
// Theme toggling
|
| 825 |
+
const themeToggle = document.getElementById('theme-toggle');
|
| 826 |
+
|
| 827 |
+
// Check for saved theme preference or system preference
|
| 828 |
+
if (localStorage.getItem('theme') === 'dark' ||
|
| 829 |
+
(!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
| 830 |
+
document.documentElement.setAttribute('data-theme', 'dark');
|
| 831 |
+
themeToggle.checked = true;
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
// Toggle theme when switch is clicked
|
| 835 |
+
themeToggle.addEventListener('change', function() {
|
| 836 |
+
if (this.checked) {
|
| 837 |
+
document.documentElement.setAttribute('data-theme', 'dark');
|
| 838 |
+
localStorage.setItem('theme', 'dark');
|
| 839 |
+
} else {
|
| 840 |
+
document.documentElement.setAttribute('data-theme', 'light');
|
| 841 |
+
localStorage.setItem('theme', 'light');
|
| 842 |
+
}
|
| 843 |
+
});
|
| 844 |
+
|
| 845 |
+
// Get and display endpoint URL
|
| 846 |
const url = new URL(window.location.href);
|
| 847 |
const link = url.protocol + '//' + url.host + '/hf/v1';
|
| 848 |
document.getElementById('endpoint-url').textContent = link;
|
| 849 |
|
| 850 |
+
// Load models list
|
| 851 |
fetch('/hf/v1/models')
|
| 852 |
.then(response => response.json())
|
| 853 |
.then(data => {
|
| 854 |
const modelListEl = document.getElementById('model-list');
|
| 855 |
modelListEl.innerHTML = '';
|
| 856 |
|
| 857 |
+
// Sort models alphabetically
|
| 858 |
+
data.data.sort((a, b) => a.id.localeCompare(b.id));
|
| 859 |
+
|
| 860 |
data.data.forEach(model => {
|
| 861 |
const modelEl = document.createElement('div');
|
| 862 |
modelEl.className = 'model-item';
|
| 863 |
modelEl.textContent = model.id;
|
| 864 |
+
modelEl.addEventListener('click', () => {
|
| 865 |
+
if (document.getElementById('model-select')) {
|
| 866 |
+
document.getElementById('model-select').value = model.id;
|
| 867 |
+
}
|
| 868 |
+
});
|
| 869 |
modelListEl.appendChild(modelEl);
|
| 870 |
+
|
| 871 |
+
// Also add to dropdown if it exists
|
| 872 |
+
if (document.getElementById('model-select')) {
|
| 873 |
+
const option = document.createElement('option');
|
| 874 |
+
option.value = model.id;
|
| 875 |
+
option.textContent = model.id;
|
| 876 |
+
document.getElementById('model-select').appendChild(option);
|
| 877 |
+
}
|
| 878 |
});
|
| 879 |
})
|
| 880 |
.catch(err => {
|
| 881 |
+
document.getElementById('model-list').textContent = 'Failed to load models: ' + err.message;
|
| 882 |
+
});
|
| 883 |
+
|
| 884 |
+
// Tab switching
|
| 885 |
+
const tabs = document.querySelectorAll('.tab');
|
| 886 |
+
tabs.forEach(tab => {
|
| 887 |
+
tab.addEventListener('click', () => {
|
| 888 |
+
// Remove active class from all tabs
|
| 889 |
+
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
|
| 890 |
+
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
| 891 |
+
|
| 892 |
+
// Add active class to clicked tab
|
| 893 |
+
tab.classList.add('active');
|
| 894 |
+
document.getElementById(tab.dataset.tab).classList.add('active');
|
| 895 |
});
|
| 896 |
+
});
|
| 897 |
+
|
| 898 |
+
// Temperature slider
|
| 899 |
+
const temperatureSlider = document.getElementById('temperature');
|
| 900 |
+
const temperatureValue = document.getElementById('temperature-value');
|
| 901 |
+
if (temperatureSlider) {
|
| 902 |
+
temperatureSlider.addEventListener('input', () => {
|
| 903 |
+
temperatureValue.textContent = temperatureSlider.value;
|
| 904 |
+
});
|
| 905 |
+
}
|
| 906 |
+
|
| 907 |
+
// API test functionality
|
| 908 |
+
const submitApiBtn = document.getElementById('submit-api');
|
| 909 |
+
if (submitApiBtn) {
|
| 910 |
+
submitApiBtn.addEventListener('click', async () => {
|
| 911 |
+
const apiKey = document.getElementById('api-key').value;
|
| 912 |
+
const model = document.getElementById('model-select').value;
|
| 913 |
+
const prompt = document.getElementById('prompt-input').value;
|
| 914 |
+
const temperature = parseFloat(document.getElementById('temperature').value);
|
| 915 |
+
|
| 916 |
+
const responseContainer = document.getElementById('api-response');
|
| 917 |
+
responseContainer.textContent = 'Loading...';
|
| 918 |
+
|
| 919 |
+
try {
|
| 920 |
+
const response = await fetch(`${link}/chat/completions`, {
|
| 921 |
+
method: 'POST',
|
| 922 |
+
headers: {
|
| 923 |
+
'Content-Type': 'application/json',
|
| 924 |
+
'Authorization': `Bearer ${apiKey}`
|
| 925 |
+
},
|
| 926 |
+
body: JSON.stringify({
|
| 927 |
+
model: model,
|
| 928 |
+
messages: [{ role: 'user', content: prompt }],
|
| 929 |
+
temperature: temperature
|
| 930 |
+
})
|
| 931 |
+
});
|
| 932 |
+
|
| 933 |
+
const data = await response.json();
|
| 934 |
+
responseContainer.textContent = JSON.stringify(data, null, 2);
|
| 935 |
+
} catch (error) {
|
| 936 |
+
responseContainer.textContent = 'Error: ' + (error.message || 'Unknown error');
|
| 937 |
+
}
|
| 938 |
+
});
|
| 939 |
+
}
|
| 940 |
</script>
|
| 941 |
</body>
|
| 942 |
</html>
|
|
|
|
| 948 |
app.listen(port, () => {
|
| 949 |
console.log(`HF Proxy server is running at PORT: ${port}`);
|
| 950 |
console.log(`Proxy status: ${proxyConfig ? 'Enabled' : 'Disabled'}`);
|
| 951 |
+
});
|