-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmock-ai.js
More file actions
48 lines (42 loc) · 1.58 KB
/
mock-ai.js
File metadata and controls
48 lines (42 loc) · 1.58 KB
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
const http = require('http');
const server = http.createServer((req, res) => {
// Set headers to allow VS Code to talk to us (CORS)
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
if (req.method === 'OPTIONS') {
res.writeHead(204);
res.end();
return;
}
if (req.method === 'POST') {
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
console.log('Received request:', body); // See what VS Code sends!
// 1. Mock response for OpenAI format
const mockResponse = {
id: "mock-response-123",
object: "chat.completion",
created: Date.now(),
choices: [{
index: 0,
message: {
role: "assistant",
content: "Hello! I am a MOCK AI running on your system. I received your code!"
},
finish_reason: "stop"
}]
};
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(mockResponse));
});
}
});
const PORT = 11434; // Same port as Ollama!
server.listen(PORT, () => {
console.log(`🤖 Mock AI Server running at http://localhost:${PORT}`);
console.log(`Ready to trick the extension into thinking I am a supercomputer.`);
});