| const http = require("http"); | |
| const data = JSON.stringify({ | |
| model: "qwen3.5:latest", | |
| messages: [{ role: "user", content: "hello" }], | |
| }); | |
| const options = { | |
| hostname: "127.0.0.1", | |
| port: 11434, | |
| path: "/v1/chat/completions", | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json", | |
| "Content-Length": Buffer.byteLength(data), | |
| Authorization: "Bearer ollama-local", | |
| }, | |
| }; | |
| const req = http.request(options, (res) => { | |
| console.log(`STATUS: ${res.statusCode}`); | |
| console.log(`HEADERS: ${JSON.stringify(res.headers)}`); | |
| res.setEncoding("utf8"); | |
| let body = ""; | |
| res.on("data", (chunk) => { | |
| body += chunk; | |
| }); | |
| res.on("end", () => { | |
| console.log(`BODY: ${body}`); | |
| }); | |
| }); | |
| req.on("error", (e) => { | |
| console.error(`problem with request: ${e.message}`); | |
| }); | |
| req.write(data); | |
| req.end(); | |