2024-11-03 15:46:07 -06:00
|
|
|
import { Ollama } from 'ollama'
|
|
|
|
import { createInterface } from 'readline';
|
|
|
|
|
2024-11-18 12:09:35 -06:00
|
|
|
const model = "sparksammy/samantha-eggplant"
|
2024-11-03 15:46:07 -06:00
|
|
|
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()
|