Commit 9fefddd8 authored by AnkurSachdeva22's avatar AnkurSachdeva22
Browse files
parents 7dade071 0ed54055
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -472,29 +472,20 @@ export const blobToFile = (blob, fileName) => { ...@@ -472,29 +472,20 @@ export const blobToFile = (blob, fileName) => {
return file; return file;
}; };
// promptTemplate replaces any occurrences of the following in the template with the prompt
// {{prompt}} will be replaced with the prompt
// {{prompt:start:<length>}} will be replaced with the first <length> characters of the prompt
// {{prompt:end:<length>}} will be replaced with the last <length> characters of the prompt
// Character length is used as we don't have the ability to tokenize the prompt
export const promptTemplate = (template: string, prompt: string) => { export const promptTemplate = (template: string, prompt: string) => {
prompt = prompt.replace(/{{prompt}}|{{prompt:start:\d+}}|{{prompt:end:\d+}}/g, '');
template = template.replace(/{{prompt}}/g, prompt); template = template.replace(/{{prompt}}/g, prompt);
// Replace all instances of {{prompt:start:<length>}} with the first <length> characters of the prompt // Replace all instances of {{prompt:start:<length>}} with the first <length> characters of the prompt
const startRegex = /{{prompt:start:(\d+)}}/g; template = template.replace(/{{prompt:start:(\d+)}}/g, (match, length) =>
let startMatch: RegExpMatchArray | null; prompt.substring(0, parseInt(length))
while ((startMatch = startRegex.exec(template)) !== null) { );
const length = parseInt(startMatch[1]);
template = template.replace(startMatch[0], prompt.substring(0, length));
}
// Replace all instances of {{prompt:end:<length>}} with the last <length> characters of the prompt // Replace all instances of {{prompt:end:<length>}} with the last <length> characters of the prompt
const endRegex = /{{prompt:end:(\d+)}}/g; template = template.replace(/{{prompt:end:(\d+)}}/g, (match, length) =>
let endMatch: RegExpMatchArray | null; prompt.slice(-parseInt(length))
while ((endMatch = endRegex.exec(template)) !== null) { );
const length = parseInt(endMatch[1]);
template = template.replace(endMatch[0], prompt.substring(prompt.length - length));
}
return template; return template;
}; };
...@@ -520,3 +511,34 @@ export const approximateToHumanReadable = (nanoseconds: number) => { ...@@ -520,3 +511,34 @@ export const approximateToHumanReadable = (nanoseconds: number) => {
return results.reverse().join(' '); return results.reverse().join(' ');
}; };
export const getTimeRange = (timestamp) => {
const now = new Date();
const date = new Date(timestamp * 1000); // Convert Unix timestamp to milliseconds
// Calculate the difference in milliseconds
const diffTime = now.getTime() - date.getTime();
const diffDays = diffTime / (1000 * 3600 * 24);
const nowDate = now.getDate();
const nowMonth = now.getMonth();
const nowYear = now.getFullYear();
const dateDate = date.getDate();
const dateMonth = date.getMonth();
const dateYear = date.getFullYear();
if (nowYear === dateYear && nowMonth === dateMonth && nowDate === dateDate) {
return 'Today';
} else if (nowYear === dateYear && nowMonth === dateMonth && nowDate - dateDate === 1) {
return 'Yesterday';
} else if (diffDays <= 7) {
return 'Previous 7 days';
} else if (diffDays <= 30) {
return 'Previous 30 days';
} else if (nowYear === dateYear) {
return date.toLocaleString('default', { month: 'long' });
} else {
return date.getFullYear().toString();
}
};
...@@ -177,7 +177,7 @@ ...@@ -177,7 +177,7 @@
</script> </script>
<div class=" hidden lg:flex fixed bottom-0 right-0 px-3 py-3 z-10"> <div class=" hidden lg:flex fixed bottom-0 right-0 px-3 py-3 z-10">
<Tooltip content="Help" placement="left"> <Tooltip content={$i18n.t('Help')} placement="left">
<button <button
id="show-shortcuts-button" id="show-shortcuts-button"
bind:this={showShortcutsButtonElement} bind:this={showShortcutsButtonElement}
...@@ -201,11 +201,11 @@ ...@@ -201,11 +201,11 @@
> >
{#if loaded} {#if loaded}
{#if !['user', 'admin'].includes($user.role)} {#if !['user', 'admin'].includes($user.role)}
<div class="fixed w-full h-full flex z-50"> <div class="fixed w-full h-full flex z-[999]">
<div <div
class="absolute w-full h-full backdrop-blur-md bg-white/20 dark:bg-gray-900/50 flex justify-center" class="absolute w-full h-full backdrop-blur-lg bg-white/10 dark:bg-gray-900/50 flex justify-center"
> >
<div class="m-auto pb-44 flex flex-col justify-center"> <div class="m-auto pb-10 flex flex-col justify-center">
<div class="max-w-md"> <div class="max-w-md">
<div class="text-center dark:text-white text-2xl font-medium z-50"> <div class="text-center dark:text-white text-2xl font-medium z-50">
Account Activation Pending<br /> Contact Admin for WebUI Access Account Activation Pending<br /> Contact Admin for WebUI Access
......
...@@ -134,6 +134,14 @@ ...@@ -134,6 +134,14 @@
selectedModels = ['']; selectedModels = [''];
} }
if ($page.url.searchParams.get('q')) {
prompt = $page.url.searchParams.get('q') ?? '';
if (prompt) {
await tick();
submitPrompt(prompt);
}
}
selectedModels = selectedModels.map((modelId) => selectedModels = selectedModels.map((modelId) =>
$models.map((m) => m.id).includes(modelId) ? modelId : '' $models.map((m) => m.id).includes(modelId) ? modelId : ''
); );
...@@ -366,7 +374,8 @@ ...@@ -366,7 +374,8 @@
}, },
format: $settings.requestFormat ?? undefined, format: $settings.requestFormat ?? undefined,
keep_alive: $settings.keepAlive ?? undefined, keep_alive: $settings.keepAlive ?? undefined,
docs: docs.length > 0 ? docs : undefined docs: docs.length > 0 ? docs : undefined,
citations: docs.length > 0
}); });
if (res && res.ok) { if (res && res.ok) {
...@@ -401,6 +410,11 @@ ...@@ -401,6 +410,11 @@
console.log(line); console.log(line);
let data = JSON.parse(line); let data = JSON.parse(line);
if ('citations' in data) {
responseMessage.citations = data.citations;
continue;
}
if ('detail' in data) { if ('detail' in data) {
throw data; throw data;
} }
...@@ -598,7 +612,8 @@ ...@@ -598,7 +612,8 @@
num_ctx: $settings?.options?.num_ctx ?? undefined, num_ctx: $settings?.options?.num_ctx ?? undefined,
frequency_penalty: $settings?.options?.repeat_penalty ?? undefined, frequency_penalty: $settings?.options?.repeat_penalty ?? undefined,
max_tokens: $settings?.options?.num_predict ?? undefined, max_tokens: $settings?.options?.num_predict ?? undefined,
docs: docs.length > 0 ? docs : undefined docs: docs.length > 0 ? docs : undefined,
citations: docs.length > 0
}, },
model?.source?.toLowerCase() === 'litellm' model?.source?.toLowerCase() === 'litellm'
? `${LITELLM_API_BASE_URL}/v1` ? `${LITELLM_API_BASE_URL}/v1`
...@@ -614,7 +629,7 @@ ...@@ -614,7 +629,7 @@
const textStream = await createOpenAITextStream(res.body, $settings.splitLargeChunks); const textStream = await createOpenAITextStream(res.body, $settings.splitLargeChunks);
for await (const update of textStream) { for await (const update of textStream) {
const { value, done } = update; const { value, done, citations } = update;
if (done || stopResponseFlag || _chatId !== $chatId) { if (done || stopResponseFlag || _chatId !== $chatId) {
responseMessage.done = true; responseMessage.done = true;
messages = messages; messages = messages;
...@@ -626,6 +641,11 @@ ...@@ -626,6 +641,11 @@
break; break;
} }
if (citations) {
responseMessage.citations = citations;
continue;
}
if (responseMessage.content == '' && value == '\n') { if (responseMessage.content == '' && value == '\n') {
continue; continue;
} else { } else {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Open WebUI</ShortName>
<Description>Search Open WebUI</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">http://localhost:5137/favicon.png</Image>
<Url type="text/html" method="get" template="http://localhost:5137/?q={searchTerms}"/>
<moz:SearchForm>http://localhost:5137</moz:SearchForm>
</OpenSearchDescription>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment