mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac: prompt variables
This commit is contained in:
@@ -45,7 +45,8 @@
|
||||
promptTemplate,
|
||||
splitStream,
|
||||
sleep,
|
||||
removeDetailsWithReasoning
|
||||
removeDetailsWithReasoning,
|
||||
getPromptVariables
|
||||
} from '$lib/utils';
|
||||
|
||||
import { generateChatCompletion } from '$lib/apis/ollama';
|
||||
@@ -628,7 +629,7 @@
|
||||
} catch (e) {
|
||||
// Remove the failed doc from the files array
|
||||
files = files.filter((f) => f.name !== url);
|
||||
toast.error(e);
|
||||
toast.error(`${e}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1558,10 +1559,17 @@
|
||||
|
||||
files: (files?.length ?? 0) > 0 ? files : undefined,
|
||||
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
|
||||
|
||||
features: {
|
||||
image_generation: imageGenerationEnabled,
|
||||
web_search: webSearchEnabled
|
||||
},
|
||||
variables: {
|
||||
...getPromptVariables(
|
||||
$user.name,
|
||||
$settings?.userLocation ? await getAndUpdateUserLocation(localStorage.token) : undefined
|
||||
)
|
||||
},
|
||||
|
||||
session_id: $socket?.id,
|
||||
chat_id: $chatId,
|
||||
|
||||
@@ -766,6 +766,19 @@ export const blobToFile = (blob, fileName) => {
|
||||
return file;
|
||||
};
|
||||
|
||||
export const getPromptVariables = (user_name, user_location) => {
|
||||
return {
|
||||
'{{USER_NAME}}': user_name,
|
||||
'{{USER_LOCATION}}': user_location || 'Unknown',
|
||||
'{{CURRENT_DATETIME}}': getCurrentDateTime(),
|
||||
'{{CURRENT_DATE}}': getFormattedDate(),
|
||||
'{{CURRENT_TIME}}': getFormattedTime(),
|
||||
'{{CURRENT_WEEKDAY}}': getWeekday(),
|
||||
'{{CURRENT_TIMEZONE}}': getUserTimezone(),
|
||||
'{{USER_LANGUAGE}}': localStorage.getItem('locale') || 'en-US'
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} template - The template string containing placeholders.
|
||||
* @returns {string} The template string with the placeholders replaced by the prompt.
|
||||
|
||||
Reference in New Issue
Block a user