kwaroran 19d50d1ef1 feat: add optional prompt metadata saving to chat messages (#848)
# PR Checklist
- [ ] Have you checked if it works normally in all models? *Ignore this
if it doesn't use models.*
- [x] Have you checked if it works normally in all web, local, and node
hosted versions? If it doesn't, have you blocked it in those versions?
- [x] Have you added type definitions?

# Description
## What does this PR do?

This PR adds an optional feature to store prompt preset metadata in each
chat message.

<img width="311" alt="prompt"
src="https://github.com/user-attachments/assets/2591ac25-6cb2-41fc-85b2-e12c35b79370"
/>

---

## Why is this useful?

When writing prompts, it's common to test **dozens of prompt presets**
across many messages. After just a day or two, it's hard to remember
which message used which prompt.
This is especially important for sensitive models, where even small
changes to prompt wording or toggle combinations can greatly affect
output.

---

## What is stored when enabled?

To support this, an option has been added to **Advanced Settings** that
stores:

- Prompt preset name (*Add Prompt Info to Chat*)
- Active custom toggles (*Add Prompt Info to Chat*)
- Prompt text (*Add Prompt *Text* To Chat*):
Only the **Prompt Template** portion of the final prompt (**as sent**)
is stored — character description, persona, lorebook, and long-term
memory are excluded to avoid excessive size.
    This option is separated due to its potential impact on storage.

This information is stored per message, if the feature is enabled.

<img width="319" alt="setting"
src="https://github.com/user-attachments/assets/00600d0c-d38d-46cf-890f-3f08d78ccb0a"
/>

---

## Implementation Summary

### `src/ts/storage/database.svelte.ts`

- Added `interface MessagePresetInfo` (includes `promptName`,
`promptToggles`, `promptText`)
- Updated `interface Message` with optional `promptInfo`

### `src/ts/process/index.svelte.ts`

- In `sendChat()`, prompt metadata is collected and stored
- `promptText` is taken from the existing `formated` array, but only
after filtering out types like `'persona'`, `'description'`,
`'authornote'`, `'memory'`
- Since `formated` is reused, this had to be placed in the **later**
part of the `sendChat` function.
- However, `promptName` and `promptToggles` are collected **early** to
avoid mismatches caused by user changes during message sending. *(A
short comment has been added to explain the code separation. See
screenshot below.)*
<img width="494" alt="comment"
src="https://github.com/user-attachments/assets/b43da333-d529-4b3c-b659-579b847135a5"
/>

- Used this condition when storing partial prompt data (As you can see,
these are the types that support Custom Inner Format.):

```ts
// only for types supporting Custom Inner Format
if (DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat) {
    pushPromptInfoBody('supaMemory', card.innerFormat)
}
```

- The final `promptInfo` is added to the message object during
`message.push`

---

## Additional Notes

- The prompt preset name and active toggles take up very little space,
so they are unlikely to be an issue.
- The prompt text may increase the message size slightly, but:
- Modern models already generate outputs of several thousand tokens, so
adding \~2,000 tokens of metadata is relatively minor in comparison.
  - The `{{slot}}` contents are not included in the saved text.
- The prompt text is filtered through `risuChatParser`, which reduces
unnecessary parts before saving.
- Most importantly, this feature is optional and can be enabled only by
those who need it — for example, prompt creators or advanced users.

---

## Final Thoughts

This feature is designed to help prompt creators **track, debug, and
revisit** messages more easily.
If this feature doesn't fit the project goals or introduces any
concerns, feel free to let me know or suggest changes.
It might also be interesting to allow users to write a note for each
message!

Thanks for reading.
2025-05-17 01:08:11 +09:00
2024-12-25 22:27:48 +09:00
2024-09-06 02:45:49 +09:00
2023-07-07 06:30:04 +09:00
2025-03-16 19:41:06 +09:00
2024-01-01 23:14:58 +09:00
2025-04-18 13:18:37 +09:00
2025-04-28 16:09:29 +09:00
2024-10-13 01:29:12 +09:00
2025-04-14 15:28:14 +09:00
2025-03-10 13:14:20 +09:00
2023-07-08 15:24:18 +09:00
2024-01-01 23:14:58 +09:00
2025-02-26 22:26:15 +09:00
2024-09-10 22:09:58 +09:00
2025-04-28 16:09:29 +09:00
2025-04-28 16:09:29 +09:00
2024-10-13 01:46:57 +09:00
2025-03-20 12:08:34 +09:00
2025-02-15 21:29:37 +09:00
2024-10-25 18:11:00 +09:00

RisuAI

text

Svelte Typescript Tauri

RisuAI, or Risu for short, is a cross platform AI chatting software / web application with powerful features such as multiple API support, assets in the chat, regex functions and much more.

Screenshots

Screenshot 1 Screenshot 2
Screenshot 1 Screenshot 2
Screenshot 3 Screenshot 4

Features

  • Multiple API Supports: Supports OAI, Claude, Ooba, OpenRouter... and More!
  • Emotion Images: Display the image of the current character, according to his/her expressions!
  • Group Chats: Multiple characters in one chat.
  • Plugins: Add your features and providers, and simply share.
  • Regex Script: Modify model's output by regex, to make a custom GUI and others
  • Powerful Translators: Automatically translate the input/output, so you can roleplay without knowing model's language.
  • Lorebook: Also known as world infos or memory book, which can make character memorize more.
  • Themes: Choose it from 3 themes, Classic, WaifuLike, WaifuCut.
  • Powerful Prompting: Change the prompting order easily, Impersonate inside prompts, Use conditions, variables... and more!
  • Customizable, Friendly UI: Great Accessibility and mobile friendly
  • TTS: Use TTS to make the output text into voice.
  • Additonal Assets: Embed your images, audios and videos to bot, and make it display at chat or background!
  • And More!

You can get detailed information on https://github.com/kwaroran/RisuAI/wiki (Work in Progress)

Discord

Installation

Docker Installation

You can also run RisuAI using Docker. This method is particularly useful for web hosting.

  1. Clone the repository:

    git clone https://github.com/kwaroran/RisuAI.git
    cd RisuAI
    
  2. Build and run the Docker container:

    docker-compose up -d
    
  3. Access RisuAI at http://localhost:6001 in your web browser.

Description
No description provided
Readme 62 MiB
Languages
TypeScript 58.9%
Svelte 35.1%
JavaScript 4.4%
Rust 0.5%
Lua 0.3%
Other 0.7%