forked from open-webui/open-webui
feat: option to toggle auto title generation
This commit is contained in:
parent
1196fa886a
commit
cfb3f307b4
3 changed files with 89 additions and 52 deletions
|
@ -38,6 +38,7 @@
|
||||||
let pullProgress = null;
|
let pullProgress = null;
|
||||||
|
|
||||||
// Addons
|
// Addons
|
||||||
|
let titleAutoGenerate = true;
|
||||||
let speechAutoSend = false;
|
let speechAutoSend = false;
|
||||||
let gravatarEmail = '';
|
let gravatarEmail = '';
|
||||||
let OPENAI_API_KEY = '';
|
let OPENAI_API_KEY = '';
|
||||||
|
@ -91,6 +92,11 @@
|
||||||
saveSettings({ speechAutoSend: speechAutoSend });
|
saveSettings({ speechAutoSend: speechAutoSend });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleTitleAutoGenerate = async () => {
|
||||||
|
titleAutoGenerate = !titleAutoGenerate;
|
||||||
|
saveSettings({ titleAutoGenerate: titleAutoGenerate });
|
||||||
|
};
|
||||||
|
|
||||||
const toggleAuthHeader = async () => {
|
const toggleAuthHeader = async () => {
|
||||||
authEnabled = !authEnabled;
|
authEnabled = !authEnabled;
|
||||||
};
|
};
|
||||||
|
@ -226,6 +232,7 @@
|
||||||
top_k = settings.top_k ?? 40;
|
top_k = settings.top_k ?? 40;
|
||||||
top_p = settings.top_p ?? 0.9;
|
top_p = settings.top_p ?? 0.9;
|
||||||
|
|
||||||
|
titleAutoGenerate = settings.titleAutoGenerate ?? true;
|
||||||
speechAutoSend = settings.speechAutoSend ?? false;
|
speechAutoSend = settings.speechAutoSend ?? false;
|
||||||
gravatarEmail = settings.gravatarEmail ?? '';
|
gravatarEmail = settings.gravatarEmail ?? '';
|
||||||
OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
|
OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
|
||||||
|
@ -851,6 +858,28 @@
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class=" space-y-3">
|
<div class=" space-y-3">
|
||||||
|
<div>
|
||||||
|
<div class=" py-1 flex w-full justify-between">
|
||||||
|
<div class=" self-center text-sm font-medium">Title Auto Generation</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="p-1 px-3 text-xs flex rounded transition"
|
||||||
|
on:click={() => {
|
||||||
|
toggleTitleAutoGenerate();
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{#if titleAutoGenerate === true}
|
||||||
|
<span class="ml-2 self-center">On</span>
|
||||||
|
{:else}
|
||||||
|
<span class="ml-2 self-center">Off</span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr class=" dark:border-gray-700" />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class=" py-1 flex w-full justify-between">
|
<div class=" py-1 flex w-full justify-between">
|
||||||
<div class=" self-center text-sm font-medium">Voice Input Auto-Send</div>
|
<div class=" self-center text-sm font-medium">Voice Input Auto-Send</div>
|
||||||
|
|
|
@ -415,35 +415,39 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateChatTitle = async (_chatId, userPrompt) => {
|
const generateChatTitle = async (_chatId, userPrompt) => {
|
||||||
console.log('generateChatTitle');
|
if ($settings.titleAutoGenerate ?? true) {
|
||||||
|
console.log('generateChatTitle');
|
||||||
|
|
||||||
const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/generate`, {
|
const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/generate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/event-stream',
|
'Content-Type': 'text/event-stream',
|
||||||
...($settings.authHeader && { Authorization: $settings.authHeader }),
|
...($settings.authHeader && { Authorization: $settings.authHeader }),
|
||||||
...($user && { Authorization: `Bearer ${localStorage.token}` })
|
...($user && { Authorization: `Bearer ${localStorage.token}` })
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: selectedModels[0],
|
model: selectedModels[0],
|
||||||
prompt: `Generate a brief 3-5 word title for this question, excluding the term 'title.' Then, please reply with only the title: ${userPrompt}`,
|
prompt: `Generate a brief 3-5 word title for this question, excluding the term 'title.' Then, please reply with only the title: ${userPrompt}`,
|
||||||
stream: false
|
stream: false
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
.then(async (res) => {
|
||||||
.then(async (res) => {
|
if (!res.ok) throw await res.json();
|
||||||
if (!res.ok) throw await res.json();
|
return res.json();
|
||||||
return res.json();
|
})
|
||||||
})
|
.catch((error) => {
|
||||||
.catch((error) => {
|
if ('detail' in error) {
|
||||||
if ('detail' in error) {
|
toast.error(error.detail);
|
||||||
toast.error(error.detail);
|
}
|
||||||
}
|
console.log(error);
|
||||||
console.log(error);
|
return null;
|
||||||
return null;
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
await setChatTitle(_chatId, res.response === '' ? 'New Chat' : res.response);
|
await setChatTitle(_chatId, res.response === '' ? 'New Chat' : res.response);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await setChatTitle(_chatId, `${userPrompt}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -451,35 +451,39 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateChatTitle = async (_chatId, userPrompt) => {
|
const generateChatTitle = async (_chatId, userPrompt) => {
|
||||||
console.log('generateChatTitle');
|
if ($settings.titleAutoGenerate ?? true) {
|
||||||
|
console.log('generateChatTitle');
|
||||||
|
|
||||||
const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/generate`, {
|
const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/generate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/event-stream',
|
'Content-Type': 'text/event-stream',
|
||||||
...($settings.authHeader && { Authorization: $settings.authHeader }),
|
...($settings.authHeader && { Authorization: $settings.authHeader }),
|
||||||
...($user && { Authorization: `Bearer ${localStorage.token}` })
|
...($user && { Authorization: `Bearer ${localStorage.token}` })
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: selectedModels[0],
|
model: selectedModels[0],
|
||||||
prompt: `Generate a brief 3-5 word title for this question, excluding the term 'title.' Then, please reply with only the title: ${userPrompt}`,
|
prompt: `Generate a brief 3-5 word title for this question, excluding the term 'title.' Then, please reply with only the title: ${userPrompt}`,
|
||||||
stream: false
|
stream: false
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
.then(async (res) => {
|
||||||
.then(async (res) => {
|
if (!res.ok) throw await res.json();
|
||||||
if (!res.ok) throw await res.json();
|
return res.json();
|
||||||
return res.json();
|
})
|
||||||
})
|
.catch((error) => {
|
||||||
.catch((error) => {
|
if ('detail' in error) {
|
||||||
if ('detail' in error) {
|
toast.error(error.detail);
|
||||||
toast.error(error.detail);
|
}
|
||||||
}
|
console.log(error);
|
||||||
console.log(error);
|
return null;
|
||||||
return null;
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
await setChatTitle(_chatId, res.response === '' ? 'New Chat' : res.response);
|
await setChatTitle(_chatId, res.response === '' ? 'New Chat' : res.response);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await setChatTitle(_chatId, `${userPrompt}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue