kwaroran 2f251811c1 fix: re‑implement prompt text storage without memo field (#860)
# 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
## Related PRs

- This PR replaces the previous implementation in
[#848](https://github.com/kwaroran/RisuAI/pull/848).

---

## Problem

- After [#848](https://github.com/kwaroran/RisuAI/pull/848), input token
counts and `\n\n` spacing changed (e.g. custom API & OpenAI compatible
models).
- Before, I used the `memo` field in each message to help get **the
final, parsed and pre-processed prompt template** from the `formated`
array for storage.
- But the `memo` field is used in `pushPrompts()` to decide when to
merge strings inside `formated`:

```js
// Existing code
if (chat.role === 'system') {
    const endf = formated.at(-1)
    if (endf && endf.role === 'system' && endf.memo === chat.memo && endf.name === chat.name) {
        formated[formated.length - 1].content += '\n\n' + chat.content
    }
}
```
- Therefore, relying on `memo` produced wrong results.


## Solution
- Rolled back all `memo` logic (For a clean diff, compare with 040652d,
the last version before the memo logic was added).
- Added `pushPromptInfoBody()` (independent of global `formated`):

```js
function pushPromptInfoBody(role, fmt, promptBody) {
    if (!fmt.trim()) return;
    promptBody.push({
        role: role,
        content: risuChatParser(fmt),
    });
}
```
- Prompt text is now collected in a single switch(`card.type`) block,
without needing to filter with `memo` or external fields.


## Result

Prompt text is still stored per message without side effects.


## Considerations (commit
[8dc05cc](8dc05ccace))

- Extracting only the original `globalNote` is hard unless parser order
is changed.
1. When `positionParser` is called first, sections marked as `position`
are inserted early, making it impossible to extract only the prompt
template afterward.
2. If `risuChatParser` is called separately **just to save the prompt
text**, the saved prompt may differ from the actual prompt sent,
especially in cases involving `{{random}}` values.
- Reordering the function calls might help, but since it could change
the prompt that is actually sent and cause differences from the previous
output, it may be better to leave things as they are.
- Personally, I tend to avoid using `position` in main system prompts;
adding it often makes the main prompt structure a bit messy (Using
`position` is very useful for things that change frequently, such as
bots or personas)
- Global notes are typically used for individual bots, rather than as
prompts shared globally, so skipping them here has no functional
drawback, I think.
- The **Custom Inner Format** fields such as authorNote, persona,
description, and memory mainly serve as labels, so things like
`{{random}}` are rarely used here. For this reason, I used **2(only
`risuChatParser` is called just to save the prompt text)** in this
context.

## Final Note

Sorry for any inconvenience! If you have questions or feedback, please
let me know.
2025-05-24 20:26:42 +09:00
2025-05-18 17:24:27 +09:00
2024-09-06 02:45:49 +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
2024-10-13 01:29:12 +09:00
2025-03-10 13:14:20 +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
2024-10-13 01:46:57 +09:00
2025-03-20 12:08:34 +09:00
2025-05-17 01:42:08 +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%