You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a lorebook in an LLM Frontend SillyTavern with yaml. A lorebook consists of entries, which are plain text that are possibly sent to LLM as system prompts depending on whether user's prompts mention their corresponding keywords.
How lorebook works with my weapon document entries
The above is my weapon document in a lorebook. Entries of it are separated from a single yaml file with my python script, where a comment starting with a ^ indicates that the following content belongs to a new entry. For example,
---
# ^===Weapon Document - Begin===description: This document defines various weapon categories and their properties# ^===Melee - Start===Melee:
# ^SwordSword:
- Single-edged/Double-edged blade
- Thrusting and slashing# ^===Melee - End===# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them
...
Note that I use both --- and ... because there're other entries in my lorebook, so I must remind LLM where my weapon document starts and ends.
Problem
LLM treats spaces and newlines as tokens as well. To save tokens, I use yq '... style="flow"' file.yaml to transform my yaml files into flow style before I push it into my lorebook, but this breaks my indicator comments:
---
# ^===Weapon Document - Begin==={description: This document defines various weapon categories and their properties,# ^===Melee - Start===Melee: {# ^SwordSword: [Single-edged/Double-edged blade, Thrusting and slashing]},# ^===Melee - End===# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them}
}, is apended to the end of the Sword entry - a conditional entry that may not be sent to LLM if it's keyword isn't in user's prompts. If that's the case, the yaml structure breaks:
---
{description: This document defines various weapon categories and their properties,Melee: {rule: assistant should read this weapon document carefully and recall it when characters using them}
Expected Output
---
# ^===Weapon Document - Begin==={description: This document defines various weapon categories and their properties,# ^===Melee - Start===Melee: {# ^SwordSword: [Single-edged/Double-edged blade, Thrusting and slashing]# ^===Melee - End===},# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them}
Failed Tries
I tried to add spaces before ^==Melee - end== or put it in other places but failed:
===Melee - End=== is treated as level 3 comment
---
# ^===Weapon Document - Begin===description: This document defines various weapon categories and their properties# ^===Melee - Start===Melee:
# ^SwordSword:
- Single-edged/Double-edged blade
- Thrusting and slashing# ^===Melee - End===# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them
...
---
# ^===Weapon Document - Begin==={description: This document defines various weapon categories and their properties,# ^===Melee - Start===Melee: {# ^SwordSword: [Single-edged/Double-edged blade, Thrusting and slashing,# ^===Melee - End===]},# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them}
===Melee - End=== is treated as level 3 comment
---
# ^===Weapon Document - Begin===description: This document defines various weapon categories and their properties# ^===Melee - Start===Melee:
# ^SwordSword:
- Single-edged/Double-edged blade
- Thrusting and slashing# ^===Melee - End===# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them
...
---
# ^===Weapon Document - Begin==={description: This document defines various weapon categories and their properties,# ^===Melee - Start===Melee: {# ^SwordSword: [Single-edged/Double-edged blade, Thrusting and slashing,# ^===Melee - End===]},# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them}
===Melee - End=== appended to the end of the array element is treated as level 3 comment and of course appended to the end
---
# ^===Weapon Document - Begin===description: This document defines various weapon categories and their properties# ^===Melee - Start===Melee:
# ^SwordSword:
- Single-edged/Double-edged blade
- Thrusting and slashing # ^===Melee - End===# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them
...
---
# ^===Weapon Document - Begin==={description: This document defines various weapon categories and their properties,# ^===Melee - Start===Melee: {# ^SwordSword: [Single-edged/Double-edged blade, Thrusting and slashing, # ^===Melee - End===]},# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them}
Workaround
The expected output could be done with an odd trick:
---
# ^===Weapon Document - Begin===description: This document defines various weapon categories and their properties# ^===Melee - Start===Melee:
# ^SwordSword:
- Single-edged/Double-edged blade
- Thrusting and slashing# dummy# ^===Melee - End===# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them
...
---
# ^===Weapon Document - Begin==={description: This document defines various weapon categories and their properties,# ^===Melee - Start===Melee: {# ^SwordSword: [Single-edged/Double-edged blade, Thrusting and slashing,# dummy],# ^===Melee - End===},# ^===Weapon Document - End===rule: assistant should read this weapon document carefully and recall it when characters using them}
To summarize, is there a way to specify the nesting levels of comments so I can get the expected output without such trick?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Background
I'm writing a lorebook in an LLM Frontend SillyTavern with yaml. A lorebook consists of entries, which are plain text that are possibly sent to LLM as system prompts depending on whether user's prompts mention their corresponding keywords.
How lorebook works with my
weapon document
entriesThe above is my
weapon document
in a lorebook. Entries of it are separated from a single yaml file with my python script, where a comment starting with a^
indicates that the following content belongs to a new entry. For example,Note that I use both
---
and...
because there're other entries in my lorebook, so I must remind LLM where myweapon document
starts and ends.Problem
LLM treats spaces and newlines as tokens as well. To save tokens, I use
yq '... style="flow"' file.yaml
to transform my yaml files into flow style before I push it into my lorebook, but this breaks my indicator comments:},
is apended to the end of the Sword entry - a conditional entry that may not be sent to LLM if it's keyword isn't in user's prompts. If that's the case, the yaml structure breaks:Expected Output
Failed Tries
I tried to add spaces before
^==Melee - end==
or put it in other places but failed:===Melee - End===
is treated as level 3 comment===Melee - End===
is treated as level 3 comment===Melee - End===
appended to the end of the array element is treated as level 3 comment and of course appended to the endWorkaround
The expected output could be done with an odd trick:
To summarize, is there a way to specify the nesting levels of comments so I can get the expected output without such trick?
Beta Was this translation helpful? Give feedback.
All reactions