mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 05:02:01 -06:00
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:
@@ -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 || '';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user