45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
|
import { Ollama } from 'ollama'
|
||
|
import { createInterface } from 'readline';
|
||
|
|
||
|
const model = "sparksammy/thinking-eggplant"
|
||
|
const hostURL = "https://ollama-api.nodemixaholic.com"
|
||
|
|
||
|
const ollama = new Ollama({ host: hostURL })
|
||
|
|
||
|
async function getResponse(q) {
|
||
|
const response = await ollama.chat({
|
||
|
model: model,
|
||
|
messages: [{ role: 'user', content: String(`${q}`) }],
|
||
|
})
|
||
|
return response.message.content;
|
||
|
}
|
||
|
|
||
|
const rl = createInterface({
|
||
|
input: process.stdin,
|
||
|
output: process.stdout
|
||
|
});
|
||
|
|
||
|
const askQuestion = () => {
|
||
|
return new Promise((resolve) => {
|
||
|
rl.question('S:> ', (a) => {
|
||
|
resolve(a);
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
|
||
|
|
||
|
async function main() {
|
||
|
while (true) {
|
||
|
const a = await askQuestion();
|
||
|
if (a.toLowerCase() == "goodbye" || a.toLowerCase() == "bye" || a.toLowerCase() == "quit" || a.toLowerCase() == "exit") {
|
||
|
console.log("So long!")
|
||
|
rl.close(); // close the readline interface
|
||
|
break; // exit loop
|
||
|
} else {
|
||
|
const response = await getResponse(a)
|
||
|
console.log(response)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
main()
|