This commit is contained in:
Arma-Damna-Dillo 2024-11-03 15:46:07 -06:00
commit b3cd0b620c
4 changed files with 91 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules

44
index.mjs Normal file
View file

@ -0,0 +1,44 @@
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()

30
package-lock.json generated Normal file
View file

@ -0,0 +1,30 @@
{
"name": "samantha-webui",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "samantha-webui",
"version": "1.0.0",
"dependencies": {
"ollama": "^0.5.9"
}
},
"node_modules/ollama": {
"version": "0.5.9",
"resolved": "https://registry.npmjs.org/ollama/-/ollama-0.5.9.tgz",
"integrity": "sha512-F/KZuDRC+ZsVCuMvcOYuQ6zj42/idzCkkuknGyyGVmNStMZ/sU3jQpvhnl4SyC0+zBzLiKNZJnJeuPFuieWZvQ==",
"license": "MIT",
"dependencies": {
"whatwg-fetch": "^3.6.20"
}
},
"node_modules/whatwg-fetch": {
"version": "3.6.20",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz",
"integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==",
"license": "MIT"
}
}
}

16
package.json Normal file
View file

@ -0,0 +1,16 @@
{
"name": "samantha-cli",
"version": "1.0.0",
"main": "index.mjs",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "",
"description": "",
"dependencies": {
"ollama": "^0.5.9"
}
}