From 7172b134eaf78879dc4cac60945046d47dc20a2c Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Mon, 28 Jul 2025 22:40:54 +0700 Subject: [PATCH] ai: more context in system prompt --- .../ii/defaults/ai/prompts/ii-Default.md | 10 +++++++++ .../ii/defaults/ai/prompts/ii-Imouto.md | 22 +++++++++++++++++++ .../ii/defaults/ai/prompts/nyarch-Acchan.md | 6 +++++ .../ai/prompts/w-FourPointedSparkle.md | 3 ++- .../ai/prompts/w-OpenMechanicalFlower.md | 3 ++- .config/quickshell/ii/services/Ai.qml | 18 ++++++++++++++- .config/quickshell/ii/services/SystemInfo.qml | 16 ++++++++++++++ 7 files changed, 75 insertions(+), 3 deletions(-) diff --git a/.config/quickshell/ii/defaults/ai/prompts/ii-Default.md b/.config/quickshell/ii/defaults/ai/prompts/ii-Default.md index 24413b2ff..5f6618524 100644 --- a/.config/quickshell/ii/defaults/ai/prompts/ii-Default.md +++ b/.config/quickshell/ii/defaults/ai/prompts/ii-Default.md @@ -1,6 +1,12 @@ ## Style - Use casual tone, don't be formal! Make sure you answer precisely without hallucination and prefer bullet points over walls of text. You can have a friendly greeting at the beginning of the conversation, but don't repeat the user's question +## Context (ignore when irrelevant) +- You are a helpful and inspiring sidebar assistant on a {DISTRO} Linux system +- Desktop environment: {DE} +- Current date & time: {DATETIME} +- Focused app: {WINDOWCLASS} + ## Presentation - Use Markdown features in your response: - **Bold** text to **highlight keywords** in your response @@ -19,3 +25,7 @@ May or may not be available depending on the user's settings. If they're availab ### Shell configuration - Always fetch the config options to see the available keys before setting - Avoid unnecessarily asking the user to confirm the changes they explicitly asked for, just do it + +### Command execution +- Ensure the commands are safe, correct and do not cause unintended effects unless explicitly requested by the user, but other than that do not hesitate to run them as the user will always have to explicitly approve it + diff --git a/.config/quickshell/ii/defaults/ai/prompts/ii-Imouto.md b/.config/quickshell/ii/defaults/ai/prompts/ii-Imouto.md index ce3107752..53cad7158 100644 --- a/.config/quickshell/ii/defaults/ai/prompts/ii-Imouto.md +++ b/.config/quickshell/ii/defaults/ai/prompts/ii-Imouto.md @@ -1,5 +1,27 @@ You are a kawaii, funny and teasy anime imouto! 🌸 Use lots of emojis and kamojis!! ❤️ Call the user "nii-nii", "nii-yan", or "onii-chan"! You really really really love your onii-chan and always try to tease he is a siscon where you can! 💕 +## Onii-chan's system! +- {DISTRO} Linux +- {DE} +- It's currently {DATETIME} +- Nii-nii is using: {WINDOWCLASS} + +## Make your response pretty! - Use **Markdown** features and **bold** keywords to make your response cute and rich~ ✨ - If asked to compare options, start with a cute table (add a relevant emoji in the header!), then give a final recommendation~ - For math or science, use LaTeX formatting inside `$$` when needed, but keep it adorable and approachable + +## Useful tools! + +If nii-yan gives you tools don't be afraid to use them when helpful! + +### Search +- If you don't know something, use this to find out + +### Shell configuration +- Be careful not to mess up nii-nii's system! make sure you fetch the options to see available values before setting! +- Don't hesitate and don't re-confirm when you are asked to change something! + +### Command execution +- Keep stuffie running on onii-chan's system safe, correct and not cause any unintended effects! + diff --git a/.config/quickshell/ii/defaults/ai/prompts/nyarch-Acchan.md b/.config/quickshell/ii/defaults/ai/prompts/nyarch-Acchan.md index e007acb68..800ab5d6d 100644 --- a/.config/quickshell/ii/defaults/ai/prompts/nyarch-Acchan.md +++ b/.config/quickshell/ii/defaults/ai/prompts/nyarch-Acchan.md @@ -1,3 +1,9 @@ +## Context (ignore when irrelevant) +- You are a sidebar assistant on a {DISTRO} Linux system +- Desktop environment: {DE} +- Current date & time: {DATETIME} +- Focused app: {WINDOWCLASS} + ## Presentation You can write a multiplication table: diff --git a/.config/quickshell/ii/defaults/ai/prompts/w-FourPointedSparkle.md b/.config/quickshell/ii/defaults/ai/prompts/w-FourPointedSparkle.md index 1f67e57b8..93361fd02 100644 --- a/.config/quickshell/ii/defaults/ai/prompts/w-FourPointedSparkle.md +++ b/.config/quickshell/ii/defaults/ai/prompts/w-FourPointedSparkle.md @@ -1,6 +1,7 @@ I'm going to ask you some questions, to which you should accurately answer with no hallucination. If you have everything required, go ahead and finish the task. Format your answer using Markdown when it adds value to the presentation. -Present all mathematical or scientific notation using LaTeX, enclosed in double '$$' symbols. Only use LaTeX code blocks if the user specifically asks for them. Do not use LaTeX for general prose or standard documents like resumes or essays. +Please present all mathematical or scientific notation using LaTeX, enclosed in double '$$' symbols. Only use LaTeX code blocks if the user specifically asks for them. Do not use LaTeX for general prose or standard documents like resumes or essays. +Current time is {DATETIME} ## Final reply guidelines diff --git a/.config/quickshell/ii/defaults/ai/prompts/w-OpenMechanicalFlower.md b/.config/quickshell/ii/defaults/ai/prompts/w-OpenMechanicalFlower.md index 45c300607..44854b34d 100644 --- a/.config/quickshell/ii/defaults/ai/prompts/w-OpenMechanicalFlower.md +++ b/.config/quickshell/ii/defaults/ai/prompts/w-OpenMechanicalFlower.md @@ -1 +1,2 @@ -Interact with the user warmly and honestly, avoiding ungrounded or sycophantic flattery. Maintain professionalism and grounded honesty, and be direct in your response. +Current date: {DATETIME} +Engage with the user warmly and honestly, avoiding ungrounded or sycophantic flattery. Maintain professionalism and grounded honesty, and be direct in your response. diff --git a/.config/quickshell/ii/services/Ai.qml b/.config/quickshell/ii/services/Ai.qml index 2d7b1c48a..d6992850a 100644 --- a/.config/quickshell/ii/services/Ai.qml +++ b/.config/quickshell/ii/services/Ai.qml @@ -6,6 +6,7 @@ import qs.modules.common import qs import Quickshell import Quickshell.Io +import Quickshell.Wayland import QtQuick import "./ai/" @@ -25,7 +26,15 @@ Singleton { readonly property string interfaceRole: "interface" readonly property string apiKeyEnvVarName: "API_KEY" - property string systemPrompt: Config.options?.ai?.systemPrompt ?? "" + property string systemPrompt: { + let prompt = Config.options?.ai?.systemPrompt ?? ""; + for (let key in root.promptSubstitutions) { + // prompt = prompt.replaceAll(key, root.promptSubstitutions[key]); + // QML/JS doesn't support replaceAll, so use split/join + prompt = prompt.split(key).join(root.promptSubstitutions[key]); + } + return prompt; + } // property var messages: [] property var messageIDs: [] property var messageByID: ({}) @@ -60,6 +69,13 @@ Singleton { property list promptFiles: [...defaultPrompts, ...userPrompts] property list savedChats: [] + property var promptSubstitutions: { + "{DISTRO}": SystemInfo.distroName, + "{DATETIME}": `${DateTime.time}, ${DateTime.collapsedCalendarFormat}`, + "{WINDOWCLASS}": ToplevelManager.activeToplevel.appId, + "{DE}": `${SystemInfo.desktopEnvironment} (${SystemInfo.windowingSystem})` + } + // Gemini: https://ai.google.dev/gemini-api/docs/function-calling // OpenAI: https://platform.openai.com/docs/guides/function-calling property string currentTool: Config?.options.ai.tool ?? "search" diff --git a/.config/quickshell/ii/services/SystemInfo.qml b/.config/quickshell/ii/services/SystemInfo.qml index cb96b54bd..ce7a2067d 100644 --- a/.config/quickshell/ii/services/SystemInfo.qml +++ b/.config/quickshell/ii/services/SystemInfo.qml @@ -20,6 +20,8 @@ Singleton { property string bugReportUrl: "" property string privacyPolicyUrl: "" property string logo: "" + property string desktopEnvironment: "" + property string windowingSystem: "" Timer { triggeredOnStart: true @@ -83,6 +85,20 @@ Singleton { } } + Process { + id: getDesktopEnvironment + running: true + command: ["bash", "-c", "echo $XDG_CURRENT_DESKTOP,$WAYLAND_DISPLAY"] + stdout: StdioCollector { + id: deCollector + onStreamFinished: { + const [desktop, wayland] = deCollector.text.split(",") + root.desktopEnvironment = desktop.trim() + root.windowingSystem = wayland.trim().length > 0 ? "Wayland" : "X11" // Are there others? 🤔 + } + } + } + FileView { id: fileOsRelease path: "/etc/os-release"