2024-04-08 10:08:30 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { toast } from 'svelte-sonner';
|
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
import { createEventDispatcher, onMount, getContext } from 'svelte';
|
2024-10-23 01:05:30 +00:00
|
|
|
import { config, models } from '$lib/stores';
|
2024-10-24 03:18:51 +00:00
|
|
|
import Tags from '$lib/components/common/Tags.svelte';
|
2024-04-20 18:35:01 +00:00
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
const i18n = getContext('i18n');
|
2024-04-08 10:08:30 +00:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
export let message;
|
2024-09-24 12:02:41 +00:00
|
|
|
export let show = false;
|
2024-04-08 10:08:30 +00:00
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
let LIKE_REASONS = [];
|
|
|
|
let DISLIKE_REASONS = [];
|
|
|
|
|
2024-10-24 03:18:51 +00:00
|
|
|
let tags = [];
|
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
function loadReasons() {
|
|
|
|
LIKE_REASONS = [
|
2024-10-24 03:18:51 +00:00
|
|
|
'accurate_information',
|
|
|
|
'followed_instructions_perfectly',
|
|
|
|
'showcased_creativity',
|
|
|
|
'positive_attitude',
|
|
|
|
'attention_to_detail',
|
|
|
|
'thorough_explanation',
|
|
|
|
'other'
|
2024-04-20 04:51:11 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
DISLIKE_REASONS = [
|
2024-10-24 03:18:51 +00:00
|
|
|
'dont_like_the_style',
|
|
|
|
'too_verbose',
|
|
|
|
'not_helpful',
|
|
|
|
'not_factually_correct',
|
|
|
|
'didnt_fully_follow_instructions',
|
|
|
|
'refused_when_it_shouldnt_have',
|
|
|
|
'being_lazy',
|
|
|
|
'other'
|
2024-04-20 04:51:11 +00:00
|
|
|
];
|
|
|
|
}
|
2024-04-08 10:08:30 +00:00
|
|
|
|
|
|
|
let reasons = [];
|
|
|
|
let selectedReason = null;
|
|
|
|
let comment = '';
|
|
|
|
|
2024-10-23 01:05:30 +00:00
|
|
|
let selectedModel = null;
|
|
|
|
|
2024-05-13 21:27:58 +00:00
|
|
|
$: if (message?.annotation?.rating === 1) {
|
2024-04-08 10:08:30 +00:00
|
|
|
reasons = LIKE_REASONS;
|
2024-05-13 21:27:58 +00:00
|
|
|
} else if (message?.annotation?.rating === -1) {
|
2024-04-08 10:08:30 +00:00
|
|
|
reasons = DISLIKE_REASONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
2024-06-11 01:53:33 +00:00
|
|
|
selectedReason = message?.annotation?.reason ?? '';
|
2024-06-11 01:55:45 +00:00
|
|
|
comment = message?.annotation?.comment ?? '';
|
2024-10-24 03:18:51 +00:00
|
|
|
tags = (message?.annotation?.tags ?? []).map((tag) => ({
|
|
|
|
name: tag
|
|
|
|
}));
|
2024-10-23 01:05:30 +00:00
|
|
|
|
|
|
|
if (message?.arena) {
|
|
|
|
selectedModel = $models.find((m) => m.id === message.selectedModelId);
|
|
|
|
toast.success(
|
|
|
|
$i18n.t('This response was generated by "{{model}}"', {
|
2024-10-23 22:35:40 +00:00
|
|
|
model: selectedModel ? (selectedModel?.name ?? selectedModel.id) : message.selectedModelId
|
2024-10-23 01:05:30 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
loadReasons();
|
2024-04-08 10:08:30 +00:00
|
|
|
});
|
|
|
|
|
2024-10-15 03:35:06 +00:00
|
|
|
const saveHandler = () => {
|
|
|
|
console.log('saveHandler');
|
2024-10-24 03:18:51 +00:00
|
|
|
// if (!selectedReason) {
|
|
|
|
// toast.error($i18n.t('Please select a reason'));
|
|
|
|
// return;
|
|
|
|
// }
|
2024-04-08 10:08:30 +00:00
|
|
|
|
2024-10-15 03:35:06 +00:00
|
|
|
dispatch('save', {
|
2024-08-15 15:28:43 +00:00
|
|
|
reason: selectedReason,
|
2024-10-24 03:18:51 +00:00
|
|
|
comment: comment,
|
2024-10-24 03:19:42 +00:00
|
|
|
tags: tags.map((tag) => tag.name)
|
2024-08-15 15:28:43 +00:00
|
|
|
});
|
2024-04-08 10:08:30 +00:00
|
|
|
|
2024-04-20 04:51:11 +00:00
|
|
|
toast.success($i18n.t('Thanks for your feedback!'));
|
2024-04-08 10:08:30 +00:00
|
|
|
show = false;
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2024-10-23 23:59:54 +00:00
|
|
|
{#if message?.arena}
|
2024-10-24 03:18:51 +00:00
|
|
|
<div class="text-xs font-medium pt-1.5 -mb-0.5">
|
2024-10-23 22:35:40 +00:00
|
|
|
{$i18n.t('This response was generated by "{{model}}"', {
|
|
|
|
model: selectedModel ? (selectedModel?.name ?? selectedModel.id) : message.selectedModelId
|
|
|
|
})}
|
2024-10-23 01:05:30 +00:00
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
2024-04-21 00:10:05 +00:00
|
|
|
<div
|
2024-10-17 07:51:46 +00:00
|
|
|
class=" my-2.5 rounded-xl px-4 py-3 border border-gray-50 dark:border-gray-850"
|
2024-09-24 12:02:41 +00:00
|
|
|
id="message-feedback-{message.id}"
|
2024-04-21 00:10:05 +00:00
|
|
|
>
|
2024-04-08 10:08:30 +00:00
|
|
|
<div class="flex justify-between items-center">
|
2024-04-20 04:51:11 +00:00
|
|
|
<div class=" text-sm">{$i18n.t('Tell us more:')}</div>
|
2024-04-08 10:08:30 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
on:click={() => {
|
|
|
|
show = false;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
fill="none"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5"
|
|
|
|
stroke="currentColor"
|
|
|
|
class="size-4"
|
|
|
|
>
|
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if reasons.length > 0}
|
2024-10-24 03:18:51 +00:00
|
|
|
<div class="flex flex-wrap gap-1.5 text-sm mt-2.5">
|
2024-04-08 10:08:30 +00:00
|
|
|
{#each reasons as reason}
|
|
|
|
<button
|
2024-10-24 03:18:51 +00:00
|
|
|
class="px-3 py-0.5 border border-gray-50 dark:border-gray-850 hover:bg-gray-100 dark:hover:bg-gray-850 {selectedReason ===
|
2024-04-08 10:08:30 +00:00
|
|
|
reason
|
2024-04-20 04:03:47 +00:00
|
|
|
? 'bg-gray-200 dark:bg-gray-800'
|
2024-04-08 10:08:30 +00:00
|
|
|
: ''} transition rounded-lg"
|
|
|
|
on:click={() => {
|
|
|
|
selectedReason = reason;
|
|
|
|
}}
|
|
|
|
>
|
2024-10-24 03:18:51 +00:00
|
|
|
{#if reason === 'accurate_information'}
|
|
|
|
{$i18n.t('Accurate information')}
|
|
|
|
{:else if reason === 'followed_instructions_perfectly'}
|
|
|
|
{$i18n.t('Followed instructions perfectly')}
|
|
|
|
{:else if reason === 'showcased_creativity'}
|
|
|
|
{$i18n.t('Showcased creativity')}
|
|
|
|
{:else if reason === 'positive_attitude'}
|
|
|
|
{$i18n.t('Positive attitude')}
|
|
|
|
{:else if reason === 'attention_to_detail'}
|
|
|
|
{$i18n.t('Attention to detail')}
|
|
|
|
{:else if reason === 'thorough_explanation'}
|
|
|
|
{$i18n.t('Thorough explanation')}
|
|
|
|
{:else if reason === 'dont_like_the_style'}
|
|
|
|
{$i18n.t("Don't like the style")}
|
|
|
|
{:else if reason === 'too_verbose'}
|
|
|
|
{$i18n.t('Too verbose')}
|
|
|
|
{:else if reason === 'not_helpful'}
|
|
|
|
{$i18n.t('Not helpful')}
|
|
|
|
{:else if reason === 'not_factually_correct'}
|
|
|
|
{$i18n.t('Not factually correct')}
|
|
|
|
{:else if reason === 'didnt_fully_follow_instructions'}
|
|
|
|
{$i18n.t("Didn't fully follow instructions")}
|
|
|
|
{:else if reason === 'refused_when_it_shouldnt_have'}
|
|
|
|
{$i18n.t("Refused when it shouldn't have")}
|
|
|
|
{:else if reason === 'being_lazy'}
|
|
|
|
{$i18n.t('Being lazy')}
|
|
|
|
{:else if reason === 'other'}
|
|
|
|
{$i18n.t('Other')}
|
|
|
|
{:else}
|
|
|
|
{reason}
|
|
|
|
{/if}
|
2024-04-08 10:08:30 +00:00
|
|
|
</button>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<div class="mt-2">
|
|
|
|
<textarea
|
|
|
|
bind:value={comment}
|
|
|
|
class="w-full text-sm px-1 py-2 bg-transparent outline-none resize-none rounded-xl"
|
2024-04-20 18:35:01 +00:00
|
|
|
placeholder={$i18n.t('Feel free to add specific details')}
|
2024-10-24 03:18:51 +00:00
|
|
|
rows="3"
|
2024-04-08 10:08:30 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2024-10-24 03:18:51 +00:00
|
|
|
<div class="mt-2 gap-1.5 flex justify-between">
|
|
|
|
<div class="flex items-end group">
|
|
|
|
<Tags
|
|
|
|
{tags}
|
|
|
|
on:delete={(e) => {
|
|
|
|
tags = tags.filter(
|
|
|
|
(tag) =>
|
|
|
|
tag.name.replaceAll(' ', '_').toLowerCase() !==
|
|
|
|
e.detail.replaceAll(' ', '_').toLowerCase()
|
|
|
|
);
|
2024-10-17 07:51:46 +00:00
|
|
|
}}
|
2024-10-24 03:18:51 +00:00
|
|
|
on:add={(e) => {
|
|
|
|
tags = [...tags, { name: e.detail }];
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-10-17 07:51:46 +00:00
|
|
|
|
2024-04-08 10:08:30 +00:00
|
|
|
<button
|
2024-10-17 07:51:46 +00:00
|
|
|
class=" bg-emerald-700 hover:bg-emerald-800 transition text-white text-sm font-medium rounded-xl px-3.5 py-1.5"
|
2024-04-08 10:08:30 +00:00
|
|
|
on:click={() => {
|
2024-10-15 03:35:06 +00:00
|
|
|
saveHandler();
|
2024-04-08 10:08:30 +00:00
|
|
|
}}
|
|
|
|
>
|
2024-10-15 03:35:06 +00:00
|
|
|
{$i18n.t('Save')}
|
2024-04-08 10:08:30 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|