diff --git a/chat-core.js b/chat-core.js index dd84075..2652bc0 100644 --- a/chat-core.js +++ b/chat-core.js @@ -486,21 +486,23 @@ document.addEventListener("DOMContentLoaded", () => { chatBox.appendChild(loadingDiv); chatBox.scrollTop = chatBox.scrollHeight; - const messages = [{ role: "system", content: window.memoryInstructions }]; + const messages = [{ role: "user", content: window.memoryInstructions }]; const memories = Memory.getMemories(); if (memories?.length) { messages.push({ role: "user", content: `Relevant memory:\n${memories.join("\n")}\nUse it in your response.` }); } const HISTORY = 10; - const start = Math.max(0, currentSession.messages.length - HISTORY); - for (let i = start; i < currentSession.messages.length; i++) { + const end = currentSession.messages.length - 1; + const start = Math.max(0, end - HISTORY); + for (let i = start; i < end; i++) { const m = currentSession.messages[i]; messages.push({ role: m.role === "ai" ? "assistant" : m.role, content: m.content }); } - if (overrideContent && messages[messages.length - 1].content !== overrideContent) { - messages.push({ role: "user", content: overrideContent }); + const lastUser = overrideContent || currentSession.messages[end]?.content; + if (lastUser) { + messages.push({ role: "user", content: lastUser }); } const model = (document.getElementById("model-select")?.value) || currentSession.model || "unity"; diff --git a/screensaver.js b/screensaver.js index f251544..1a269af 100644 --- a/screensaver.js +++ b/screensaver.js @@ -139,38 +139,24 @@ document.addEventListener("DOMContentLoaded", () => { }); } - async function fetchDynamicPrompt() { - const metaPrompt = "Generate an image prompt of something new and wild. Respond with text only."; - const messages = [ - { role: "system", content: "Generate unique, new, fucked up and explicit wild image prompts as text only of outlandish and psychologically thrilling images. ie demented, evil, psychotic art, under 100 characters." }, - { role: "user", content: metaPrompt } - ]; - const body = { - messages, - model: "unity" - }; - const seed = generateSeed(); - const token = encodeURIComponent(window.POLLINATIONS_TOKEN || ""); - const apiUrl = - `https://text.pollinations.ai/openai?&model=unity&seed=${seed}&token=${token}`; - try { - const response = await window.pollinationsFetch(apiUrl, { - method: "POST", - headers: { "Content-Type": "application/json", Accept: "application/json" }, - body: JSON.stringify(body), - cache: "no-store", - }); - - const data = await response.json(); - let generatedPrompt = data.choices?.[0]?.message?.content || data.choices?.[0]?.text || data.response; - if (!generatedPrompt) throw new Error("No prompt returned from API"); - if (generatedPrompt.length > 100) generatedPrompt = generatedPrompt.substring(0, 100); - return generatedPrompt; - } catch (err) { - console.error("Failed to fetch dynamic prompt:", err); - throw err; - } - } + async function fetchDynamicPrompt() { + const metaPrompt = "Generate an image prompt of something new and wild. Respond with text only."; + const token = encodeURIComponent(window.POLLINATIONS_TOKEN || ""); + const apiUrl = `https://text.pollinations.ai/${encodeURIComponent(metaPrompt)}?model=unity${token ? `&token=${token}` : ""}`; + try { + const response = await window.pollinationsFetch(apiUrl, { + method: "GET", + headers: { Accept: "text/plain" }, + cache: "no-store", + }); + const generatedPrompt = await response.text(); + if (!generatedPrompt) throw new Error("No prompt returned from API"); + return generatedPrompt; + } catch (err) { + console.error("Failed to fetch dynamic prompt:", err); + throw err; + } + } async function updatePrompt() { if (!screensaverActive || paused || !autoPromptEnabled || isFetchingPrompt) { return false;