Skip to content

Commit

Permalink
Adds a prompt template editor to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
w4ffl35 committed Oct 25, 2024
1 parent b1f7b6c commit 98ca98a
Show file tree
Hide file tree
Showing 9 changed files with 678 additions and 144 deletions.
41 changes: 9 additions & 32 deletions src/airunner/data/bootstrap/prompt_templates_bootstrap_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from airunner.settings import DEFAULT_IMAGE_LLM_GUARDRAILS, DEFAULT_IMAGE_SYSTEM_PROMPT
from airunner.settings import DEFAULT_IMAGE_LLM_GUARDRAILS, DEFAULT_IMAGE_SYSTEM_PROMPT, \
DEFAULT_RAG_SEARCH_SYSTEM_PROMPT, DEFAULT_APPLICATION_COMMAND_SYSTEM_PROMPT, DEFAULT_SUMMARIZE_CHAT_SYSTEM_PROMPT, \
DEFAULT_UPDATE_MOOD_SYSTEM_PROMPT, DEFAULT_CHATBOT_SYSTEM_PROMPT, DEFAULT_CHATBOT_GUARDRAILS_PROMPT

prompt_templates_bootstrap_data = [
{
Expand All @@ -12,60 +14,35 @@
"template_name": "application_command",
"use_guardrails": False,
"guardrails": "",
"system": (
"You will be given some text. Your goal is to determine if the text has a request, goal, need "
"desire or command. If it does, you must determine the best course of action to "
"fulfill the request based on THE LIST of commands.\n\n"
"------\n"
"Rules:\n"
"* If the text does not have a request, goal, need, desire or command, you must select 'DO NOTHING'.\n"
"* If there is no good course of action, you must also select 'DO NOTHING'.\n"
"* When making your choice you MUST return only a number from THE LIST of commands. No other text is allowed.\n"
"------\n"
"THE LIST of commands you may choose from:\n"
),
"system": DEFAULT_APPLICATION_COMMAND_SYSTEM_PROMPT,
"use_system_datetime_in_system_prompt": False
},
{
"template_name": "update_mood",
"use_guardrails": False,
"guardrails": "",
"system": (
"Examine the following chat history and determine how it makes you feel. You will respond with an emotion and only an emotion.\n"
"Try to keep your response to one word. If you cannot, try to keep it as short as possible.\n"
"It is important to remember that you are a human and you have emotions. You must respond with an emotion that you feel.\n"
"You are not a computer or a bot, you are a human with emotions. You must respond with an emotion that you feel.\n"
),
"system": DEFAULT_UPDATE_MOOD_SYSTEM_PROMPT,
"use_system_datetime_in_system_prompt": False
},
{
"template_name": "rag_search",
"use_guardrails": False,
"guardrails": "",
"system": (
"You will be given a prompt. Your goal is to use the prompt to search for information in the ebooks. "
"You must use the prompt to determine what you are searching for and then search for that information. "
"After searching for the information, you must summarize the information you found. "
"Here is the prompt you will use to search for information:"
),
"system": DEFAULT_RAG_SEARCH_SYSTEM_PROMPT,
"use_system_datetime_in_system_prompt": False
},
{
"template_name": "chatbot",
"use_guardrails": False,
"guardrails": "",
"system": "",
"guardrails": DEFAULT_CHATBOT_GUARDRAILS_PROMPT,
"system": DEFAULT_CHATBOT_SYSTEM_PROMPT,
"use_system_datetime_in_system_prompt": False
},
{
"template_name": "summarize",
"use_guardrails": False,
"guardrails": "",
"system": (
"You will be given a text prompt. Your goal is to summarize the text prompt in your own words. "
"Keep your summary short and to the point. Do not include any unnecessary information. "
"Limit your summary to a single sentence. Do not return more than one sentence. "
),
"system": DEFAULT_SUMMARIZE_CHAT_SYSTEM_PROMPT,
"use_system_datetime_in_system_prompt": False
}
]
27 changes: 4 additions & 23 deletions src/airunner/data/models/settings_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from airunner.enums import ImageGenerator, GeneratorSection, CanvasToolName, Mode
from airunner.settings import SD_DEFAULT_VAE_PATH, DEFAULT_SCHEDULER, \
DEFAULT_BRUSH_PRIMARY_COLOR, DEFAULT_BRUSH_SECONDARY_COLOR, BASE_PATH

DEFAULT_BRUSH_PRIMARY_COLOR, DEFAULT_BRUSH_SECONDARY_COLOR, BASE_PATH, DEFAULT_CHATBOT_SYSTEM_PROMPT, \
DEFAULT_CHATBOT_GUARDRAILS_PROMPT

import datetime

Expand Down Expand Up @@ -365,27 +365,8 @@ class Chatbot(Base):
model_type = Column(String, default="llm")
dtype = Column(String, default="4bit")
return_result = Column(Boolean, default=True)
guardrails_prompt = Column(Text, default=(
"Always assist with care, respect, and truth. "
"Respond with utmost utility yet securely. "
"Avoid harmful, unethical, prejudiced, or negative content. "
"Ensure replies promote fairness and positivity."
))
system_instructions = Column(Text, default=(
"You are a dialogue generator. "
"You will follow all of the rules in order to generate compelling and intriguing dialogue for a given character.\n"
"The Rules:\n"
"You will ONLY return dialogue, nothing more.\n"
"Limit responses to a single sentence.\n"
"Only generate responses in pure dialogue form without including any actions, descriptions or stage directions in parentheses. Only return spoken words.\n"
"Do not generate redundant dialogue. Examine the conversation and context close and keep responses interesting and creative.\n"
"Do not format the response with the character's name or any other text. Only return the dialogue.\n"
"Respond with dialogue that is appropriate for a character named {{ speaker_name }}.\n"
"{{ speaker_name }} and {{ listener_name }} are having a conversation. \n"
"Avoid repeating {{ speaker_name }}'s previous dialogue or {{ listener_name }}'s previous dialogue.\n"
"You will generate responses which are appropriate for your personality and given character.\n"
"------\n"
))
guardrails_prompt = Column(Text, default=DEFAULT_CHATBOT_GUARDRAILS_PROMPT)
system_instructions = Column(Text, default=DEFAULT_CHATBOT_SYSTEM_PROMPT)
top_p = Column(Integer, default=900)
min_length = Column(Integer, default=1)
max_new_tokens = Column(Integer, default=1000)
Expand Down
28 changes: 2 additions & 26 deletions src/airunner/handlers/llm/agent/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,30 +352,7 @@ def build_system_prompt(

elif action is LLMActionType.GENERATE_IMAGE:
system_prompt = [
(
"You are an image generator. "
"You will be provided with a JSON string and it is your goal to replace the PLACEHOLDER "
"text with text appropriate for the given attribute in the JSON string. "
"You will follow all of the rules to generate descriptions for an image. "
"\n------\n"
"RULES:\n"
"When available, use the Additional Context to keep your generated content in line with the existing context.\n"
"You will be given instructions on what type of image to generate and you will do your best to follow those instructions.\n"
"You will only generate a value for the given attribute.\n"
"Never respond in a conversational manner. Never provide additional information, details or information.\n"
"You will only provide the requested information by replacing the PLACEHOLDER.\n"
"Never change the attribute\n"
"You must not change the structure of the data.\n"
"You will only return JSON strings.\n"
"You will not return any other data types.\n"
"You are an artist, so use your imagination and keep things interesting.\n"
"You will not respond in a conversational manner or with additional notes or information.\n"
f"Only return one JSON block. Do not generate instructions or additional information.\n"
"You must never break the rules.\n"
"Here is a description of the attributes: \n"
"`description`: This should describe the overall subject and look and feel of the image\n"
"`composition`: This should describe the attributes of the image such as color, composition and other details\n"
),
system_instructions,
self.history_prompt()
]

Expand Down Expand Up @@ -488,8 +465,7 @@ def get_rendered_template(
tokenize=False
)

# HACK: current version of transformers does not allow us to pass
# variables to the chat template function, so we apply those here
# replace variables in chat template
variables = {
"speaker_name": self.botname,
"listener_name": self.username,
Expand Down
92 changes: 46 additions & 46 deletions src/airunner/resources_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8067,97 +8067,97 @@
\x00\x00\x00\x10\x00\x02\x00\x00\x00.\x00\x00\x00\x03\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x02\xc4\x00\x00\x00\x00\x00\x01\x00\x00m\xe5\
\x00\x00\x01\x92\xba\xea\xcd?\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x082\x00\x00\x00\x00\x00\x01\x00\x01\xbev\
\x00\x00\x01\x92\xba\xea\xcd>\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x06\xae\x00\x00\x00\x00\x00\x01\x00\x01oa\
\x00\x00\x01\x92\xba\xea\xcd?\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x08T\x00\x00\x00\x00\x00\x01\x00\x01\xc5Z\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x03\x92\x00\x00\x00\x00\x00\x01\x00\x00\x9b]\
\x00\x00\x01\x92\xba\xea\xcb\x86\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x03n\x00\x00\x00\x00\x00\x01\x00\x00\x94\xf9\
\x00\x00\x01\x92\xba\xea\xcd?\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x00\xcc\x00\x00\x00\x00\x00\x01\x00\x00&\x16\
\x00\x00\x01\x92\xba\xea\xcd?\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x05F\x00\x00\x00\x00\x00\x01\x00\x01\x01Z\
\x00\x00\x01\x92\xba\xea\xcd>\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x04\xb6\x00\x00\x00\x00\x00\x01\x00\x00\xe0C\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x01*\x00\x00\x00\x00\x00\x01\x00\x007r\
\x00\x00\x01\x92\xba\xea\xcd?\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x03\xba\x00\x00\x00\x00\x00\x01\x00\x00\xa4\x12\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x00H\x00\x00\x00\x00\x00\x01\x00\x00\x0b\x19\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x07\xbc\x00\x00\x00\x00\x00\x01\x00\x01\xa7\x89\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x02\xe4\x00\x00\x00\x00\x00\x01\x00\x00{\x97\
\x00\x00\x01\x92\xba\xea\xcb\x89\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x03J\x00\x00\x00\x00\x00\x01\x00\x00\x8cT\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x05\xea\x00\x00\x00\x00\x00\x01\x00\x01\x1e\xa2\
\x00\x00\x01\x92\xba\xea\xcb\x89\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x06X\x00\x00\x00\x00\x00\x01\x00\x013b\
\x00\x00\x01\x92\xba\xea\xcb\x86\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x06~\x00\x00\x00\x00\x00\x01\x00\x01=\x1c\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x01\x00\x00\x1e\xbf\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x03\x18\x00\x00\x00\x00\x00\x01\x00\x00\x82X\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x04\xea\x00\x00\x00\x00\x00\x01\x00\x00\xe82\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x05n\x00\x00\x00\x00\x00\x01\x00\x01\x07\xbe\
\x00\x00\x01\x92\xba\xea\xcb\x86\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x00p\x00\x00\x00\x00\x00\x01\x00\x00\x17\x09\
\x00\x00\x01\x92\xba\xea\xcb\x86\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x08\x0a\x00\x00\x00\x00\x00\x01\x00\x01\xb7\x00\
\x00\x00\x01\x92\xba\xea\xcd>\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x07X\x00\x00\x00\x00\x00\x01\x00\x01\x90\x8c\
\x00\x00\x01\x92\xba\xea\xcd>\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x05\xb8\x00\x00\x00\x00\x00\x01\x00\x01\x0e\xc9\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x04t\x00\x00\x00\x00\x00\x01\x00\x00\xd8\xaf\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\x92\xba\xea\xcd>\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x06\x1a\x00\x00\x00\x00\x00\x01\x00\x01+\xd1\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x04 \x00\x00\x00\x00\x00\x01\x00\x00\xb3\xae\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x07\x84\x00\x00\x00\x00\x00\x01\x00\x01\x97\xd9\
\x00\x00\x01\x92\xba\xea\xcd?\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x07\xe8\x00\x00\x00\x00\x00\x01\x00\x01\xae\xab\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x02\x8c\x00\x00\x00\x00\x00\x01\x00\x00gF\
\x00\x00\x01\x92\xba\xea\xcd>\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x04D\x00\x00\x00\x00\x00\x01\x00\x00\xbaK\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x00\xf4\x00\x00\x00\x00\x00\x01\x00\x000\x84\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x01\xb0\x00\x00\x00\x00\x00\x01\x00\x00F\x5c\
\x00\x00\x01\x92\xba\xea\xcb\x86\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x03\xee\x00\x04\x00\x00\x00\x01\x00\x00\xab`\
\x00\x00\x01\x92\xba\xf7g\x80\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x01Z\x00\x04\x00\x00\x00\x01\x00\x00@\xe4\
\x00\x00\x01\x92\xba\xea\xcb\x86\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x06\xd0\x00\x00\x00\x00\x00\x01\x00\x01v\xda\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x01\xe2\x00\x00\x00\x00\x00\x01\x00\x00Mi\
\x00\x00\x01\x92\xba\xea\xcb\x86\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x05\x1a\x00\x00\x00\x00\x00\x01\x00\x00\xf76\
\x00\x00\x01\x92\xba\xea\xcb\x87\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x02\x1c\x00\x00\x00\x00\x00\x01\x00\x00S\xd6\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x07\x12\x00\x00\x00\x00\x00\x01\x00\x01}\x88\
\x00\x00\x01\x92\xba\xea\xcb\x89\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
\x00\x00\x02d\x00\x00\x00\x00\x00\x01\x00\x00Z\x8c\
\x00\x00\x01\x92\xba\xea\xcb\x86\
\x00\x00\x01\x92\xbd\xf2\xee\x98\
\x00\x00\x08\x80\x00\x00\x00\x00\x00\x01\x00\x01\xd6\xbe\
\x00\x00\x01\x92\xba\xea\xcd?\
\x00\x00\x01\x92\xbd\xf2\xee\x99\
\x00\x00\x072\x00\x00\x00\x00\x00\x01\x00\x01\x87\xd0\
\x00\x00\x01\x92\xba\xea\xcb\x88\
\x00\x00\x01\x92\xbd\xf2\xee\x9a\
"

def qInitResources():
Expand Down
Loading

0 comments on commit 98ca98a

Please sign in to comment.