cure lydias dementia

This commit is contained in:
Eri Ishihara 2025-07-18 16:48:11 +02:00
parent eca615b4de
commit d2f0270896

View file

@ -72,6 +72,7 @@ screen.append(inputBox);
inputBox.focus(); inputBox.focus();
let chatHistory = []; let chatHistory = [];
let conversationHistory = [];
let currentStreamMessage = ""; let currentStreamMessage = "";
function addMessage(role, content) { function addMessage(role, content) {
@ -152,12 +153,21 @@ function finalizeStreamMessage() {
} }
} }
let assistantMessage;
if (letterIndex !== -1) { if (letterIndex !== -1) {
const messageContent = currentStreamMessage.substring(letterIndex).trim(); assistantMessage = currentStreamMessage.substring(letterIndex).trim();
addMessage(assistantname, messageContent); addMessage(assistantname, assistantMessage);
} else { } else {
assistantMessage = currentStreamMessage;
addMessage(assistantname, currentStreamMessage); addMessage(assistantname, currentStreamMessage);
} }
// Add assistant message to conversation history
conversationHistory.push({
role: "assistant",
content: assistantMessage,
});
currentStreamMessage = ""; currentStreamMessage = "";
} }
} }
@ -176,38 +186,15 @@ function setFaceBoxContent(content) {
async function sendMessage(message) { async function sendMessage(message) {
if (!message.trim()) return; if (!message.trim()) return;
//if (message.startsWith("!")) {
if (message.trim().startsWith("l!")) {
// command handler (if command, dont tell ollama about it, just handle it right here) -- THIS DOES NOT WORK AS OF NOW
const commandParts = message.slice(2).split(" ");
const command = commandParts[0];
const args = commandParts.slice(1).join(" ");
switch (command) {
case "help":
chatBox.setContent(
"available commands:\nl!help - show this help message\nl!face <text> - set face to text",
);
break;
case "clear":
chatHistory = [];
chatBox.setContent("");
break;
case "face":
if (args.trim()) {
setFaceBoxContent(args.trim());
} else {
setFaceBoxContent("=w=");
}
break;
default:
chatBox.setContent(`unknown command: ${command}`);
break;
}
} else {
// if not command, pass to ollama
addMessage(username, message); addMessage(username, message);
// Add user message to conversation history
conversationHistory.push({
role: "user",
content: message,
});
try { try {
currentStreamMessage = ""; currentStreamMessage = "";
@ -218,10 +205,7 @@ async function sendMessage(message) {
role: "system", role: "system",
content: systemprompt, content: systemprompt,
}, },
{ ...conversationHistory,
role: "user",
content: message,
},
], ],
stream: true, stream: true,
}); });
@ -237,15 +221,48 @@ async function sendMessage(message) {
} catch (error) { } catch (error) {
addMessage(assistantname, `Failed to get response: ${error.message}`); addMessage(assistantname, `Failed to get response: ${error.message}`);
} }
}
} }
inputBox.on("submit", async (text) => { inputBox.on("submit", async (text) => {
if (text.trim()) { if (text.trim()) {
inputBox.clearValue(); inputBox.clearValue();
inputBox.focus(); inputBox.focus();
// Handle commands
if (text.trim().startsWith("l!")) {
const commandParts = text.trim().slice(2).split(" ");
const command = commandParts[0];
const args = commandParts.slice(1).join(" ");
switch (command) {
case "help":
addMessage(
assistantname,
"available commands:\nl!help - if you wanna know what i can do, run this\nl!clear - clear chat history, if you want me to forget everything, just run this!\nl!face <text> - if you want to force my expression, here you go! not sure i'll be too happy about it though.",
);
break;
case "clear":
chatHistory = [];
conversationHistory = [];
chatBox.setContent("");
screen.render();
break;
case "face":
if (args.trim()) {
setFaceBoxContent(args.trim());
} else {
setFaceBoxContent("=w=");
}
break;
default:
addMessage(assistantname, `unknown command: ${command}`);
break;
}
} else {
// Regular message - send to ollama
await sendMessage(text); await sendMessage(text);
} }
}
}); });
screen.key(["escape", "q", "C-c"], () => { screen.key(["escape", "q", "C-c"], () => {