feat: {{USER_ROLE}} prompt variable for the signed-in user's role (#33441)

Prompts could use the user's name and email but not their role, so role-aware system prompts needed a custom Filter function. Model system prompts, the user's own system prompt, saved prompts used with a slash command and chat requests through the API now replace {{USER_ROLE}} with the role, such as admin or user. Requested in #4765.
This commit is contained in:
Classic298
2026-10-31 07:47:17 +09:00
committed by GitHub
parent feefe03bf2
commit c9ee89467e
3 changed files with 18 additions and 0 deletions
+2
View File
@@ -73,6 +73,7 @@ async def prompt_template(template: str, user: Optional[Any] = None) -> str:
USER_VARIABLES = {
'name': str(user.get('name')),
'email': str(user.get('email')),
'role': str(user.get('role')),
'location': str(user_info.get('location')),
'bio': str(user.get('bio')),
'gender': str(user.get('gender')),
@@ -96,6 +97,7 @@ async def prompt_template(template: str, user: Optional[Any] = None) -> str:
template = template.replace('{{USER_NAME}}', USER_VARIABLES.get('name', 'Unknown'))
template = template.replace('{{USER_EMAIL}}', USER_VARIABLES.get('email', 'Unknown'))
template = template.replace('{{USER_ROLE}}', USER_VARIABLES.get('role', 'Unknown'))
template = template.replace('{{USER_BIO}}', USER_VARIABLES.get('bio', 'Unknown'))
template = template.replace('{{USER_GENDER}}', USER_VARIABLES.get('gender', 'Unknown'))
template = template.replace('{{USER_BIRTH_DATE}}', USER_VARIABLES.get('birth_date', 'Unknown'))
@@ -182,6 +182,14 @@
}
}
if (text.includes('{{USER_ROLE}}')) {
const role = sessionUser?.role || '';
if (role) {
text = text.replaceAll('{{USER_ROLE}}', role);
}
}
if (text.includes('{{USER_BIO}}')) {
const bio = sessionUser?.bio || '';
@@ -352,6 +352,14 @@
}
}
if (text.includes('{{USER_ROLE}}')) {
const role = sessionUser?.role || '';
if (role) {
text = text.replaceAll('{{USER_ROLE}}', role);
}
}
if (text.includes('{{USER_BIO}}')) {
const bio = sessionUser?.bio || '';