Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions chat-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,49 +469,50 @@ document.addEventListener("DOMContentLoaded", () => {
}
}

let prompt = window.aiInstructions;
const messages = [];
if (window.aiInstructions) {
messages.push({ role: "system", content: window.aiInstructions });
}
const memories = Memory.getMemories();
if (memories?.length) {
prompt += `\nRelevant memory:\n${memories.join("\n")}\nUse it in your response.`;
messages.push({ role: "system", content: `Relevant memory:\n${memories.join("\n")}\nUse it in your response.` });
}

const HISTORY = 10;
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];
prompt += `\n${m.role === "ai" ? "AI" : "User"}: ${m.content}`;
messages.push(currentSession.messages[i]);
}

const lastUser = overrideContent || currentSession.messages[end]?.content;
if (lastUser) {
prompt += `\nUser: ${lastUser}`;
}

const modelSelectEl = document.getElementById("model-select");
const model = modelSelectEl?.value || currentSession.model || Storage.getDefaultModel();
if (!model) {
loadingDiv.textContent = "Error: No model selected.";
setTimeout(() => loadingDiv.remove(), 3000);
const btn = window._chatInternals?.sendButton || document.getElementById("send-button");
const input = window._chatInternals?.chatInput || document.getElementById("chat-input");
if (btn) btn.disabled = false;
if (input) input.disabled = false;
showToast("Please select a model before sending a message.");
if (callback) callback();
return;
}
const apiUrl = `https://text.pollinations.ai/${encodeURIComponent(prompt)}?model=${encodeURIComponent(model)}`;
messages.push({ role: "user", content: lastUser });
}

const modelSelectEl = document.getElementById("model-select");
const model = modelSelectEl?.value || currentSession.model || Storage.getDefaultModel();
if (!model) {
loadingDiv.textContent = "Error: No model selected.";
setTimeout(() => loadingDiv.remove(), 3000);
const btn = window._chatInternals?.sendButton || document.getElementById("send-button");
const input = window._chatInternals?.chatInput || document.getElementById("chat-input");
if (btn) btn.disabled = false;
if (input) input.disabled = false;
showToast("Please select a model before sending a message.");
if (callback) callback();
return;
}

try {
const res = await window.pollinationsFetch(apiUrl, {
method: "GET",
headers: { "Accept": "text/plain" }
const res = await window.pollinationsFetch("https://text.pollinations.ai/openai", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ model, messages })
}, { timeoutMs: 45000 });
const aiContentRaw = await res.text();

const data = await res.json();
loadingDiv.remove();

const aiContentRaw = data?.choices?.[0]?.message?.content || "";
let aiContent = aiContentRaw;

const memRegex = /\[memory\]([\s\S]*?)\[\/memory\]/gi;
Expand Down
43 changes: 24 additions & 19 deletions screensaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,30 @@ document.addEventListener("DOMContentLoaded", () => {
});
}

async function fetchDynamicPrompt() {
const metaPrompt = "Generate exactly one short-125-character, new, fucked up and explicit wild image prompt as text only of outlandish and psychologically thrilling image. i.e. demented, evil, psychotic art.";
const textModel = document.getElementById("model-select")?.value;
const seed = generateSeed();
const apiUrl = `https://text.pollinations.ai/${encodeURIComponent(metaPrompt)}?seed=${seed}&safe=false${textModel ? `&model=${encodeURIComponent(textModel)}` : ""}`;
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 fucking prompt returned from API");
return generatedPrompt;
} catch (err) {
console.error("Failed to fetch dynamic prompt:", err);
throw err;
}
}
async function fetchDynamicPrompt() {
const metaPrompt = "Generate exactly one short-125-character, new, fucked up and explicit wild image prompt as text only of outlandish and psychologically thrilling image. i.e. demented, evil, psychotic art.";
const textModel = document.getElementById("model-select")?.value;
const seed = generateSeed();
try {
const response = await window.pollinationsFetch("https://text.pollinations.ai/openai", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
cache: "no-store",
body: JSON.stringify({
model: textModel || "openai",
seed,
messages: [{ role: "user", content: metaPrompt }]
})
});
const data = await response.json();
const generatedPrompt = data?.choices?.[0]?.message?.content?.trim();
if (!generatedPrompt) throw new Error("No fucking 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) {
Expand Down