Spaces:
Running
Running
Upload 3 files
Browse files- Dockerfile +27 -0
- package.json +13 -0
- server.js +80 -0
Dockerfile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20-slim
|
| 2 |
+
|
| 3 |
+
# Install git
|
| 4 |
+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
| 5 |
+
|
| 6 |
+
WORKDIR /app
|
| 7 |
+
|
| 8 |
+
# Clone automatiquement le repo free-claude-code depuis GitHub
|
| 9 |
+
RUN git clone https://github.com/Alishahryar1/free-claude-code.git proxy
|
| 10 |
+
|
| 11 |
+
WORKDIR /app/proxy
|
| 12 |
+
|
| 13 |
+
# Installer les dΓ©pendances du proxy
|
| 14 |
+
RUN npm install
|
| 15 |
+
|
| 16 |
+
# Copier notre serveur web par-dessus
|
| 17 |
+
COPY server.js /app/server.js
|
| 18 |
+
COPY public/ /app/public/
|
| 19 |
+
|
| 20 |
+
WORKDIR /app
|
| 21 |
+
|
| 22 |
+
RUN npm init -y && npm install express
|
| 23 |
+
|
| 24 |
+
# Port exposΓ© par HuggingFace (obligatoire: 7860)
|
| 25 |
+
EXPOSE 7860
|
| 26 |
+
|
| 27 |
+
CMD ["node", "server.js"]
|
package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "free-claude-hf",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "Free Claude Code interface on HuggingFace",
|
| 5 |
+
"main": "server.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"start": "node server.js"
|
| 8 |
+
},
|
| 9 |
+
"dependencies": {
|
| 10 |
+
"express": "^4.18.2",
|
| 11 |
+
"http-proxy-middleware": "^3.0.0"
|
| 12 |
+
}
|
| 13 |
+
}
|
server.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const { spawn } = require('child_process');
|
| 3 |
+
const { createProxyMiddleware } = require('http-proxy-middleware');
|
| 4 |
+
const path = require('path');
|
| 5 |
+
|
| 6 |
+
const app = express();
|
| 7 |
+
const PORT = 7860;
|
| 8 |
+
const PROXY_PORT = 3000;
|
| 9 |
+
|
| 10 |
+
// βββ Lance le proxy free-claude-code en arriΓ¨re-plan βββββββββββββββββββββββ
|
| 11 |
+
const proxy = spawn('node', ['/app/proxy/index.js'], {
|
| 12 |
+
env: {
|
| 13 |
+
...process.env,
|
| 14 |
+
PORT: String(PROXY_PORT),
|
| 15 |
+
NVIDIA_API_KEY: process.env.NVIDIA_API_KEY || ''
|
| 16 |
+
},
|
| 17 |
+
stdio: 'inherit'
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
proxy.on('error', (err) => console.error('Proxy error:', err));
|
| 21 |
+
proxy.on('exit', (code) => console.log('Proxy exited with code:', code));
|
| 22 |
+
|
| 23 |
+
// Attendre que le proxy dΓ©marre
|
| 24 |
+
setTimeout(() => {
|
| 25 |
+
console.log(`Proxy lancΓ© sur le port ${PROXY_PORT}`);
|
| 26 |
+
}, 2000);
|
| 27 |
+
|
| 28 |
+
// βββ Servir l'interface web βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 29 |
+
app.use(express.static(path.join(__dirname, 'public')));
|
| 30 |
+
app.use(express.json());
|
| 31 |
+
|
| 32 |
+
// βββ Route API β relaie vers le proxy Claude ββββββββββββββββββββββββββββββββ
|
| 33 |
+
app.post('/api/chat', async (req, res) => {
|
| 34 |
+
try {
|
| 35 |
+
const response = await fetch(`http://localhost:${PROXY_PORT}/v1/messages`, {
|
| 36 |
+
method: 'POST',
|
| 37 |
+
headers: {
|
| 38 |
+
'Content-Type': 'application/json',
|
| 39 |
+
'x-api-key': 'fake-key',
|
| 40 |
+
'anthropic-version': '2023-06-01'
|
| 41 |
+
},
|
| 42 |
+
body: JSON.stringify({
|
| 43 |
+
model: req.body.model || 'claude-sonnet-4-20250514',
|
| 44 |
+
max_tokens: req.body.max_tokens || 2048,
|
| 45 |
+
messages: req.body.messages,
|
| 46 |
+
stream: req.body.stream || false
|
| 47 |
+
})
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
if (req.body.stream) {
|
| 51 |
+
res.setHeader('Content-Type', 'text/event-stream');
|
| 52 |
+
res.setHeader('Cache-Control', 'no-cache');
|
| 53 |
+
res.setHeader('Connection', 'keep-alive');
|
| 54 |
+
response.body.pipeTo(new WritableStream({
|
| 55 |
+
write(chunk) { res.write(chunk); }
|
| 56 |
+
})).finally(() => res.end());
|
| 57 |
+
} else {
|
| 58 |
+
const data = await response.json();
|
| 59 |
+
res.json(data);
|
| 60 |
+
}
|
| 61 |
+
} catch (err) {
|
| 62 |
+
console.error('API error:', err);
|
| 63 |
+
res.status(500).json({ error: err.message });
|
| 64 |
+
}
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
// βββ Status endpoint ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 68 |
+
app.get('/api/status', (req, res) => {
|
| 69 |
+
const key = process.env.NVIDIA_API_KEY;
|
| 70 |
+
res.json({
|
| 71 |
+
status: 'ok',
|
| 72 |
+
proxy_port: PROXY_PORT,
|
| 73 |
+
nvidia_key_set: !!(key && key.length > 10),
|
| 74 |
+
models: ['Kimi K2', 'GLM 4.7', 'MiniMax M2', 'Devstral']
|
| 75 |
+
});
|
| 76 |
+
});
|
| 77 |
+
|
| 78 |
+
app.listen(PORT, '0.0.0.0', () => {
|
| 79 |
+
console.log(`β
Serveur dΓ©marrΓ© sur http://0.0.0.0:${PORT}`);
|
| 80 |
+
});
|