From eb402501de98f4faca036dc16ca3e9e94cda8836 Mon Sep 17 00:00:00 2001 From: G-Fourteen Date: Thu, 11 Sep 2025 07:08:09 -0600 Subject: [PATCH 1/2] Use openai endpoint for screensaver meta prompt --- chat-core.js | 12 ++++++----- screensaver.js | 55 +++++++++++++++++++++----------------------------- 2 files changed, 30 insertions(+), 37 deletions(-) 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..a673147 100644 --- a/screensaver.js +++ b/screensaver.js @@ -139,38 +139,29 @@ 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/openai?model=unity${token ? `&token=${token}` : ""}`; + try { + const response = await window.pollinationsFetch(apiUrl, { + method: "POST", + headers: { "Content-Type": "application/json", Accept: "application/json" }, + cache: "no-store", + body: JSON.stringify({ + model: "unity", + messages: [{ role: "user", content: metaPrompt }] + }) + }); + const data = await response.json(); + const generatedPrompt = data?.choices?.[0]?.message?.content; + 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; From fc31865f4b1b9d010877cac58d4b9ae8c876e340 Mon Sep 17 00:00:00 2001 From: G-Fourteen Date: Thu, 11 Sep 2025 07:12:07 -0600 Subject: [PATCH 2/2] Correct Pollinations API calls --- chat-core.js | 4 ++-- screensaver.js | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/chat-core.js b/chat-core.js index 2652bc0..b12a1e1 100644 --- a/chat-core.js +++ b/chat-core.js @@ -506,13 +506,13 @@ document.addEventListener("DOMContentLoaded", () => { } const model = (document.getElementById("model-select")?.value) || currentSession.model || "unity"; - const apiUrl = `https://text.pollinations.ai/openai?model=${encodeURIComponent(model)}`; + const apiUrl = `https://text.pollinations.ai/openai?&model=${encodeURIComponent(model)}`; try { const res = await window.pollinationsFetch(apiUrl, { method: "POST", headers: { "Content-Type": "application/json", "Accept": "application/json" }, - body: JSON.stringify({ messages, model }) + body: JSON.stringify({ messages }) }, { timeoutMs: 45000 }); const data = await res.json(); diff --git a/screensaver.js b/screensaver.js index a673147..e5f3c5a 100644 --- a/screensaver.js +++ b/screensaver.js @@ -141,15 +141,13 @@ document.addEventListener("DOMContentLoaded", () => { 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/openai?model=unity${token ? `&token=${token}` : ""}`; + const apiUrl = `https://text.pollinations.ai/openai?&model=unity`; try { const response = await window.pollinationsFetch(apiUrl, { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json" }, cache: "no-store", body: JSON.stringify({ - model: "unity", messages: [{ role: "user", content: metaPrompt }] }) });