Implement a priority for prompt injections in CC (#3978) * Implement a priority for prompt injections in CC Adds a numeric order for injected prompts, 0 being default and placed at the top, and higher numbers placing further down. If two messages have the same priority, then order is determined by role as was before. * Update data-i18n for new setting field * Rename priority to order, sort higher first/lower last * Hide order when position is relative, adjust hint text * Fix type error * Fix capitalization * Cut UI texts * Reposition text labels --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

8100a542e2e97d420aa8c3368cc3ab34ef5d472c

Kristian Schlikow <Dakraid@users.noreply.github.com>

Signed
18 files changed, +86 -48Showing whitespace changes
public/index.html+12 -8
@@ -6442,21 +6442,19 @@
64426442 <label for="completion_prompt_manager_popup_entry_form_name">
64436443 <span data-i18n="prompt_manager_name">Name</span>
64446444 </label>
6445- <div class="text_muted" data-i18n="A name for this prompt.">A name for this prompt.</div>
64466445 <input id="completion_prompt_manager_popup_entry_form_name" class="text_pole" type="text" name="name" />
6446+ <div class="text_muted" data-i18n="A name for this prompt.">A name for this prompt.</div>
64476447 </div>
64486448 <div class="completion_prompt_manager_popup_entry_form_control flex1">
64496449 <label for="completion_prompt_manager_popup_entry_form_role">
64506450 <span data-i18n="Role">Role</span>
64516451 </label>
6452- <div class="text_muted">
6453- <span data-i18n="To whom this message will be attributed.">To whom this message will be attributed.</span>
6454- </div>
64556452 <select id="completion_prompt_manager_popup_entry_form_role" class="text_pole" name="role">
64566453 <option data-i18n="System" value="system">System</option>
64576454 <option data-i18n="User" value="user">User</option>
64586455 <option data-i18n="AI Assistant" value="assistant">AI Assistant</option>
64596456 </select>
6457+ <div class="text_muted" data-i18n="To whom this message will be attributed.">To whom this message will be attributed.</div>
64606458 </div>
64616459 </div>
64626460 <div class="flex-container gap10px">
@@ -6464,18 +6462,25 @@
64646462 <label for="completion_prompt_manager_popup_entry_form_injection_position">
64656463 <span data-i18n="prompt_manager_position">Position</span>
64666464 </label>
6467- <div class="text_muted" data-i18n="Injection position. Relative (to other prompts in prompt manager) or In-chat @ Depth.">Injection position. Relative (to other prompts in prompt manager) or In-chat @ Depth.</div>
64686465 <select id="completion_prompt_manager_popup_entry_form_injection_position" class="text_pole" name="injection_position">
64696466 <option data-i18n="prompt_manager_relative" value="0">Relative</option>
64706467 <option data-i18n="prompt_manager_in_chat" value="1">In-chat</option>
64716468 </select>
6469+ <div class="text_muted" data-i18n="Relative (to other prompts in prompt manager) or In-chat @ Depth.">Relative (to other prompts in prompt manager) or In-chat @ Depth.</div>
64726470 </div>
64736471 <div id="completion_prompt_manager_depth_block" class="completion_prompt_manager_popup_entry_form_control flex1">
64746472 <label for="completion_prompt_manager_popup_entry_form_injection_depth">
64756473 <span data-i18n="prompt_manager_depth">Depth</span>
64766474 </label>
6477- <div class="text_muted" data-i18n="Injection depth. 0 = after the last message, 1 = before the last message, etc.">Injection depth. 0 = after the last message, 1 = before the last message, etc.</div>
64786475 <input id="completion_prompt_manager_popup_entry_form_injection_depth" class="text_pole" type="number" name="injection_depth" min="0" max="9999" value="4" />
6476+ <div class="text_muted" data-i18n="0 = after the last message, 1 = before the last message, etc.">0 = after the last message, 1 = before the last message, etc.</div>
6477+ </div>
6478+ <div id="completion_prompt_manager_order_block" class="completion_prompt_manager_popup_entry_form_control flex1">
6479+ <label for="completion_prompt_manager_popup_entry_form_injection_order">
6480+ <span data-i18n="prompt_manager_order">Order</span>
6481+ </label>
6482+ <input id="completion_prompt_manager_popup_entry_form_injection_order" class="text_pole" type="number" name="injection_order" min="0" max="9999" value="0" />
6483+ <div class="text_muted" data-i18n="Ordered from high/top to low/bottom, and at same order: System, User, Assistant.">Ordered from high/top to low/bottom, and at same order: System, User, Assistant.</div>
64796484 </div>
64806485 </div>
64816486 <div class="completion_prompt_manager_popup_entry_form_control">
@@ -6484,7 +6489,6 @@
64846489 <label for="completion_prompt_manager_popup_entry_form_prompt">
64856490 <span data-i18n="Prompt">Prompt</span>
64866491 </label>
6487- <div class="text_muted" data-i18n="The prompt to be sent.">The prompt to be sent.</div>
64886492 </div>
64896493 <div id="completion_prompt_manager_forbid_overrides_block">
64906494 <label class="checkbox_label" for="completion_prompt_manager_popup_entry_form_forbid_overrides" title="This prompt cannot be overridden by character cards, even if overrides are preferred." data-i18n="[title]This prompt cannot be overridden by character cards, even if overrides are preferred.">
@@ -6498,7 +6502,7 @@
64986502 <span>&nbsp;</span>
64996503 <span id="completion_prompt_manager_popup_entry_source"></span>
65006504 </div>
65016505 <textarea id="completion_prompt_manager_popup_entry_form_prompt" class="text_pole" name="prompt" placeholder="The prompt to be sent." data-i18n="[placeholder]The prompt to be sent."></textarea>
65026506 </textarea>
65036507 </div>
65046508 <div class="completion_prompt_manager_popup_entry_form_footer">
public/locales/ar-sa.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "لمن ستنسب هذه الرسالة؟",
10101010 "AI Assistant": "مساعد الذكاء الاصطناعي",
10111011 "prompt_manager_position": "موضع",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "موضع الحقن. بجوار المطالبات الأخرى (نسبية) أو داخل الدردشة (مطلقة).",
10131013 "prompt_manager_relative": "نسبي",
10141014 "prompt_manager_depth": "عمق",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "عمق الحقن. 0 = بعد الرسالة الأخيرة، 1 = قبل الرسالة الأخيرة، الخ.",
10161016 "Prompt": "موضوع",
10171017 "The prompt to be sent.": "المطالبة ليتم إرسالها.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "لا يمكن تجاوز هذه المطالبة بواسطة بطاقات الأحرف، حتى إذا كان التجاوزات مفضلاً.",
public/locales/de-de.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "Wem diese Nachricht zugeschrieben wird.",
10101010 "AI Assistant": "KI-Assistent",
10111011 "prompt_manager_position": "Position",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Injektionsposition. Neben anderen Eingabeaufforderungen (relativ) oder im Chat (absolut).",
10131013 "prompt_manager_relative": "Relativ",
10141014 "prompt_manager_depth": "Tiefe",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Injektionstiefe. 0 = nach der letzten Nachricht, 1 = vor der letzten Nachricht usw.",
10161016 "Prompt": "Aufforderung",
10171017 "The prompt to be sent.": "Die zu sendende Eingabeaufforderung.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Diese Eingabeaufforderung kann nicht durch Charakterkarten überschrieben werden, selbst wenn dies bevorzugt wird.",
public/locales/es-es.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "A quién se le atribuirá este mensaje.",
10101010 "AI Assistant": "Asistente de IA",
10111011 "prompt_manager_position": "Posición",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Posición de inyección. Junto a otras indicaciones (relativa) o en el chat (absoluta).",
10131013 "prompt_manager_relative": "Relativo",
10141014 "prompt_manager_depth": "Profundidad",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Profundidad de inyección. 0 = después del último mensaje, 1 = antes del último mensaje, etc.",
10161016 "Prompt": "Indicar",
10171017 "The prompt to be sent.": "El mensaje que se enviará.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Este mensaje no puede ser anulado por tarjetas de personaje, incluso si se prefieren las anulaciones.",
public/locales/fr-fr.json+2 -2
@@ -950,7 +950,7 @@
950950 "prompt_manager_position": "Position",
951951 "prompt_manager_relative": "Relatif",
952952 "prompt_manager_depth": "Profondeur",
953953 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Profondeur d'injection. 0 = après le dernier message, 1 = avant le dernier message, etc.",
954954 "Prompt": "Prompt",
955955 "The prompt to be sent.": "Le prompt à envoyer.",
956956 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Ce prompt ne peut pas être remplacé par les cartes de personnage, même si les remplacements sont préférés.",
@@ -1544,7 +1544,7 @@
15441544 "Filter to Characters or Tags": "Filtre sur les personnages ou les tags",
15451545 "Switch the Character/Tags filter around to exclude the listed characters and tags from matching for this entry": "Changez le filtre Personnages/Tags pour exclure les personnages et tags listés de la correspondance pour cette entrée.",
15461546 "Exclude": "Exclure",
15471547 "Injection position. Relative (to other prompts in prompt manager) or In-chat @ Depth.": "Position d'injection. Relative (par rapport à d'autres prompts dans le gestionnaire de prompts) ou In-chat @ Depth.",
15481548 "prompt_manager_in_chat": "In-chat",
15491549 "The content of this prompt is pulled from elsewhere and cannot be edited here.": "Le contenu de ce message est tiré d'autres sources et ne peut être modifié ici..",
15501550 "Open checkpoint chat\nShift+Click to replace the existing checkpoint with a new one": "Cliquer pour ouvrir le chat du point de contrôle\nShift+Click pour remplacer le point de contrôle existant par un nouveau.",
public/locales/is-is.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "Hverjum þessi skilaboð verða eignuð.",
10101010 "AI Assistant": "AI aðstoðarmaður",
10111011 "prompt_manager_position": "Staða",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Inndælingarstaða. Við hliðina á öðrum leiðbeiningum (afstætt) eða í spjalli (algert).",
10131013 "prompt_manager_relative": "Aðstandandi",
10141014 "prompt_manager_depth": "Dýpt",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Inndælingardýpt. 0 = eftir síðustu skilaboð, 1 = fyrir síðustu skilaboð o.s.frv.",
10161016 "Prompt": "Ábending",
10171017 "The prompt to be sent.": "Tilvitnunin sem á að senda.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Ekki er hægt að hnekkja þessari vísbendingu með persónuspjöldum, jafnvel þótt hnekkingar séu æskilegar.",
public/locales/it-it.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "A chi verrà attribuito questo messaggio.",
10101010 "AI Assistant": "Assistente AI",
10111011 "prompt_manager_position": "Posizione",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Posizione di iniezione. Accanto ad altri suggerimenti (relativo) o in chat (assoluto).",
10131013 "prompt_manager_relative": "Parente",
10141014 "prompt_manager_depth": "Profondità",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Profondità di iniezione. 0 = dopo l'ultimo messaggio, 1 = prima dell'ultimo messaggio, ecc.",
10161016 "Prompt": "Prompt",
10171017 "The prompt to be sent.": "La richiesta da inviare.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Questo prompt non può essere sostituito dalle schede personaggio, anche se si preferisce sostituirlo.",
public/locales/ja-jp.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "このメッセージの送信者。",
10101010 "AI Assistant": "AIアシスタント",
10111011 "prompt_manager_position": "位置",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "挿入位置。他のプロンプトの隣 (相対) またはチャット内 (絶対)。",
10131013 "prompt_manager_relative": "相対的",
10141014 "prompt_manager_depth": "深さ",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "注入の深さ。0 = 最後のメッセージの後、1 = 最後のメッセージの前など。",
10161016 "Prompt": "プロンプト",
10171017 "The prompt to be sent.": "送信されるプロンプト。",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "このプロンプトは、オーバーライドが優先される場合でも、キャラクター カードによってオーバーライドすることはできません。",
public/locales/ko-kr.json+3 -3
@@ -1026,11 +1026,11 @@
10261026 "To whom this message will be attributed.": "해당 프롬프트에 부여할 역할은 무엇인가요?",
10271027 "AI Assistant": "AI 어시스턴트",
10281028 "prompt_manager_position": "위치",
10291029 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "주입 위치. 다른 프롬프트 옆(상대적) 또는 채팅 내(절대적).",
10301030 "prompt_manager_relative": "상대적인",
10311031 "prompt_manager_in_chat": "깊이에 따라",
10321032 "prompt_manager_depth": "깊이",
10331033 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "주입 깊이. 0 = 마지막 메시지 뒤, 1 = 마지막 메시지 앞 등",
10341034 "Prompt": "프롬프트",
10351035 "The prompt to be sent.": "보내질 프롬프트 내용을 작성하는 부분입니다.",
10361036 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "이 프롬프트는 고급 정의에서 재정의가 선호되는 경우에도 재정의될 수 없습니다.",
@@ -1500,7 +1500,7 @@
15001500 "enable_functions_desc_1": "다양한 확장 프로그램에서 추가 기능을 제공하기 위한",
15011501 "enable_functions_desc_2": "기능 도구",
15021502 "enable_functions_desc_3": "를 사용할 수 있게 합니다.",
15031503 "Injection position. Relative (to other prompts in prompt manager) or In-chat @ Depth.": "삽입 깊이. 상대적인 (프롬프트 관리 목록에 있는 다른 프롬프트들에 비해) 또는 @Depth 깊이에 따라.",
15041504 "Instruct Template": "지시 템플릿",
15051505 "System Message Sequences": "시스템 메시지 시퀀스",
15061506 "System Prompt Sequences": "시스템 프롬프트 시퀀스",
public/locales/nl-nl.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "Aan wie dit bericht wordt toegeschreven.",
10101010 "AI Assistant": "AI-assistent",
10111011 "prompt_manager_position": "Positie",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Injectiepositie. Naast andere prompts (relatief) of in-chat (absoluut).",
10131013 "prompt_manager_relative": "Familielid",
10141014 "prompt_manager_depth": "Diepte",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Injectiediepte. 0 = na het laatste bericht, 1 = voor het laatste bericht, etc.",
10161016 "Prompt": "Prompt",
10171017 "The prompt to be sent.": "De prompt die verzonden moet worden.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Deze prompt kan niet worden overschreven door karakterkaarten, zelfs als overschrijvingen de voorkeur hebben.",
public/locales/pt-pt.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "A quem esta mensagem será atribuída.",
10101010 "AI Assistant": "Assistente de IA",
10111011 "prompt_manager_position": "Posição",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Posição de injeção. Ao lado de outras solicitações (relativas) ou no chat (absolutas).",
10131013 "prompt_manager_relative": "Relativo",
10141014 "prompt_manager_depth": "Profundidade",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Profundidade de injeção. 0 = após a última mensagem, 1 = antes da última mensagem, etc.",
10161016 "Prompt": "Prompt",
10171017 "The prompt to be sent.": "O prompt a ser enviado.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Este prompt não pode ser substituído por cartas de personagem, mesmo que as substituições sejam preferidas.",
public/locales/ru-ru.json+3 -3
@@ -1012,10 +1012,10 @@
10121012 "To whom this message will be attributed.": "От чьего лица будет отправляться сообщение.",
10131013 "AI Assistant": "ИИ-ассистент",
10141014 "prompt_manager_position": "Точка инжекта",
10151015 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Как рассчитывать позицию для инжекта. Она может располагаться по отношению к другим промптам (относительная) либо по отношению к чату (абсолютная).",
10161016 "prompt_manager_relative": "Относительная",
10171017 "prompt_manager_depth": "Глубина",
10181018 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Глубина вставки. 0 = после последнего сообщения, 1 = перед последним сообщением, и т.д.",
10191019 "The prompt to be sent.": "Текст промпта.",
10201020 "prompt_manager_forbid_overrides": "Запретить перезапись",
10211021 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Карточка персонажа не сможет перезаписать этот промпт, даже если настройки отдают приоритет именно ей.",
@@ -1620,7 +1620,7 @@
16201620 "Using a proxy that you're not running yourself is a risk to your data privacy.": "Помните, что используя чужую прокси, вы подвергаете риску конфиденциальность своих данных.",
16211621 "ANY support requests will be REFUSED if you are using a proxy.": "НЕ РАССЧИТЫВАЙТЕ на нашу поддержку, если используете прокси.",
16221622 "Do not proceed if you do not agree to this!": "Не продолжайте, если не согласны с этими условиями!",
16231623 "Injection position. Relative (to other prompts in prompt manager) or In-chat @ Depth.": "Как рассчитывать позицию, на которую вставляется данный промпт. Относительно других промтов в менеджере, либо на опред. глубину в чате.",
16241624 "prompt_manager_in_chat": "На глубине в чате",
16251625 "01.AI API Key": "Ключ от API 01.AI",
16261626 "01.AI Model": "Модель 01.AI",
public/locales/uk-ua.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "Кому буде віднесено це повідомлення.",
10101010 "AI Assistant": "ШІ помічник",
10111011 "prompt_manager_position": "Позиція",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Позиція ін'єкції. Поруч з іншими підказками (відносні) або в чаті (абсолютні).",
10131013 "prompt_manager_relative": "Відносна",
10141014 "prompt_manager_depth": "Глибина",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Глибина ін'єкції. 0 = після останнього повідомлення, 1 = перед останнім повідомленням тощо.",
10161016 "Prompt": "Запит",
10171017 "The prompt to be sent.": "Підказка для надсилання.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Це підказка не може бути перевизначено картками символів, навіть якщо перевизначення є кращим.",
public/locales/vi-vn.json+2 -2
@@ -1009,10 +1009,10 @@
10091009 "To whom this message will be attributed.": "Tin nhắn này sẽ được quy cho ai.",
10101010 "AI Assistant": "Trợ lý AI",
10111011 "prompt_manager_position": "Chức vụ",
10121012 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "Vị trí tiêm. Bên cạnh các Prompt khác (tương đối) hoặc trong trò chuyện (tuyệt đối).",
10131013 "prompt_manager_relative": "Liên quan đến",
10141014 "prompt_manager_depth": "Chiều sâu",
10151015 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "Độ sâu phun. 0 = sau tin nhắn cuối cùng, 1 = trước tin nhắn cuối cùng, v.v.",
10161016 "Prompt": "Prompt",
10171017 "The prompt to be sent.": "Lời nhắc được gửi đi.",
10181018 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "Lời nhắc này không thể bị ghi đè bằng thẻ ký tự, ngay cả khi ưu tiên ghi đè.",
public/locales/zh-cn.json+2 -2
@@ -1168,11 +1168,11 @@
11681168 "To whom this message will be attributed.": "此消息应归于谁。",
11691169 "AI Assistant": "AI助手",
11701170 "prompt_manager_position": "位置",
11711171 "Injection position. Relative (to other prompts in prompt manager) or In-chat @ Depth.": "注入位置。相对(相对于提示管理器中的其他提示)或在聊天中@深度。",
11721172 "prompt_manager_relative": "相对",
11731173 "prompt_manager_in_chat": "聊天中",
11741174 "prompt_manager_depth": "深度",
11751175 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "注入深度。“0”为在最后一条消息之后,“1”为在最后一条消息之前,等等。",
11761176 "The content of this prompt is pulled from elsewhere and cannot be edited here.": "此提示词的内容是从其他地方提取的,无法在此处进行编辑。",
11771177 "Prompt": "提示词",
11781178 "The prompt to be sent.": "要发送的提示词。",
public/locales/zh-tw.json+3 -3
@@ -1010,10 +1010,10 @@
10101010 "To whom this message will be attributed.": "此訊息所屬的角色。",
10111011 "AI Assistant": "人工智慧助手",
10121012 "prompt_manager_position": "位置",
10131013 "Injection position. Next to other prompts (relative) or in-chat (absolute).": "注入位置。與其他提示詞相鄰(相對位置)或在聊天中(絕對位置)。",
10141014 "prompt_manager_relative": "相對位置",
10151015 "prompt_manager_depth": "深度",
10161016 "Injection depth. 0 = after the last message, 1 = before the last message, etc.": "注入深度。0 = 在最後一則訊息之後,1 = 在最後一則訊息之前,以此類推。",
10171017 "Prompt": "提示詞",
10181018 "The prompt to be sent.": "要傳送的提示詞。",
10191019 "This prompt cannot be overridden by character cards, even if overrides are preferred.": "即使啟用優先覆寫,此提示詞也不能被角色卡片覆寫。",
@@ -1650,7 +1650,7 @@
16501650 "Image Captioning": "圖片註解",
16511651 "Generate Caption": "產生圖片註解",
16521652 "Injection Position": "插入位置",
16531653 "Injection position. Relative (to other prompts in prompt manager) or In-chat @ Depth.": "插入位置(與提示詞管理器中的其他提示相比)或聊天中的深度位置。",
16541654 "Injection Template": "插入範本",
16551655 "Insert#": "插入#",
16561656 "Instruct Sequences": "指令序列",
public/scripts/PromptManager.js+16 -2
@@ -77,7 +77,7 @@ const registerPromptManagerMigration = () => {
7777 * Represents a prompt.
7878 */
7979class Prompt {
8080 identifier; role; content; name; system_prompt; position; injection_position; injection_depth; injection_order; forbid_overrides; extension;
8181
8282 /**
8383 * Create a new Prompt instance.
@@ -91,10 +91,11 @@ class Prompt {
9191 * @param {string} [param0.position] - The position of the prompt in the prompt list.
9292 * @param {number} [param0.injection_position] - The insert position of the prompt.
9393 * @param {number} [param0.injection_depth] - The depth of the prompt in the chat.
94+ * @param {number} [param0.injection_order] - The order of the prompt in the chat.
9495 * @param {boolean} [param0.forbid_overrides] - Indicates if the prompt should not be overridden.
9596 * @param {boolean} [param0.extension] - Prompt is added by an extension.
9697 */
9798 constructor({ identifier, role, content, name, system_prompt, position, injection_depth, injection_position, forbid_overrides, extension, injection_order } = {}) {
9899 this.identifier = identifier;
99100 this.role = role;
100101 this.content = content;
@@ -105,6 +106,7 @@ class Prompt {
105106 this.injection_position = injection_position;
106107 this.forbid_overrides = forbid_overrides;
107108 this.extension = extension ?? false;
109+ this.injection_order = injection_order ?? 0;
108110 }
109111}
110112
@@ -447,7 +449,9 @@ class PromptManager {
447449 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').value = prompt.content ?? '';
448450 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').value = prompt.injection_position ?? 0;
449451 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth').value = prompt.injection_depth ?? DEFAULT_DEPTH;
452+ document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_order').value = prompt.injection_order ?? 0;
450453 document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block').style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
454+ document.getElementById(this.configuration.prefix + 'prompt_manager_order_block').style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
451455 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides').checked = prompt.forbid_overrides ?? false;
452456 document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block').style.visibility = this.overridablePrompts.includes(prompt.identifier) ? 'visible' : 'hidden';
453457 document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').disabled = prompt.marker ?? false;
@@ -782,6 +786,7 @@ class PromptManager {
782786 prompt.content = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').value;
783787 prompt.injection_position = Number(document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').value);
784788 prompt.injection_depth = Number(document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth').value);
789+ prompt.injection_order = Number(document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_order').value);
785790 prompt.forbid_overrides = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides').checked;
786791 }
787792
@@ -1222,7 +1227,9 @@ class PromptManager {
12221227 const promptField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt');
12231228 const injectionPositionField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position');
12241229 const injectionDepthField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth');
1230+ const injectionOrderField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_order');
12251231 const injectionDepthBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block');
1232+ const injectionOrderBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_order_block');
12261233 const forbidOverridesField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides');
12271234 const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block');
12281235 const entrySourceBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_source_block');
@@ -1235,7 +1242,9 @@ class PromptManager {
12351242 promptField.disabled = prompt.marker ?? false;
12361243 injectionPositionField.value = prompt.injection_position ?? INJECTION_POSITION.RELATIVE;
12371244 injectionDepthField.value = prompt.injection_depth ?? DEFAULT_DEPTH;
1245+ injectionOrderField.value = prompt.injection_order ?? 0;
12381246 injectionDepthBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
1247+ injectionOrderBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
12391248 injectionPositionField.removeAttribute('disabled');
12401249 forbidOverridesField.checked = prompt.forbid_overrides ?? false;
12411250 forbidOverridesBlock.style.visibility = this.overridablePrompts.includes(prompt.identifier) ? 'visible' : 'hidden';
@@ -1267,11 +1276,14 @@ class PromptManager {
12671276
12681277 handleInjectionPositionChange(event) {
12691278 const injectionDepthBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block');
1279+ const injectionOrderBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_order_block');
12701280 const injectionPosition = Number(event.target.value);
12711281 if (injectionPosition === INJECTION_POSITION.ABSOLUTE) {
12721282 injectionDepthBlock.style.visibility = 'visible';
1283+ injectionOrderBlock.style.visibility = 'visible';
12731284 } else {
12741285 injectionDepthBlock.style.visibility = 'hidden';
1286+ injectionOrderBlock.style.visibility = 'hidden';
12751287 }
12761288 }
12771289
@@ -1328,6 +1340,7 @@ class PromptManager {
13281340 const injectionPositionField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position');
13291341 const injectionDepthField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth');
13301342 const injectionDepthBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block');
1343+ const injectionOrderBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_order_block');
13311344 const forbidOverridesField = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides');
13321345 const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block');
13331346 const entrySourceBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_source_block');
@@ -1341,6 +1354,7 @@ class PromptManager {
13411354 injectionPositionField.removeAttribute('disabled');
13421355 injectionDepthField.value = DEFAULT_DEPTH;
13431356 injectionDepthBlock.style.visibility = 'unset';
1357+ injectionOrderBlock.style.visibility = 'unset';
13441358 forbidOverridesBlock.style.visibility = 'unset';
13451359 forbidOverridesField.checked = false;
13461360 entrySourceBlock.style.display = 'none';
public/scripts/openai.js+25 -5
@@ -760,24 +760,42 @@ async function populationInjectionPrompts(prompts, messages) {
760760 // Get prompts for current depth
761761 const depthPrompts = prompts.filter(prompt => prompt.injection_depth === i && prompt.content);
762762
763- // Order of priority (most important go lower)
764- const roles = ['system', 'user', 'assistant'];
765763 const roleMessages = [];
766764 const separator = '\n';
767765 const wrap = false;
768766
767+ // Group prompts by priority
768+ const orderGroups = {};
769+ for (const prompt of depthPrompts) {
770+ const order = prompt.injection_order || 0;
771+ if (!orderGroups[order]) {
772+ orderGroups[order] = [];
773+ }
774+ orderGroups[order].push(prompt);
775+ }
776+
777+ // Process each order group in order (b - a = low to high ; a - b = high to low)
778+ const orders = Object.keys(orderGroups).sort((a, b) => +a - +b);
779+ for (const order of orders) {
780+ const orderPrompts = orderGroups[order];
781+
782+ // Order of priority for roles (most important go lower)
783+ const roles = ['system', 'user', 'assistant'];
769784 for (const role of roles) {
770- // Get prompts for current role
785+ const rolePrompts = orderPrompts
771786 const rolePrompts = depthPrompts .filter(prompt => prompt.role === role).map(x => x.content).join(separator);
787+ .map(x => x.content)
788+ .join(separator);
789+
772790 // Get extension prompt
773791 const extensionPrompt = await getExtensionPrompt(extension_prompt_types.IN_CHAT, i, separator, roleTypes[role], wrap);
774-
775792 const jointPrompt = [rolePrompts, extensionPrompt].filter(x => x).map(x => x.trim()).join(separator);
776793
777794 if (jointPrompt && jointPrompt.length) {
778795 roleMessages.push({ 'role': role, 'content': jointPrompt, injected: true });
779796 }
780797 }
798+ }
781799
782800 if (roleMessages.length) {
783801 const injectIdx = i + totalInsertedMessages;
@@ -1314,6 +1332,8 @@ async function preparePromptsForChatCompletion({ scenario, charPersonality, name
13141332 prompt.injection_position = collectionPrompt.injection_position ?? prompt.injection_position;
13151333 // Depth for In-Chat
13161334 prompt.injection_depth = collectionPrompt.injection_depth ?? prompt.injection_depth;
1335+ // Priority for In-Chat
1336+ prompt.injection_order = collectionPrompt.injection_order ?? prompt.injection_order;
13171337 // Role (system, user, assistant)
13181338 prompt.role = collectionPrompt.role ?? prompt.role;
13191339 }