-
Notifications
You must be signed in to change notification settings - Fork 3
PromptStyleInfo
Even though the prompt is usually sent ot the LLM as plaintext using the completions API, Pantella still uses a slightly enhanced version of the OpenAI standard chat completions internally to keep everything managed.
{
"role":"system",
"content":"Hello there!"
}This is the most basic a message can be. For compatiblity with chat completions APIs, role must be either assistant, system or user. This signifies to the LLM whether it or the player is speaking, or if there is information that is neither speaking nor roleplay but should be used by the LLM as context. System is what one would use for that contextual message, with user being the player, and assistant being the LLM.
A more ordinary message would be one like this:
{
"role":"assistant",
"name": "Irileth",
"content":"Hi, I'm a big meanie face. *Irileth waves at the stranger.*",
"type": "message"
}The name will be used when parsing the message into a string.
For the purposes of this explanation, lets presume you're using the current default prompt_style:
{
"stop": ["<im_end>","<im_end>", "\""],
"banned_chars": ["{", "}", "\"", "<", "im_", "<im_end"],
"end_of_sentence_chars": [".", "?", "!"],
"BOS_token": "<im_start>",
"EOS_token": "<im_end>",
"message_signifier": ": ",
"role_seperator": "\n",
"message_separator": "\n",
"message_format": "[BOS_token][role][role_seperator][name][message_signifier][content][EOS_token][message_separator]",
"system_name": "system",
"user_name": "user",
"assistant_name": "assistant",
"force_speaker": false,
"roleplay_inverted": false,
"roleplay_prefix": "*",
"roleplay_prefix_aliases": [
"("
],
"roleplay_suffix": "*",
"roleplay_suffix_aliases": [
")"
]
}So if we take that format, [BOS_token][role][role_seperator][name][message_signifier][content][EOS_token][message_signifier], and start replacing parts of it, I'm sure you'll start getting the idea how this works. Lets fill out just what's in the prompt style first:
<im_start>[role]\n[name]: [content]<im_end>\n
And then the rest we can get from each message:
<im_start>assistant\nIrileth: Hi, I'm a big meanie face. *Irileth waves at the stranger.<im_end>\n
This is effectively an entire message ready to go. These are just appended to each other in series. Some helpful context is that that funny little duo \n is actually shorthand for newline, so imagine newlines in place of those. Example:
Irileth: Hi, I'm a big meanie face. *Irileth waves at the stranger.*<im_end>
<im_start>assistant
Irileth: And I have no character development at all in the base game.<im_end>
If you tweak the values in the style of your prompt_style, this will adjust how all messages are formatted. When using completions instead of chat_completions, we can use these user defined formats. When using a chat_completions only API, like OpenAPI, they handle this part of the process(and likely add more shit to the prompt...) and thus we cannot use our user defined styles with those providers. Nothing to fix, just a limitation.
When you start a conversation in Pantella, or respond to a conversation, a prompt is sent to the LLM. This is how that prompt is generally laid out:
1 - [System Message explaining the character's Bio, and the rules at which the LLM has to follow to correctly partake in roleplaying in the world of skyrim.]
2 - [Behaviors Examples - Fake memories added to the conversation defined in each behavior.]
3 - [Behaviors Summary - A large single message that has a summary of all available behaviors for everyone who can talk using this prompt.]
4 - [NPC Memories - Memories recalled from the selected memeory manager (Defaults to Chromadb) are inserted here.]
5 - [System message that declares the start of the conversation, gives an example on how roleplay works, and explains how memories are not part of the current conversation.]
6 - [Any game events that were added between adding the NPC to the conversation and their first response. Usually has the current time.]
7 - [System message that declares the player character is starting a conversation with the NPC.]
8 - [The Present - The current ongoing conversation]
Every prompt, every conversation, is built off this general shape at the moment.
Prompt creation begins in ./src/characters_manager.py, at the get_system_prompt() method. This method calls get_raw_prompt() which checks the type of conversation. It should be one of the following types of conversation: single_player_with_npc, single_npc_with_npc or multi_npc.
These are configurable in the prompt_style JSON under language and then prompts
These strings are automatically formatted by the replacement_dict method, which is different based on the type of conversation but more or less works as you expect.
Lets assume this is a single_player_with_npc conversation.
<im_start>system\n*{name} is a {race} {gendered_age} that lives in Skyrim. {name} can only speak {language}.\n\n{bio}*\n\nSometimes in-game events will be sent as system messages with the text between * symbols. System is not really there, no one will hear what System said, they will just know it. System is the narrator explaining the state of the world. Here is an example:\n\n*{player_name} picked up a pair of gloves*\n\nHere is another:\n\n*{name} dropped a Steel Sword*\n\n{name} is having a conversation with {perspective_player_name} in {location}.\n\nIt is {time12} {time_group}.\n\nContext:\n{context}\n\n\n\nThe following is a conversation that will be spoken aloud between {name} and {perspective_player_name}. {name} will not respond with numbered lists, code, etc. only natural responses to the conversation.<im_end>\n
This is the pre-formatted system message, the entirety of Part 1 of the prompt. The parts of this in brackets are replaced with variables when the context is read with the correct information at it's put at the top.
Currently this is not super configurable by the prompt_style, will change later. But you can change a few parts of it.
<im_start>system
The following messages are examples of how behaviors work. Behaviors are how the assistant can do actions in the game world. If an asterisk roleplay coincides with a behavior the assistant should use the behavior to facilitate the asterisk roleplay in the game world. Here are the the examples of how behaviors work:<im_end>
<im_start>user
Hulda: Give me your money or I'll kill you!<im_end>
<im_start>assistant
Irileth: [Attack] Never, bandit scum!<im_end>
...
<im_start>assistant
Irileth: [Take] Thank you, I appreciate it.<im_end>
<im_start>user
Dragonborn: Can we please trade items?<im_end>
<im_start>assistant
Irileth: [Trade] Of course my friend, what do you need?<im_end>
Here's an abbreviated snippet of what the default should look like. There's a system message at the top that inserts behaviors_explanation_system_message_1 from the prompt_style language into the message. Each message is an example that is included with the behaviors currently.
Lets take a look at the default for behaviors_explanation_system_message_2 from language in your prompt_style:
Only the behaviors demonstrated above are real and exist. Any other word put inside parenthesis will not work. Here is a summary of the available behaviors:\n\n{summaries}
This one is pretty simple. The summaries is built for the behaviors decesptions stacked on top of themselves between new lines.(I think actually double newlines.) These currently aren't configurable, but I don't imagine many people need to change this precise part of the style. I wanna make this more modular later, so this isn't permanent.
Memories are usually just chunks of messages from previous conversations this NPC was a part of. In multiNPC conversations, it presents all memories from all characters preesnt. Chromadb returns the most relevent memory chunks based on your chromadb settings in config.json. not really covered here.
This is another pretty simple one. You can set the value for it in language at memory_present_separator, but the default is:
<im_start>system
A NEW CONVERSATION HAS STARTED. The rest of the messages below this are from the current conversation, the present. Everything above this is a memory from the past. DO NOT RESPOND TO MEMORY MESSAGES. They are for reference only. If you want to do an action, please use asterisks to indicate the action. For example: Do you get to the Cloud District very often? Oh, what am I saying, of course you don't. *Nazeem scowls bitterly at the filthy adventurer.*<im_end>
I use this mostly to be a hard reminder and divider between the fake/imaginary/old information and the real conversation. So far seems to work pretty well. Would love to see other attempts at this.
Basically just what it says on the tin but it felt weird skipping it entirely. The first of these appears before the Introduction Message, and the rest appear before the next response to the LLM. The default for this is:
<im_start>system
It is {time12} {time_group}.<im_end>
This message is a bit neat. The sender of this message can be set in config.json under PromptStyle at conversation_start_role, but it defaults to system. I'm not sure what effect changing it will have, I just thought it might be fun to see what happens if you can change that, maybe for some prompt_styles it'd work bettter to be from the AI/user. Lets take a look at the default under language in your prompt_style, intro_message:
*[player] approaches {name} with the intent to start a conversation with them.*
I have it as a roleplayed action currently to enforce the narrator style, but not sure about that.
This is the conversation you've had with the NPC so far. Are currently having. Have fun!
Game events are hidden messages triggered by the game. Stuff like picking up stuff while talking to someone will be sent as a message just before your next response to the LLM. So if you give them something, they'll prolly see it. You can set the text for these game events in your prompt_style language, the event names are hopefully self-explanatory, but the variables that appear in each of them is very specific to each of them, so don't forget which has which when you change these. {item_name} from OnItemAdded can't be used in OnSpellCase basically. Game events are currently communicated from Skyrim to Pantella via file buffers. There's a txt file generated in your Skyrim directory that Pantella reads from and the game writes to. This is a bit of a hacky solution, a bit out dated since I know there's a better way to do it, but it works for now.
The typical format is as follows:
{line_type}<{game_event_title}>arg1=test|arg2=2|arg3=true|arg4=1,2,3,4,String without commas<end>
This by default is parsed by your selected prompt_style's game_events section. There are some special game events that do not follow the standard in the default prompt_style, but typically they're organized in the same way. First is the line_type, then by game_event_title. The arguemnts are formatted into the strain by name. Addons can also have their own prompt_style.json to add their own game events, or they can use game event renderers to create custom formatters for the game events they want to add if they want to make it more interesting.
If you're a mod author and want to add your own custom game events, read over here: Addons
racial_language is where you can set racial overrides for any part of the language of your prompt style. This will let you set specific races to use non-default languages, have specific ways of speaking, etc. without having to set prompt_style_overrides for all members of a race. Speaking of, prompt_style_override can be set in each character JSON to the string name of your prompt_style file. E.g. nomal_en is used by default behind the scenes to call normal_en.json.
The prompt style is a JSON file that contains all the information needed to format the messages that are sent to the LLM. The prompt style is used to format the messages in a way that the LLM can understand. The prompt style contains the following information:
-
name: The name of the prompt style. -
style: The style of the prompt. This includes the stop characters, banned characters, end of sentence characters, BOS token, EOS token, message signifier, role separator, message separator, message format, system name, user name, assistant name, roleplay inverted, roleplay prefix, roleplay suffix, roleplay prefix aliases, and roleplay suffix aliases.-
stop: The stop characters that are used to determine the end of a message. -
banned_chars: The banned characters that are not allowed in a message. -
end_of_sentence_chars: The end of sentence characters that are used to determine the end of a sentence. -
BOS_token: The beginning of sentence token that is used to indicate the beginning of a sentence. -
EOS_token: The end of sentence token that is used to indicate the end of a sentence. -
message_signifier: The message signifier that is used to separate the role from the content of the message. -
role_seperator: The role separator that is used to separate the roles in a message. -
message_separator: The message separator that is used to separate the messages in a conversation. -
message_format: The message format that is used to format the messages in a conversation. -
system_name: The name of the system role. -
user_name: The name of the user role. -
assistant_name: The name of the assistant role. -
force_speaker: Determines if the speaker is forced to the name of the active character. -
roleplay_inverted: The roleplay inverted that is used to determine if the roleplay is inverted. -
roleplay_prefix: The roleplay prefix that is used to indicate the beginning of a roleplay. -
roleplay_prefix_aliases: The roleplay prefix aliases that are used to indicate the beginning of a roleplay. -
roleplay_suffix: The roleplay suffix that is used to indicate the end of a roleplay. -
roleplay_suffix_aliases: The roleplay suffix aliases that are used to indicate the end of a roleplay.
-
-
language: The language of the prompt. This includes the prompts, in game language name, language name, language code, TTS language code-
prompts: The prompts that are used to format the messages in a conversation. -
in_game_language_name: The in game language name that is used to indicate the in game language. -
language_name: The language name that is used to indicate the language name. -
language_code: The language code that is used to indicate the language code. -
tts_language_code: The TTS language code that is used to indicate the TTS language code. -
race_titles: The title of the races that are used to indicate the title -
age_titles: The age titles that are used to indicate the age titles. -
aged_gendered_titles: The aged gendered titles that are used to indicate the aged gendered titles. -
trust_titles: The trust titles that are used to indicate the trust titles. -
unknown_perspective_name: The unknown perspective name that is used to indicate the unknown perspective name. -
known_perspective_name: The known perspective name that is used to indicate the known perspective name. -
meet_string: The meet string that is used to indicate the meet string. -
memory_present_separator: The memory present separator that is used to indicate the memory present separator. -
behaviors_explanation_system_message_1: The behaviors explanation system message 1 that is used to indicate the behaviors explanation system message 1. -
behaviors_explanation_system_message_2: The behaviors explanation system message 2 that is used to indicate the behaviors explanation system message 2. -
chromadb_memories_explanation: The chromadb memories explanation that is used to indicate the chromadb memories explanation. -
summarizing_memory_prompt: The summarizing memory prompt that is used to indicate the summarizing memory prompt. -
summarizing_memory_explanation: The summarizing memory explanation that is used to indicate the summarizing memory explanation. -
intro_message: The introduction message that is used to indicate the introduction message. -
game_events: The game events that are used to indicate the game events. You can add custom game events by creating an addon.-
time_update: The time update that is used to indicate the time update. -
player_started_combat: The player started combat that is used to indicate the player started combat. -
player: The player that is used to indicate the player.-
OnItemAdded: The on item added that is used to indicate the on item added. -
OnItemAddedFromDestination: The on item added from destination that is used to indicate the on item added from destination. -
OnItemRemoved: The on item removed that is used to indicate the on item removed. -
OnItemRemovedToDestination: The on item removed to destination that is used to indicate the on item removed to destination. -
OnSpellCast: The on spell cast that is used to indicate the on spell cast. -
OnHit: The on hit that is used to indicate the on hit. -
OnHitFromSource: The on hit from source that is used to indicate the on hit from source. -
OnLocationChange: The on location change that is used to indicate the on location change. -
OnObjectEquipped: The on object equipped that is used to indicate the on object equipped. -
OnObjectUnequipped: The on object unequipped that is used to indicate the on object unequipped. -
OnBowShot: The on bow shot that is used to indicate the on bow shot. -
OnBowShotAmmoNamed: The on bow shot ammo named that is used to indicate the on bow shot ammo named. -
OnBowShotWeaponNamed: The on bow shot weapon named that is used to indicate the on bow shot weapon named. -
OnBowShotAmmoNamedWeaponNamed: The on bow shot ammo named weapon named that is used to indicate the on bow shot ammo named weapon named. -
OnSit: The on sit that is used to indicate the on sit. -
OnGetUp: The on get up that is used to indicate the on get up. -
OnVampireFeed: The on vampire feed that is used to indicate the on vampire feed. -
OnFastTravelEnd: The on fast travel end that is used to indicate the on fast travel end. -
OnVampirismStateChangedTrue: The on vampirism state changed true that is used to indicate the on vampirism state changed true. -
OnVampirismStateChangedFalse: The on vampirism state changed false that is used to indicate the on vampirism state changed false. -
OnLycanthropyStateChangedTrue: The on lycanthropy state changed true that is used to indicate the on lycanthropy state changed true. -
OnLycanthropyStateChangedFalse: The on lycanthropy state changed false that is used to indicate the on lycanthropy state changed false.
-
-
npc: The npc that is used to indicate the npc.-
OnItemAdded: The on item added that is used to indicate the on item added. -
OnItemAddedFromDestination: The on item added from destination that is used to indicate the on item added from destination. -
OnItemRemoved: The on item removed that is used to indicate the on item removed. -
OnItemRemovedToDestination: The on item removed to destination that is used to indicate the on item removed to destination. -
OnSpellCast: The on spell cast that is used to indicate the on spell cast. -
OnHit: The on hit that is used to indicate the on hit. -
OnHitFromSource: The on hit from source that is used to indicate the on hit from source. -
OnLocationChange: The on location change that is used to indicate the on location change. -
OnObjectEquipped: The on object equipped that is used to indicate the on object equipped. -
OnObjectUnequipped: The on object unequipped that is used to indicate the on object unequipped. -
OnBowShot: The on bow shot that is used to indicate the on bow shot. -
OnBowShotAmmoNamed: The on bow shot ammo named that is used to indicate the on bow shot ammo named. -
OnBowShotWeaponNamed: The on bow shot weapon named that is used to indicate the on bow shot weapon named. -
OnBowShotAmmoNamedWeaponNamed: The on bow shot ammo named weapon named that is used to indicate the on bow shot ammo named weapon named. -
OnSit: The on sit that is used to indicate the on sit. -
OnGetUp: The on get up that is used to indicate the on get up. -
OnVampireFeed: The on vampire feed that is used to indicate the on vampire feed. -
OnFastTravelEnd: The on fast travel end that is used to indicate the on fast travel end. -
OnVampirismStateChangedTrue: The on vampirism state changed true that is used to indicate the on vampirism state changed true. -
OnVampirismStateChangedFalse: The on vampirism state changed false that is used to indicate the on vampirism state changed false. -
OnLycanthropyStateChangedTrue: The on lycanthropy state changed true that is used to indicate the on lycanthropy state changed true. -
OnLycanthropyStateChangedFalse: The on lycanthropy state changed false that is used to indicate the on lycanthropy state changed false.
-
-
-
banned_learnable_names: The banned learnable names that are used to indicate the banned learnable names. -
predetermined_npc_greetings: The predetermined NPC greetings that are used to indicate the predetermined NPC greetings. -
predetermined_player_greetings: The predetermined player greetings that are used to indicate the predetermined player greetings. -
end_conversation_keywords: The end conversation keywords that are used to indicate the end conversation keywords. -
goodbye_npc_responses: The goodbye NPC responses that are used to indicate the goodbye NPC responses. -
first_message_hidden_symbol: The first message hidden symbol that is used to indicate the first message hidden symbol. -
message_hidden_symbol: The message hidden symbol that is used to indicate the message hidden symbol. -
allow_npc_roleplay: The allow NPC roleplay that is used to indicate if the NPC roleplay is allowed. -
behavior_example_insertion: The behavior example insertion that is used to indicate if the behavior example insertion is allowed. -
include_behavior_explanation: The include behavior explanation that is used to indicate if the behavior explanation is included.
-
-
racial_language: The racial language of the prompt. This includes the age titles, aged gendered titles, trust titles, unknown perspective name, known perspective name, meet string, memory present separator, behaviors explanation system message 1, behaviors explanation system message 2, chromadb memories explanation, summarizing memory prompt, summarizing memory explanation, intro message, game events, banned learnable names, predetermined NPC greetings, predetermined player greetings, end conversation keywords, goodbye NPC responses, first message hidden symbol, message hidden symbol, allow NPC roleplay, behavior example insertion, include behavior explanation-
Argonian: The Argonian racial language that is used to indicate the Argonian racial language.-
age_titles: The age titles that are used to indicate the age titles. -
aged_gendered_titles: The aged gendered titles that are used to indicate the aged gendered titles.
-
-
Khajiit: The Khajiit racial language that is used to indicate the Khajiit racial language.-
age_titles: The age titles that are used to indicate the age titles. -
aged_gendered_titles: The aged gendered titles that are used to indicate the aged gendered titles.
-
-