mirror of
https://github.com/open-webui/open-webui
synced 2025-04-23 15:55:23 +00:00
enh: enable message rating setting
This commit is contained in:
parent
5abe1076ed
commit
0fa85c5c64
@ -43,6 +43,7 @@ from config import (
|
|||||||
JWT_EXPIRES_IN,
|
JWT_EXPIRES_IN,
|
||||||
WEBUI_BANNERS,
|
WEBUI_BANNERS,
|
||||||
ENABLE_COMMUNITY_SHARING,
|
ENABLE_COMMUNITY_SHARING,
|
||||||
|
ENABLE_MESSAGE_RATING,
|
||||||
AppConfig,
|
AppConfig,
|
||||||
OAUTH_USERNAME_CLAIM,
|
OAUTH_USERNAME_CLAIM,
|
||||||
OAUTH_PICTURE_CLAIM,
|
OAUTH_PICTURE_CLAIM,
|
||||||
@ -81,6 +82,7 @@ app.state.config.WEBHOOK_URL = WEBHOOK_URL
|
|||||||
app.state.config.BANNERS = WEBUI_BANNERS
|
app.state.config.BANNERS = WEBUI_BANNERS
|
||||||
|
|
||||||
app.state.config.ENABLE_COMMUNITY_SHARING = ENABLE_COMMUNITY_SHARING
|
app.state.config.ENABLE_COMMUNITY_SHARING = ENABLE_COMMUNITY_SHARING
|
||||||
|
app.state.config.ENABLE_MESSAGE_RATING = ENABLE_MESSAGE_RATING
|
||||||
|
|
||||||
app.state.config.OAUTH_USERNAME_CLAIM = OAUTH_USERNAME_CLAIM
|
app.state.config.OAUTH_USERNAME_CLAIM = OAUTH_USERNAME_CLAIM
|
||||||
app.state.config.OAUTH_PICTURE_CLAIM = OAUTH_PICTURE_CLAIM
|
app.state.config.OAUTH_PICTURE_CLAIM = OAUTH_PICTURE_CLAIM
|
||||||
|
@ -352,6 +352,7 @@ async def get_admin_config(request: Request, user=Depends(get_admin_user)):
|
|||||||
"DEFAULT_USER_ROLE": request.app.state.config.DEFAULT_USER_ROLE,
|
"DEFAULT_USER_ROLE": request.app.state.config.DEFAULT_USER_ROLE,
|
||||||
"JWT_EXPIRES_IN": request.app.state.config.JWT_EXPIRES_IN,
|
"JWT_EXPIRES_IN": request.app.state.config.JWT_EXPIRES_IN,
|
||||||
"ENABLE_COMMUNITY_SHARING": request.app.state.config.ENABLE_COMMUNITY_SHARING,
|
"ENABLE_COMMUNITY_SHARING": request.app.state.config.ENABLE_COMMUNITY_SHARING,
|
||||||
|
"ENABLE_MESSAGE_RATING": request.app.state.config.ENABLE_MESSAGE_RATING,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -361,6 +362,7 @@ class AdminConfig(BaseModel):
|
|||||||
DEFAULT_USER_ROLE: str
|
DEFAULT_USER_ROLE: str
|
||||||
JWT_EXPIRES_IN: str
|
JWT_EXPIRES_IN: str
|
||||||
ENABLE_COMMUNITY_SHARING: bool
|
ENABLE_COMMUNITY_SHARING: bool
|
||||||
|
ENABLE_MESSAGE_RATING: bool
|
||||||
|
|
||||||
|
|
||||||
@router.post("/admin/config")
|
@router.post("/admin/config")
|
||||||
@ -382,6 +384,7 @@ async def update_admin_config(
|
|||||||
request.app.state.config.ENABLE_COMMUNITY_SHARING = (
|
request.app.state.config.ENABLE_COMMUNITY_SHARING = (
|
||||||
form_data.ENABLE_COMMUNITY_SHARING
|
form_data.ENABLE_COMMUNITY_SHARING
|
||||||
)
|
)
|
||||||
|
request.app.state.config.ENABLE_MESSAGE_RATING = form_data.ENABLE_MESSAGE_RATING
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"SHOW_ADMIN_DETAILS": request.app.state.config.SHOW_ADMIN_DETAILS,
|
"SHOW_ADMIN_DETAILS": request.app.state.config.SHOW_ADMIN_DETAILS,
|
||||||
@ -389,6 +392,7 @@ async def update_admin_config(
|
|||||||
"DEFAULT_USER_ROLE": request.app.state.config.DEFAULT_USER_ROLE,
|
"DEFAULT_USER_ROLE": request.app.state.config.DEFAULT_USER_ROLE,
|
||||||
"JWT_EXPIRES_IN": request.app.state.config.JWT_EXPIRES_IN,
|
"JWT_EXPIRES_IN": request.app.state.config.JWT_EXPIRES_IN,
|
||||||
"ENABLE_COMMUNITY_SHARING": request.app.state.config.ENABLE_COMMUNITY_SHARING,
|
"ENABLE_COMMUNITY_SHARING": request.app.state.config.ENABLE_COMMUNITY_SHARING,
|
||||||
|
"ENABLE_MESSAGE_RATING": request.app.state.config.ENABLE_MESSAGE_RATING,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -842,6 +842,12 @@ ENABLE_COMMUNITY_SHARING = PersistentConfig(
|
|||||||
os.environ.get("ENABLE_COMMUNITY_SHARING", "True").lower() == "true",
|
os.environ.get("ENABLE_COMMUNITY_SHARING", "True").lower() == "true",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ENABLE_MESSAGE_RATING = PersistentConfig(
|
||||||
|
"ENABLE_MESSAGE_RATING",
|
||||||
|
"ui.enable_message_rating",
|
||||||
|
os.environ.get("ENABLE_MESSAGE_RATING", "True").lower() == "true",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_cors_origins(origins):
|
def validate_cors_origins(origins):
|
||||||
for origin in origins:
|
for origin in origins:
|
||||||
|
@ -1973,6 +1973,7 @@ async def get_app_config():
|
|||||||
"enable_web_search": rag_app.state.config.ENABLE_RAG_WEB_SEARCH,
|
"enable_web_search": rag_app.state.config.ENABLE_RAG_WEB_SEARCH,
|
||||||
"enable_image_generation": images_app.state.config.ENABLED,
|
"enable_image_generation": images_app.state.config.ENABLED,
|
||||||
"enable_community_sharing": webui_app.state.config.ENABLE_COMMUNITY_SHARING,
|
"enable_community_sharing": webui_app.state.config.ENABLE_COMMUNITY_SHARING,
|
||||||
|
"enable_message_rating": webui_app.state.config.ENABLE_MESSAGE_RATING,
|
||||||
"enable_admin_export": ENABLE_ADMIN_EXPORT,
|
"enable_admin_export": ENABLE_ADMIN_EXPORT,
|
||||||
"enable_admin_chat_access": ENABLE_ADMIN_CHAT_ACCESS,
|
"enable_admin_chat_access": ENABLE_ADMIN_CHAT_ACCESS,
|
||||||
},
|
},
|
||||||
|
@ -336,8 +336,11 @@
|
|||||||
<div class="flex-1 mt-3 lg:mt-0 overflow-y-scroll">
|
<div class="flex-1 mt-3 lg:mt-0 overflow-y-scroll">
|
||||||
{#if selectedTab === 'general'}
|
{#if selectedTab === 'general'}
|
||||||
<General
|
<General
|
||||||
saveHandler={() => {
|
saveHandler={async () => {
|
||||||
toast.success($i18n.t('Settings saved successfully!'));
|
toast.success($i18n.t('Settings saved successfully!'));
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
await config.set(await getBackendConfig());
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{:else if selectedTab === 'users'}
|
{:else if selectedTab === 'users'}
|
||||||
|
@ -1,22 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import { getBackendConfig, getWebhookUrl, updateWebhookUrl } from '$lib/apis';
|
||||||
getCommunitySharingEnabledStatus,
|
import { getAdminConfig, updateAdminConfig } from '$lib/apis/auths';
|
||||||
getWebhookUrl,
|
|
||||||
toggleCommunitySharingEnabledStatus,
|
|
||||||
updateWebhookUrl
|
|
||||||
} from '$lib/apis';
|
|
||||||
import {
|
|
||||||
getAdminConfig,
|
|
||||||
getDefaultUserRole,
|
|
||||||
getJWTExpiresDuration,
|
|
||||||
getSignUpEnabledStatus,
|
|
||||||
toggleSignUpEnabledStatus,
|
|
||||||
updateAdminConfig,
|
|
||||||
updateDefaultUserRole,
|
|
||||||
updateJWTExpiresDuration
|
|
||||||
} from '$lib/apis/auths';
|
|
||||||
import Switch from '$lib/components/common/Switch.svelte';
|
import Switch from '$lib/components/common/Switch.svelte';
|
||||||
|
import { config } from '$lib/stores';
|
||||||
import { onMount, getContext } from 'svelte';
|
import { onMount, getContext } from 'svelte';
|
||||||
|
import { toast } from 'svelte-sonner';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
@ -30,7 +18,7 @@
|
|||||||
const res = await updateAdminConfig(localStorage.token, adminConfig);
|
const res = await updateAdminConfig(localStorage.token, adminConfig);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
toast.success(i18n.t('Settings updated successfully'));
|
saveHandler();
|
||||||
} else {
|
} else {
|
||||||
toast.error(i18n.t('Failed to update settings'));
|
toast.error(i18n.t('Failed to update settings'));
|
||||||
}
|
}
|
||||||
@ -51,9 +39,8 @@
|
|||||||
|
|
||||||
<form
|
<form
|
||||||
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
||||||
on:submit|preventDefault={() => {
|
on:submit|preventDefault={async () => {
|
||||||
updateHandler();
|
updateHandler();
|
||||||
saveHandler();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class=" space-y-3 overflow-y-scroll scrollbar-hidden h-full">
|
<div class=" space-y-3 overflow-y-scroll scrollbar-hidden h-full">
|
||||||
@ -98,6 +85,12 @@
|
|||||||
<Switch bind:state={adminConfig.ENABLE_COMMUNITY_SHARING} />
|
<Switch bind:state={adminConfig.ENABLE_COMMUNITY_SHARING} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="my-3 flex w-full items-center justify-between pr-2">
|
||||||
|
<div class=" self-center text-xs font-medium">{$i18n.t('Enable Message Rating')}</div>
|
||||||
|
|
||||||
|
<Switch bind:state={adminConfig.ENABLE_MESSAGE_RATING} />
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr class=" dark:border-gray-850 my-2" />
|
<hr class=" dark:border-gray-850 my-2" />
|
||||||
|
|
||||||
<div class=" w-full justify-between">
|
<div class=" w-full justify-between">
|
||||||
|
@ -719,103 +719,105 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if !readOnly}
|
{#if !readOnly}
|
||||||
<Tooltip content={$i18n.t('Good Response')} placement="bottom">
|
{#if $config?.features.enable_message_rating ?? true}
|
||||||
<button
|
<Tooltip content={$i18n.t('Good Response')} placement="bottom">
|
||||||
class="{isLastMessage
|
<button
|
||||||
? 'visible'
|
class="{isLastMessage
|
||||||
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg {(message
|
? 'visible'
|
||||||
?.annotation?.rating ?? null) === 1
|
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg {(message
|
||||||
? 'bg-gray-100 dark:bg-gray-800'
|
?.annotation?.rating ?? null) === 1
|
||||||
: ''} dark:hover:text-white hover:text-black transition"
|
? 'bg-gray-100 dark:bg-gray-800'
|
||||||
on:click={async () => {
|
: ''} dark:hover:text-white hover:text-black transition"
|
||||||
await rateMessage(message.id, 1);
|
on:click={async () => {
|
||||||
|
await rateMessage(message.id, 1);
|
||||||
|
|
||||||
(model?.actions ?? [])
|
(model?.actions ?? [])
|
||||||
.filter((action) => action?.__webui__ ?? false)
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
.forEach((action) => {
|
.forEach((action) => {
|
||||||
dispatch('action', {
|
dispatch('action', {
|
||||||
id: action.id,
|
id: action.id,
|
||||||
event: {
|
event: {
|
||||||
id: 'good-response',
|
id: 'good-response',
|
||||||
data: {
|
data: {
|
||||||
messageId: message.id
|
messageId: message.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
showRateComment = true;
|
showRateComment = true;
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
document
|
document
|
||||||
.getElementById(`message-feedback-${message.id}`)
|
.getElementById(`message-feedback-${message.id}`)
|
||||||
?.scrollIntoView();
|
?.scrollIntoView();
|
||||||
}, 0);
|
}, 0);
|
||||||
}}
|
}}
|
||||||
>
|
|
||||||
<svg
|
|
||||||
stroke="currentColor"
|
|
||||||
fill="none"
|
|
||||||
stroke-width="2.3"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
class="w-4 h-4"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
><path
|
|
||||||
d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"
|
|
||||||
/></svg
|
|
||||||
>
|
>
|
||||||
</button>
|
<svg
|
||||||
</Tooltip>
|
stroke="currentColor"
|
||||||
|
fill="none"
|
||||||
|
stroke-width="2.3"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="w-4 h-4"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
><path
|
||||||
|
d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"
|
||||||
|
/></svg
|
||||||
|
>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
<Tooltip content={$i18n.t('Bad Response')} placement="bottom">
|
<Tooltip content={$i18n.t('Bad Response')} placement="bottom">
|
||||||
<button
|
<button
|
||||||
class="{isLastMessage
|
class="{isLastMessage
|
||||||
? 'visible'
|
? 'visible'
|
||||||
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg {(message
|
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg {(message
|
||||||
?.annotation?.rating ?? null) === -1
|
?.annotation?.rating ?? null) === -1
|
||||||
? 'bg-gray-100 dark:bg-gray-800'
|
? 'bg-gray-100 dark:bg-gray-800'
|
||||||
: ''} dark:hover:text-white hover:text-black transition"
|
: ''} dark:hover:text-white hover:text-black transition"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
await rateMessage(message.id, -1);
|
await rateMessage(message.id, -1);
|
||||||
|
|
||||||
(model?.actions ?? [])
|
(model?.actions ?? [])
|
||||||
.filter((action) => action?.__webui__ ?? false)
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
.forEach((action) => {
|
.forEach((action) => {
|
||||||
dispatch('action', {
|
dispatch('action', {
|
||||||
id: action.id,
|
id: action.id,
|
||||||
event: {
|
event: {
|
||||||
id: 'bad-response',
|
id: 'bad-response',
|
||||||
data: {
|
data: {
|
||||||
messageId: message.id
|
messageId: message.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
showRateComment = true;
|
showRateComment = true;
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
document
|
document
|
||||||
.getElementById(`message-feedback-${message.id}`)
|
.getElementById(`message-feedback-${message.id}`)
|
||||||
?.scrollIntoView();
|
?.scrollIntoView();
|
||||||
}, 0);
|
}, 0);
|
||||||
}}
|
}}
|
||||||
>
|
|
||||||
<svg
|
|
||||||
stroke="currentColor"
|
|
||||||
fill="none"
|
|
||||||
stroke-width="2.3"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
class="w-4 h-4"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
><path
|
|
||||||
d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"
|
|
||||||
/></svg
|
|
||||||
>
|
>
|
||||||
</button>
|
<svg
|
||||||
</Tooltip>
|
stroke="currentColor"
|
||||||
|
fill="none"
|
||||||
|
stroke-width="2.3"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="w-4 h-4"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
><path
|
||||||
|
d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"
|
||||||
|
/></svg
|
||||||
|
>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if isLastMessage}
|
{#if isLastMessage}
|
||||||
<Tooltip content={$i18n.t('Continue Response')} placement="bottom">
|
<Tooltip content={$i18n.t('Continue Response')} placement="bottom">
|
||||||
|
Loading…
Reference in New Issue
Block a user