mirror of
https://github.com/open-webui/open-webui
synced 2024-11-25 13:29:53 +00:00
enh: detailed 1-10 rating
This commit is contained in:
parent
7966367107
commit
e54879aeb1
@ -38,6 +38,7 @@
|
|||||||
let selectedReason = null;
|
let selectedReason = null;
|
||||||
let comment = '';
|
let comment = '';
|
||||||
|
|
||||||
|
let detailedRating = null;
|
||||||
let selectedModel = null;
|
let selectedModel = null;
|
||||||
|
|
||||||
$: if (message?.annotation?.rating === 1) {
|
$: if (message?.annotation?.rating === 1) {
|
||||||
@ -56,6 +57,7 @@
|
|||||||
tags = (message?.annotation?.tags ?? []).map((tag) => ({
|
tags = (message?.annotation?.tags ?? []).map((tag) => ({
|
||||||
name: tag
|
name: tag
|
||||||
}));
|
}));
|
||||||
|
detailedRating = message?.annotation?.details?.rating ?? null;
|
||||||
};
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@ -79,7 +81,10 @@
|
|||||||
dispatch('save', {
|
dispatch('save', {
|
||||||
reason: selectedReason,
|
reason: selectedReason,
|
||||||
comment: comment,
|
comment: comment,
|
||||||
tags: tags.map((tag) => tag.name)
|
tags: tags.map((tag) => tag.name),
|
||||||
|
details: {
|
||||||
|
rating: detailedRating
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
toast.success($i18n.t('Thanks for your feedback!'));
|
toast.success($i18n.t('Thanks for your feedback!'));
|
||||||
@ -100,7 +105,9 @@
|
|||||||
id="message-feedback-{message.id}"
|
id="message-feedback-{message.id}"
|
||||||
>
|
>
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<div class=" text-sm">{$i18n.t('Tell us more:')}</div>
|
<div class="text-sm font-medium">{$i18n.t('How would you rate this response?')}</div>
|
||||||
|
|
||||||
|
<!-- <div class=" text-sm">{$i18n.t('Tell us more:')}</div> -->
|
||||||
|
|
||||||
<button
|
<button
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
@ -120,14 +127,49 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full flex justify-center">
|
||||||
|
<div class=" relative w-fit">
|
||||||
|
<div class="mt-1.5 w-fit flex gap-1 pb-5">
|
||||||
|
<!-- 1-10 scale -->
|
||||||
|
{#each Array.from({ length: 10 }).map((_, i) => i + 1) as rating}
|
||||||
|
<button
|
||||||
|
class="size-7 text-sm border border-gray-50 dark:border-gray-850 hover:bg-gray-50 dark:hover:bg-gray-850 {detailedRating ===
|
||||||
|
rating
|
||||||
|
? 'bg-gray-100 dark:bg-gray-800'
|
||||||
|
: ''} transition rounded-full disabled:cursor-not-allowed disabled:bg-white disabled:dark:bg-gray-900"
|
||||||
|
on:click={() => {
|
||||||
|
detailedRating = rating;
|
||||||
|
}}
|
||||||
|
disabled={message?.annotation?.rating === -1 ? rating > 5 : rating < 6}
|
||||||
|
>
|
||||||
|
{rating}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="absolute bottom-0 left-0 right-0 flex justify-between text-xs">
|
||||||
|
<div>
|
||||||
|
1 - {$i18n.t('Awful')}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
10 - {$i18n.t('Amazing')}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
{#if reasons.length > 0}
|
{#if reasons.length > 0}
|
||||||
<div class="flex flex-wrap gap-1.5 text-sm mt-2.5">
|
<div class="text-sm mt-1.5 font-medium">{$i18n.t('Why?')}</div>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap gap-1.5 text-sm mt-1.5">
|
||||||
{#each reasons as reason}
|
{#each reasons as reason}
|
||||||
<button
|
<button
|
||||||
class="px-3 py-0.5 border border-gray-50 dark:border-gray-850 hover:bg-gray-100 dark:hover:bg-gray-850 {selectedReason ===
|
class="px-3 py-0.5 border border-gray-50 dark:border-gray-850 hover:bg-gray-50 dark:hover:bg-gray-850 {selectedReason ===
|
||||||
reason
|
reason
|
||||||
? 'bg-gray-200 dark:bg-gray-800'
|
? 'bg-gray-100 dark:bg-gray-800'
|
||||||
: ''} transition rounded-lg"
|
: ''} transition rounded-xl"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
selectedReason = reason;
|
selectedReason = reason;
|
||||||
}}
|
}}
|
||||||
@ -167,6 +209,7 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<textarea
|
<textarea
|
||||||
@ -195,7 +238,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class=" bg-emerald-700 hover:bg-emerald-800 transition text-white text-sm font-medium rounded-xl px-3.5 py-1.5"
|
class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
saveHandler();
|
saveHandler();
|
||||||
}}
|
}}
|
||||||
|
@ -340,19 +340,16 @@
|
|||||||
|
|
||||||
let feedbackLoading = false;
|
let feedbackLoading = false;
|
||||||
|
|
||||||
const feedbackHandler = async (
|
const feedbackHandler = async (rating: number | null = null, details: object | null = null) => {
|
||||||
rating: number | null = null,
|
|
||||||
annotation: object | null = null
|
|
||||||
) => {
|
|
||||||
feedbackLoading = true;
|
feedbackLoading = true;
|
||||||
console.log('Feedback', rating, annotation);
|
console.log('Feedback', rating, details);
|
||||||
|
|
||||||
const updatedMessage = {
|
const updatedMessage = {
|
||||||
...message,
|
...message,
|
||||||
annotation: {
|
annotation: {
|
||||||
...(message?.annotation ?? {}),
|
...(message?.annotation ?? {}),
|
||||||
...(rating !== null ? { rating: rating } : {}),
|
...(rating !== null ? { rating: rating } : {}),
|
||||||
...(annotation ? annotation : {})
|
...(details ? details : {})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -429,7 +426,7 @@
|
|||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
|
|
||||||
if (!annotation) {
|
if (!details) {
|
||||||
showRateComment = true;
|
showRateComment = true;
|
||||||
|
|
||||||
if (!updatedMessage.annotation?.tags) {
|
if (!updatedMessage.annotation?.tags) {
|
||||||
@ -1194,9 +1191,7 @@
|
|||||||
bind:show={showRateComment}
|
bind:show={showRateComment}
|
||||||
on:save={async (e) => {
|
on:save={async (e) => {
|
||||||
await feedbackHandler(null, {
|
await feedbackHandler(null, {
|
||||||
tags: e.detail.tags,
|
...e.detail
|
||||||
comment: e.detail.comment,
|
|
||||||
reason: e.detail.reason
|
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user