mirror of
https://github.com/open-webui/open-webui
synced 2025-02-06 13:10:16 +00:00
Add more variables to prompts
This commit is contained in:
parent
d6d6098378
commit
d53062a9b0
@ -1,6 +1,14 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { prompts } from '$lib/stores';
|
import { prompts } from '$lib/stores';
|
||||||
import { findWordIndices } from '$lib/utils';
|
import {
|
||||||
|
findWordIndices,
|
||||||
|
getUserPosition,
|
||||||
|
getFormattedDate,
|
||||||
|
getFormattedTime,
|
||||||
|
getCurrentDateTime,
|
||||||
|
getUserTimezone,
|
||||||
|
getWeekday
|
||||||
|
} from '$lib/utils';
|
||||||
import { tick, getContext } from 'svelte';
|
import { tick, getContext } from 'svelte';
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
|
|
||||||
@ -39,8 +47,6 @@
|
|||||||
return '{{CLIPBOARD}}';
|
return '{{CLIPBOARD}}';
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(clipboardText);
|
|
||||||
|
|
||||||
const clipboardItems = await navigator.clipboard.read();
|
const clipboardItems = await navigator.clipboard.read();
|
||||||
|
|
||||||
let imageUrl = null;
|
let imageUrl = null;
|
||||||
@ -50,7 +56,6 @@
|
|||||||
if (type.startsWith('image/')) {
|
if (type.startsWith('image/')) {
|
||||||
const blob = await item.getType(type);
|
const blob = await item.getType(type);
|
||||||
imageUrl = URL.createObjectURL(blob);
|
imageUrl = URL.createObjectURL(blob);
|
||||||
console.log(`Image URL (${type}): ${imageUrl}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +70,42 @@
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
text = command.content.replaceAll('{{CLIPBOARD}}', clipboardText);
|
text = text.replaceAll('{{CLIPBOARD}}', clipboardText);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.content.includes('{{USER_LOCATION}}')) {
|
||||||
|
const location = await getUserPosition();
|
||||||
|
text = text.replaceAll('{{USER_LOCATION}}', String(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.content.includes('{{USER_LANGUAGE}}')) {
|
||||||
|
const language = localStorage.getItem('locale') || 'en-US';
|
||||||
|
text = text.replaceAll('{{USER_LANGUAGE}}', language);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.content.includes('{{CURRENT_DATE}}')) {
|
||||||
|
const date = getFormattedDate();
|
||||||
|
text = text.replaceAll('{{CURRENT_DATE}}', date);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.content.includes('{{CURRENT_TIME}}')) {
|
||||||
|
const time = getFormattedTime();
|
||||||
|
text = text.replaceAll('{{CURRENT_TIME}}', time);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.content.includes('{{CURRENT_DATETIME}}')) {
|
||||||
|
const dateTime = getCurrentDateTime();
|
||||||
|
text = text.replaceAll('{{CURRENT_DATETIME}}', dateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.content.includes('{{CURRENT_TIMEZONE}}')) {
|
||||||
|
const timezone = getUserTimezone();
|
||||||
|
text = text.replaceAll('{{CURRENT_TIMEZONE}}', timezone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.content.includes('{{CURRENT_WEEKDAY}}')) {
|
||||||
|
const weekday = getWeekday();
|
||||||
|
text = text.replaceAll('{{CURRENT_WEEKDAY}}', weekday);
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt = text;
|
prompt = text;
|
||||||
|
@ -829,6 +829,34 @@ export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, def
|
|||||||
.map((prefLang) => languages.find((lang) => lang.startsWith(prefLang)))
|
.map((prefLang) => languages.find((lang) => lang.startsWith(prefLang)))
|
||||||
.find(Boolean);
|
.find(Boolean);
|
||||||
|
|
||||||
console.log(languages, preferredLanguages, match, defaultLocale);
|
|
||||||
return match || defaultLocale;
|
return match || defaultLocale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get the date in the format YYYY-MM-DD
|
||||||
|
export const getFormattedDate = () => {
|
||||||
|
const date = new Date();
|
||||||
|
return date.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the time in the format HH:MM:SS
|
||||||
|
export const getFormattedTime = () => {
|
||||||
|
const date = new Date();
|
||||||
|
return date.toTimeString().split(' ')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the current date and time in the format YYYY-MM-DD HH:MM:SS
|
||||||
|
export const getCurrentDateTime = () => {
|
||||||
|
return `${getFormattedDate()} ${getFormattedTime()}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the user's timezone
|
||||||
|
export const getUserTimezone = () => {
|
||||||
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the weekday
|
||||||
|
export const getWeekday = () => {
|
||||||
|
const date = new Date();
|
||||||
|
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||||
|
return weekdays[date.getDay()];
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user