mirror of
https://github.com/open-webui/open-webui
synced 2025-04-22 23:35:26 +00:00
refac: feedback
This commit is contained in:
parent
bc95e62600
commit
ce85400817
@ -23,9 +23,11 @@ class Feedback(Base):
|
|||||||
__tablename__ = "feedback"
|
__tablename__ = "feedback"
|
||||||
id = Column(Text, primary_key=True)
|
id = Column(Text, primary_key=True)
|
||||||
user_id = Column(Text)
|
user_id = Column(Text)
|
||||||
|
version = Column(BigInteger, default=0)
|
||||||
type = Column(Text)
|
type = Column(Text)
|
||||||
data = Column(JSON, nullable=True)
|
data = Column(JSON, nullable=True)
|
||||||
meta = Column(JSON, nullable=True)
|
meta = Column(JSON, nullable=True)
|
||||||
|
snapshot = Column(JSON, nullable=True)
|
||||||
created_at = Column(BigInteger)
|
created_at = Column(BigInteger)
|
||||||
updated_at = Column(BigInteger)
|
updated_at = Column(BigInteger)
|
||||||
|
|
||||||
@ -33,9 +35,11 @@ class Feedback(Base):
|
|||||||
class FeedbackModel(BaseModel):
|
class FeedbackModel(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
user_id: str
|
user_id: str
|
||||||
|
version: int
|
||||||
type: str
|
type: str
|
||||||
data: Optional[dict] = None
|
data: Optional[dict] = None
|
||||||
meta: Optional[dict] = None
|
meta: Optional[dict] = None
|
||||||
|
snapshot: Optional[dict] = None
|
||||||
created_at: int
|
created_at: int
|
||||||
updated_at: int
|
updated_at: int
|
||||||
|
|
||||||
@ -47,30 +51,44 @@ class FeedbackModel(BaseModel):
|
|||||||
####################
|
####################
|
||||||
|
|
||||||
|
|
||||||
|
class FeedbackResponse(BaseModel):
|
||||||
|
id: str
|
||||||
|
user_id: str
|
||||||
|
version: int
|
||||||
|
type: str
|
||||||
|
data: Optional[dict] = None
|
||||||
|
meta: Optional[dict] = None
|
||||||
|
created_at: int
|
||||||
|
updated_at: int
|
||||||
|
|
||||||
|
|
||||||
class RatingData(BaseModel):
|
class RatingData(BaseModel):
|
||||||
rating: str
|
rating: Optional[str | int] = None
|
||||||
comment: str
|
model_id: Optional[str] = None
|
||||||
model_config = ConfigDict(extra="allow")
|
sibling_model_ids: Optional[list[str]] = None
|
||||||
|
reason: Optional[str] = None
|
||||||
|
comment: Optional[str] = None
|
||||||
class VoteData(BaseModel):
|
|
||||||
rating: str
|
|
||||||
model_id: str
|
|
||||||
model_ids: list[str]
|
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
class MetaData(BaseModel):
|
class MetaData(BaseModel):
|
||||||
chat: Optional[dict] = None
|
arena: Optional[bool] = None
|
||||||
|
chat_id: Optional[str] = None
|
||||||
message_id: Optional[str] = None
|
message_id: Optional[str] = None
|
||||||
tags: Optional[list[str]] = None
|
tags: Optional[list[str]] = None
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
|
class SnapshotData(BaseModel):
|
||||||
|
chat: Optional[dict] = None
|
||||||
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
class FeedbackForm(BaseModel):
|
class FeedbackForm(BaseModel):
|
||||||
type: str
|
type: str
|
||||||
data: Optional[RatingData | VoteData] = None
|
data: Optional[RatingData] = None
|
||||||
meta: Optional[dict] = None
|
meta: Optional[dict] = None
|
||||||
|
snapshot: Optional[SnapshotData] = None
|
||||||
model_config = ConfigDict(extra="allow")
|
model_config = ConfigDict(extra="allow")
|
||||||
|
|
||||||
|
|
||||||
@ -84,10 +102,10 @@ class FeedbackTable:
|
|||||||
**{
|
**{
|
||||||
"id": id,
|
"id": id,
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"type": form_data.type,
|
"version": 0,
|
||||||
"data": form_data.data,
|
**form_data.model_dump(),
|
||||||
"meta": form_data.meta,
|
|
||||||
"created_at": int(time.time()),
|
"created_at": int(time.time()),
|
||||||
|
"updated_at": int(time.time()),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
@ -113,6 +131,25 @@ class FeedbackTable:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_feedback_by_id_and_user_id(
|
||||||
|
self, id: str, user_id: str
|
||||||
|
) -> Optional[FeedbackModel]:
|
||||||
|
try:
|
||||||
|
with get_db() as db:
|
||||||
|
feedback = db.query(Feedback).filter_by(id=id, user_id=user_id).first()
|
||||||
|
if not feedback:
|
||||||
|
return None
|
||||||
|
return FeedbackModel.model_validate(feedback)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_all_feedbacks(self) -> list[FeedbackModel]:
|
||||||
|
with get_db() as db:
|
||||||
|
return [
|
||||||
|
FeedbackModel.model_validate(feedback)
|
||||||
|
for feedback in db.query(Feedback).all()
|
||||||
|
]
|
||||||
|
|
||||||
def get_feedbacks_by_type(self, type: str) -> list[FeedbackModel]:
|
def get_feedbacks_by_type(self, type: str) -> list[FeedbackModel]:
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
return [
|
return [
|
||||||
@ -136,9 +173,31 @@ class FeedbackTable:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if form_data.data:
|
if form_data.data:
|
||||||
feedback.data = form_data.data
|
feedback.data = form_data.data.model_dump()
|
||||||
if form_data.meta:
|
if form_data.meta:
|
||||||
feedback.meta = form_data.meta
|
feedback.meta = form_data.meta
|
||||||
|
if form_data.snapshot:
|
||||||
|
feedback.snapshot = form_data.snapshot.model_dump()
|
||||||
|
|
||||||
|
feedback.updated_at = int(time.time())
|
||||||
|
|
||||||
|
db.commit()
|
||||||
|
return FeedbackModel.model_validate(feedback)
|
||||||
|
|
||||||
|
def update_feedback_by_id_and_user_id(
|
||||||
|
self, id: str, user_id: str, form_data: FeedbackForm
|
||||||
|
) -> Optional[FeedbackModel]:
|
||||||
|
with get_db() as db:
|
||||||
|
feedback = db.query(Feedback).filter_by(id=id, user_id=user_id).first()
|
||||||
|
if not feedback:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if form_data.data:
|
||||||
|
feedback.data = form_data.data.model_dump()
|
||||||
|
if form_data.meta:
|
||||||
|
feedback.meta = form_data.meta
|
||||||
|
if form_data.snapshot:
|
||||||
|
feedback.snapshot = form_data.snapshot.model_dump()
|
||||||
|
|
||||||
feedback.updated_at = int(time.time())
|
feedback.updated_at = int(time.time())
|
||||||
|
|
||||||
@ -154,5 +213,34 @@ class FeedbackTable:
|
|||||||
db.commit()
|
db.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def delete_feedback_by_id_and_user_id(self, id: str, user_id: str) -> bool:
|
||||||
|
with get_db() as db:
|
||||||
|
feedback = db.query(Feedback).filter_by(id=id, user_id=user_id).first()
|
||||||
|
if not feedback:
|
||||||
|
return False
|
||||||
|
db.delete(feedback)
|
||||||
|
db.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def delete_feedbacks_by_user_id(self, user_id: str) -> bool:
|
||||||
|
with get_db() as db:
|
||||||
|
feedbacks = db.query(Feedback).filter_by(user_id=user_id).all()
|
||||||
|
if not feedbacks:
|
||||||
|
return False
|
||||||
|
for feedback in feedbacks:
|
||||||
|
db.delete(feedback)
|
||||||
|
db.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def delete_all_feedbacks(self) -> bool:
|
||||||
|
with get_db() as db:
|
||||||
|
feedbacks = db.query(Feedback).all()
|
||||||
|
if not feedbacks:
|
||||||
|
return False
|
||||||
|
for feedback in feedbacks:
|
||||||
|
db.delete(feedback)
|
||||||
|
db.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
Feedbacks = FeedbackTable()
|
Feedbacks = FeedbackTable()
|
||||||
|
@ -3,6 +3,12 @@ from fastapi import APIRouter, Depends, HTTPException, status, Request
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
from open_webui.apps.webui.models.feedbacks import (
|
||||||
|
FeedbackModel,
|
||||||
|
FeedbackForm,
|
||||||
|
Feedbacks,
|
||||||
|
)
|
||||||
|
|
||||||
from open_webui.constants import ERROR_MESSAGES
|
from open_webui.constants import ERROR_MESSAGES
|
||||||
from open_webui.utils.utils import get_admin_user, get_verified_user
|
from open_webui.utils.utils import get_admin_user, get_verified_user
|
||||||
|
|
||||||
@ -47,3 +53,86 @@ async def update_config(
|
|||||||
"ENABLE_EVALUATION_ARENA_MODELS": config.ENABLE_EVALUATION_ARENA_MODELS,
|
"ENABLE_EVALUATION_ARENA_MODELS": config.ENABLE_EVALUATION_ARENA_MODELS,
|
||||||
"EVALUATION_ARENA_MODELS": config.EVALUATION_ARENA_MODELS,
|
"EVALUATION_ARENA_MODELS": config.EVALUATION_ARENA_MODELS,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/feedbacks", response_model=list[FeedbackModel])
|
||||||
|
async def get_feedbacks(user=Depends(get_verified_user)):
|
||||||
|
feedbacks = Feedbacks.get_feedbacks_by_user_id(user.id)
|
||||||
|
return feedbacks
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/feedbacks", response_model=bool)
|
||||||
|
async def delete_feedbacks(user=Depends(get_verified_user)):
|
||||||
|
success = Feedbacks.delete_feedbacks_by_user_id(user.id)
|
||||||
|
return success
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/feedbacks/all")
|
||||||
|
async def delete_all_feedbacks(user=Depends(get_admin_user)):
|
||||||
|
success = Feedbacks.delete_all_feedbacks()
|
||||||
|
return success
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/feedbacks/all", response_model=list[FeedbackModel])
|
||||||
|
async def get_all_feedbacks(user=Depends(get_admin_user)):
|
||||||
|
feedbacks = Feedbacks.get_all_feedbacks()
|
||||||
|
return feedbacks
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/feedback", response_model=FeedbackModel)
|
||||||
|
async def create_feedback(
|
||||||
|
request: Request,
|
||||||
|
form_data: FeedbackForm,
|
||||||
|
user=Depends(get_verified_user),
|
||||||
|
):
|
||||||
|
feedback = Feedbacks.insert_new_feedback(user_id=user.id, form_data=form_data)
|
||||||
|
if not feedback:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail=ERROR_MESSAGES.DEFAULT(),
|
||||||
|
)
|
||||||
|
|
||||||
|
return feedback
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/feedback/{id}", response_model=FeedbackModel)
|
||||||
|
async def get_feedback_by_id(id: str, user=Depends(get_verified_user)):
|
||||||
|
feedback = Feedbacks.get_feedback_by_id_and_user_id(id=id, user_id=user.id)
|
||||||
|
|
||||||
|
if not feedback:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
|
return feedback
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/feedback/{id}", response_model=FeedbackModel)
|
||||||
|
async def update_feedback_by_id(
|
||||||
|
id: str, form_data: FeedbackForm, user=Depends(get_verified_user)
|
||||||
|
):
|
||||||
|
feedback = Feedbacks.update_feedback_by_id_and_user_id(
|
||||||
|
id=id, user_id=user.id, form_data=form_data
|
||||||
|
)
|
||||||
|
|
||||||
|
if not feedback:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
|
return feedback
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/feedback/{id}")
|
||||||
|
async def delete_feedback_by_id(id: str, user=Depends(get_verified_user)):
|
||||||
|
if user.role == "admin":
|
||||||
|
success = Feedbacks.delete_feedback_by_id(id=id)
|
||||||
|
else:
|
||||||
|
success = Feedbacks.delete_feedback_by_id_and_user_id(id=id, user_id=user.id)
|
||||||
|
|
||||||
|
if not success:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
|
return success
|
||||||
|
@ -26,11 +26,17 @@ def upgrade():
|
|||||||
sa.Column(
|
sa.Column(
|
||||||
"user_id", sa.Text(), nullable=True
|
"user_id", sa.Text(), nullable=True
|
||||||
), # ID of the user providing the feedback (TEXT type)
|
), # ID of the user providing the feedback (TEXT type)
|
||||||
|
sa.Column(
|
||||||
|
"version", sa.BigInteger(), default=0
|
||||||
|
), # Version of feedback (BIGINT type)
|
||||||
sa.Column("type", sa.Text(), nullable=True), # Type of feedback (TEXT type)
|
sa.Column("type", sa.Text(), nullable=True), # Type of feedback (TEXT type)
|
||||||
sa.Column("data", sa.JSON(), nullable=True), # Feedback data (JSON type)
|
sa.Column("data", sa.JSON(), nullable=True), # Feedback data (JSON type)
|
||||||
sa.Column(
|
sa.Column(
|
||||||
"meta", sa.JSON(), nullable=True
|
"meta", sa.JSON(), nullable=True
|
||||||
), # Metadata for feedback (JSON type)
|
), # Metadata for feedback (JSON type)
|
||||||
|
sa.Column(
|
||||||
|
"snapshot", sa.JSON(), nullable=True
|
||||||
|
), # snapshot data for feedback (JSON type)
|
||||||
sa.Column(
|
sa.Column(
|
||||||
"created_at", sa.BigInteger(), nullable=False
|
"created_at", sa.BigInteger(), nullable=False
|
||||||
), # Feedback creation timestamp (BIGINT representing epoch)
|
), # Feedback creation timestamp (BIGINT representing epoch)
|
||||||
|
@ -61,3 +61,155 @@ export const updateConfig = async (token: string, config: object) => {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAllFeedbacks = async (token: string = '') => {
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
const res = await fetch(`${WEBUI_API_BASE_URL}/evaluations/feedbacks/all`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then((json) => {
|
||||||
|
return json;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
error = err.detail;
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createNewFeedback = async (token: string, feedback: object) => {
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
const res = await fetch(`${WEBUI_API_BASE_URL}/evaluations/feedback`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
authorization: `Bearer ${token}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
...feedback
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
error = err.detail;
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getFeedbackById = async (token: string, feedbackId: string) => {
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
const res = await fetch(`${WEBUI_API_BASE_URL}/evaluations/feedback/${feedbackId}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then((json) => {
|
||||||
|
return json;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
error = err.detail;
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateFeedbackById = async (token: string, feedbackId: string, feedback: object) => {
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
const res = await fetch(`${WEBUI_API_BASE_URL}/evaluations/feedback/${feedbackId}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
authorization: `Bearer ${token}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
...feedback
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
error = err.detail;
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteFeedbackById = async (token: string, feedbackId: string) => {
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
const res = await fetch(`${WEBUI_API_BASE_URL}/evaluations/feedback/${feedbackId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
error = err.detail;
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
@ -2,19 +2,24 @@
|
|||||||
import { onMount, getContext } from 'svelte';
|
import { onMount, getContext } from 'svelte';
|
||||||
|
|
||||||
import { models } from '$lib/stores';
|
import { models } from '$lib/stores';
|
||||||
|
import GarbageBin from '../icons/GarbageBin.svelte';
|
||||||
|
import FeedbackMenu from './Evaluations/FeedbackMenu.svelte';
|
||||||
|
import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte';
|
||||||
|
import { getAllFeedbacks } from '$lib/apis/evaluations';
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
let rankedModels = [];
|
let rankedModels = [];
|
||||||
|
let feedbacks = [];
|
||||||
|
|
||||||
let loaded = false;
|
let loaded = false;
|
||||||
|
onMount(async () => {
|
||||||
onMount(() => {
|
feedbacks = await getAllFeedbacks(localStorage.token);
|
||||||
loaded = true;
|
|
||||||
|
|
||||||
rankedModels = $models
|
rankedModels = $models
|
||||||
.filter((m) => m?.owned_by !== 'arena' && (m?.info?.meta?.hidden ?? false) !== true)
|
.filter((m) => m?.owned_by !== 'arena' && (m?.info?.meta?.hidden ?? false) !== true)
|
||||||
.map((model) => {
|
.map((model) => {
|
||||||
return {
|
return {
|
||||||
...model,
|
...model,
|
||||||
|
ranking: '-',
|
||||||
rating: '-',
|
rating: '-',
|
||||||
stats: {
|
stats: {
|
||||||
won: '-',
|
won: '-',
|
||||||
@ -34,11 +39,13 @@
|
|||||||
// If both ratings are '-', sort alphabetically (by 'name')
|
// If both ratings are '-', sort alphabetically (by 'name')
|
||||||
return a.name.localeCompare(b.name);
|
return a.name.localeCompare(b.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
loaded = true;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if loaded}
|
{#if loaded}
|
||||||
<div class="mt-0.5 mb-3 gap-1 flex flex-col md:flex-row justify-between">
|
<div class="mt-0.5 mb-2 gap-1 flex flex-col md:flex-row justify-between">
|
||||||
<div class="flex md:self-center text-lg font-medium px-0.5">
|
<div class="flex md:self-center text-lg font-medium px-0.5">
|
||||||
{$i18n.t('Leaderboard')}
|
{$i18n.t('Leaderboard')}
|
||||||
|
|
||||||
@ -52,75 +59,164 @@
|
|||||||
<div
|
<div
|
||||||
class="scrollbar-hidden relative whitespace-nowrap overflow-x-auto max-w-full rounded pt-0.5"
|
class="scrollbar-hidden relative whitespace-nowrap overflow-x-auto max-w-full rounded pt-0.5"
|
||||||
>
|
>
|
||||||
<table
|
{#if (rankedModels ?? []).length === 0}
|
||||||
class="w-full text-sm text-left text-gray-500 dark:text-gray-400 table-auto max-w-full rounded"
|
<div class="text-center text-xs text-gray-500 dark:text-gray-400 py-1">
|
||||||
>
|
{$i18n.t('No models found')}
|
||||||
<thead
|
</div>
|
||||||
class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-850 dark:text-gray-400 -translate-y-0.5"
|
{:else}
|
||||||
|
<table
|
||||||
|
class="w-full text-sm text-left text-gray-500 dark:text-gray-400 table-auto max-w-full rounded"
|
||||||
>
|
>
|
||||||
<tr class="">
|
<thead
|
||||||
<th scope="col" class="px-3 py-1.5 cursor-pointer select-none">
|
class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-850 dark:text-gray-400 -translate-y-0.5"
|
||||||
{$i18n.t('Model')}
|
>
|
||||||
</th>
|
<tr class="">
|
||||||
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none">
|
<th scope="col" class="px-3 py-1.5 cursor-pointer select-none w-3">
|
||||||
{$i18n.t('Rating')}
|
{$i18n.t('RK')}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-fit">
|
<th scope="col" class="px-3 py-1.5 cursor-pointer select-none">
|
||||||
{$i18n.t('Won')}
|
{$i18n.t('Model')}
|
||||||
</th>
|
</th>
|
||||||
|
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-fit">
|
||||||
|
{$i18n.t('Rating')}
|
||||||
|
</th>
|
||||||
|
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-fit">
|
||||||
|
{$i18n.t('Won')}
|
||||||
|
</th>
|
||||||
|
|
||||||
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-fit">
|
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-fit">
|
||||||
{$i18n.t('Draw')}
|
{$i18n.t('Draw')}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-fit">
|
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-fit">
|
||||||
{$i18n.t('Lost')}
|
{$i18n.t('Lost')}
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody class="">
|
|
||||||
{#each rankedModels as model (model.id)}
|
|
||||||
<tr class="bg-white dark:bg-gray-900 dark:border-gray-850 text-xs">
|
|
||||||
<td class="px-3 py-1 flex flex-col justify-center">
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<div class="flex-shrink-0">
|
|
||||||
<img
|
|
||||||
src={model?.info?.meta?.profile_image_url ?? '/favicon.png'}
|
|
||||||
alt={model.name}
|
|
||||||
class="size-6 rounded-full object-cover shrink-0"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="font-medium text-gray-600 dark:text-gray-400 pr-4">
|
|
||||||
{model.name}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="px-3 py-1 text-right font-medium text-gray-900 dark:text-white w-max">
|
|
||||||
{model.rating}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td class=" px-3 py-1 text-right font-semibold text-green-500"> {model.stats.won} </td>
|
|
||||||
|
|
||||||
<td class=" px-3 py-1 text-right font-semibold">
|
|
||||||
{model.stats.draw}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td class="px-3 py-1 text-right font-semibold text-red-500">
|
|
||||||
{model.stats.lost}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
</thead>
|
||||||
</tbody>
|
<tbody class="">
|
||||||
</table>
|
{#each rankedModels as model (model.id)}
|
||||||
|
<tr class="bg-white dark:bg-gray-900 dark:border-gray-850 text-xs">
|
||||||
|
<td class="px-3 py-1.5 text-left font-medium text-gray-900 dark:text-white w-fit">
|
||||||
|
<div class=" line-clamp-1">
|
||||||
|
{model.ranking}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="px-3 py-1.5 flex flex-col justify-center">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div class="flex-shrink-0">
|
||||||
|
<img
|
||||||
|
src={model?.info?.meta?.profile_image_url ?? '/favicon.png'}
|
||||||
|
alt={model.name}
|
||||||
|
class="size-5 rounded-full object-cover shrink-0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="font-medium text-gray-800 dark:text-gray-200 pr-4">
|
||||||
|
{model.name}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="px-3 py-1.5 text-right font-medium text-gray-900 dark:text-white w-max">
|
||||||
|
{model.rating}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class=" px-3 py-1.5 text-right font-semibold text-green-500">
|
||||||
|
{model.stats.won}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class=" px-3 py-1.5 text-right font-semibold">
|
||||||
|
{model.stats.draw}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class="px-3 py-1.5 text-right font-semibold text-red-500">
|
||||||
|
{model.stats.lost}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pb-4"></div>
|
<div class="pb-4"></div>
|
||||||
|
|
||||||
<div class="mt-0.5 mb-3 gap-1 flex flex-col md:flex-row justify-between">
|
<div class="mt-0.5 mb-2 gap-1 flex flex-col md:flex-row justify-between">
|
||||||
<div class="flex md:self-center text-lg font-medium px-0.5">
|
<div class="flex md:self-center text-lg font-medium px-0.5">
|
||||||
{$i18n.t('Rating History')}
|
{$i18n.t('Feedback History')}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="scrollbar-hidden relative whitespace-nowrap overflow-x-auto max-w-full rounded pt-0.5"
|
||||||
|
>
|
||||||
|
{#if (feedbacks ?? []).length === 0}
|
||||||
|
<div class="text-center text-xs text-gray-500 dark:text-gray-400 py-1">
|
||||||
|
{$i18n.t('No feedbacks found')}
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<table
|
||||||
|
class="w-full text-sm text-left text-gray-500 dark:text-gray-400 table-auto max-w-full rounded"
|
||||||
|
>
|
||||||
|
<thead
|
||||||
|
class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-850 dark:text-gray-400 -translate-y-0.5"
|
||||||
|
>
|
||||||
|
<tr class="">
|
||||||
|
<th scope="col" class="px-3 py-1.5 cursor-pointer select-none">
|
||||||
|
{$i18n.t('Models')}
|
||||||
|
</th>
|
||||||
|
|
||||||
|
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-fit">
|
||||||
|
{$i18n.t('Result')}
|
||||||
|
</th>
|
||||||
|
|
||||||
|
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-0">
|
||||||
|
{$i18n.t('User')}
|
||||||
|
</th>
|
||||||
|
|
||||||
|
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-0">
|
||||||
|
{$i18n.t('Created At')}
|
||||||
|
</th>
|
||||||
|
|
||||||
|
<th scope="col" class="px-3 py-1.5 text-right cursor-pointer select-none w-0"> </th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="">
|
||||||
|
{#each feedbacks as feedback (feedback.id)}
|
||||||
|
<tr class="bg-white dark:bg-gray-900 dark:border-gray-850 text-xs">
|
||||||
|
<td class="px-3 py-1 flex flex-col">
|
||||||
|
<div class="flex flex-col items-start gap-1">
|
||||||
|
<div class="font-medium text-gray-600 dark:text-gray-400">
|
||||||
|
{model.name}
|
||||||
|
</div>
|
||||||
|
<div class="font-medium text-gray-600 dark:text-gray-400">
|
||||||
|
{model.name}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="px-3 py-1 text-right font-medium text-gray-900 dark:text-white w-max">
|
||||||
|
{model.rating}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class=" px-3 py-1 text-right font-semibold"> {model.stats.won} </td>
|
||||||
|
|
||||||
|
<td class=" px-3 py-1 text-right font-semibold">
|
||||||
|
{model.stats.draw}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class=" px-3 py-1 text-right font-semibold">
|
||||||
|
<FeedbackMenu>
|
||||||
|
<button
|
||||||
|
class="self-center w-fit text-sm p-1.5 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
|
||||||
|
>
|
||||||
|
<EllipsisHorizontal />
|
||||||
|
</button>
|
||||||
|
</FeedbackMenu>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="pb-8"></div>
|
<div class="pb-8"></div>
|
||||||
{/if}
|
{/if}
|
||||||
|
46
src/lib/components/admin/Evaluations/FeedbackMenu.svelte
Normal file
46
src/lib/components/admin/Evaluations/FeedbackMenu.svelte
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { DropdownMenu } from 'bits-ui';
|
||||||
|
import { flyAndScale } from '$lib/utils/transitions';
|
||||||
|
import { getContext, createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
import fileSaver from 'file-saver';
|
||||||
|
const { saveAs } = fileSaver;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
import Dropdown from '$lib/components/common/Dropdown.svelte';
|
||||||
|
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
|
||||||
|
import Pencil from '$lib/components/icons/Pencil.svelte';
|
||||||
|
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||||
|
import Download from '$lib/components/icons/Download.svelte';
|
||||||
|
|
||||||
|
let show = false;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dropdown bind:show on:change={(e) => {}}>
|
||||||
|
<Tooltip content={$i18n.t('More')}>
|
||||||
|
<slot />
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<div slot="content">
|
||||||
|
<DropdownMenu.Content
|
||||||
|
class="w-full max-w-[150px] rounded-xl px-1 py-1.5 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-lg"
|
||||||
|
sideOffset={-2}
|
||||||
|
side="bottom"
|
||||||
|
align="start"
|
||||||
|
transition={flyAndScale}
|
||||||
|
>
|
||||||
|
<DropdownMenu.Item
|
||||||
|
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
|
||||||
|
on:click={() => {
|
||||||
|
dispatch('delete');
|
||||||
|
show = false;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<GarbageBin strokeWidth="2" />
|
||||||
|
<div class="flex items-center">{$i18n.t('Delete')}</div>
|
||||||
|
</DropdownMenu.Item>
|
||||||
|
</DropdownMenu.Content>
|
||||||
|
</div>
|
||||||
|
</Dropdown>
|
@ -66,6 +66,7 @@
|
|||||||
/>
|
/>
|
||||||
{:else if (history.messages[history.messages[messageId].parentId]?.models?.length ?? 1) === 1}
|
{:else if (history.messages[history.messages[messageId].parentId]?.models?.length ?? 1) === 1}
|
||||||
<ResponseMessage
|
<ResponseMessage
|
||||||
|
{chatId}
|
||||||
{history}
|
{history}
|
||||||
{messageId}
|
{messageId}
|
||||||
isLastMessage={messageId === history.currentId}
|
isLastMessage={messageId === history.currentId}
|
||||||
|
@ -200,6 +200,7 @@
|
|||||||
{#key history.currentId}
|
{#key history.currentId}
|
||||||
{#if message}
|
{#if message}
|
||||||
<ResponseMessage
|
<ResponseMessage
|
||||||
|
{chatId}
|
||||||
{history}
|
{history}
|
||||||
messageId={_messageId}
|
messageId={_messageId}
|
||||||
isLastMessage={true}
|
isLastMessage={true}
|
||||||
|
@ -40,6 +40,8 @@
|
|||||||
import type { Writable } from 'svelte/store';
|
import type { Writable } from 'svelte/store';
|
||||||
import type { i18n as i18nType } from 'i18next';
|
import type { i18n as i18nType } from 'i18next';
|
||||||
import ContentRenderer from './ContentRenderer.svelte';
|
import ContentRenderer from './ContentRenderer.svelte';
|
||||||
|
import { createNewFeedback, getFeedbackById, updateFeedbackById } from '$lib/apis/evaluations';
|
||||||
|
import { getChatById } from '$lib/apis/chats';
|
||||||
|
|
||||||
interface MessageType {
|
interface MessageType {
|
||||||
id: string;
|
id: string;
|
||||||
@ -92,6 +94,7 @@
|
|||||||
annotation?: { type: string; rating: number };
|
annotation?: { type: string; rating: number };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let chatId = '';
|
||||||
export let history;
|
export let history;
|
||||||
export let messageId;
|
export let messageId;
|
||||||
|
|
||||||
@ -330,6 +333,80 @@
|
|||||||
generatingImage = false;
|
generatingImage = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const feedbackHandler = async (
|
||||||
|
rating: number | null = null,
|
||||||
|
annotation: object | null = null
|
||||||
|
) => {
|
||||||
|
console.log('Feedback', rating, annotation);
|
||||||
|
|
||||||
|
const updatedMessage = {
|
||||||
|
...message,
|
||||||
|
annotation: {
|
||||||
|
...(message?.annotation ?? {}),
|
||||||
|
...(rating !== null ? { rating: rating } : {}),
|
||||||
|
...(annotation ? annotation : {})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const chat = await getChatById(localStorage.token, chatId).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
});
|
||||||
|
if (!chat) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let feedbackItem = {
|
||||||
|
type: 'rating',
|
||||||
|
data: {
|
||||||
|
...(updatedMessage?.annotation ? updatedMessage.annotation : {}),
|
||||||
|
model_id: message?.selectedModelId ?? message.model,
|
||||||
|
...(history.messages[message.parentId].childrenIds.length > 1
|
||||||
|
? {
|
||||||
|
sibling_model_ids: history.messages[message.parentId].childrenIds
|
||||||
|
.filter((id) => id !== message.id)
|
||||||
|
.map((id) => history.messages[id]?.selectedModelId ?? history.messages[id].model)
|
||||||
|
}
|
||||||
|
: {})
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
arena: message ? message.arena : false,
|
||||||
|
message_id: message.id,
|
||||||
|
chat_id: chatId
|
||||||
|
},
|
||||||
|
snapshot: {
|
||||||
|
chat: chat
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let feedback = null;
|
||||||
|
if (message?.feedbackId) {
|
||||||
|
feedback = await updateFeedbackById(
|
||||||
|
localStorage.token,
|
||||||
|
message.feedbackId,
|
||||||
|
feedbackItem
|
||||||
|
).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
feedback = await createNewFeedback(localStorage.token, feedbackItem).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (feedback) {
|
||||||
|
updatedMessage.feedbackId = feedback.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(updatedMessage);
|
||||||
|
dispatch('save', updatedMessage);
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
if (!annotation) {
|
||||||
|
showRateComment = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$: if (!edit) {
|
$: if (!edit) {
|
||||||
(async () => {
|
(async () => {
|
||||||
await tick();
|
await tick();
|
||||||
@ -880,12 +957,13 @@
|
|||||||
<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 {(
|
||||||
?.annotation?.rating ?? null) === 1
|
message?.annotation?.rating ?? ''
|
||||||
|
).toString() === '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 feedbackHandler(1);
|
||||||
|
|
||||||
(model?.actions ?? [])
|
(model?.actions ?? [])
|
||||||
.filter((action) => action?.__webui__ ?? false)
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
@ -901,7 +979,6 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
showRateComment = true;
|
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
document
|
document
|
||||||
.getElementById(`message-feedback-${message.id}`)
|
.getElementById(`message-feedback-${message.id}`)
|
||||||
@ -930,12 +1007,13 @@
|
|||||||
<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 {(
|
||||||
?.annotation?.rating ?? null) === -1
|
message?.annotation?.rating ?? ''
|
||||||
|
).toString() === '-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 feedbackHandler(-1);
|
||||||
|
|
||||||
(model?.actions ?? [])
|
(model?.actions ?? [])
|
||||||
.filter((action) => action?.__webui__ ?? false)
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
@ -951,7 +1029,6 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
showRateComment = true;
|
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
document
|
document
|
||||||
.getElementById(`message-feedback-${message.id}`)
|
.getElementById(`message-feedback-${message.id}`)
|
||||||
@ -1103,15 +1180,12 @@
|
|||||||
<RateComment
|
<RateComment
|
||||||
bind:message
|
bind:message
|
||||||
bind:show={showRateComment}
|
bind:show={showRateComment}
|
||||||
on:save={(e) => {
|
on:save={async (e) => {
|
||||||
dispatch('save', {
|
await feedbackHandler(null, {
|
||||||
...message,
|
comment: e.detail.comment,
|
||||||
annotation: {
|
reason: e.detail.reason
|
||||||
...message.annotation,
|
|
||||||
comment: e.detail.comment,
|
|
||||||
reason: e.detail.reason
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
(model?.actions ?? [])
|
(model?.actions ?? [])
|
||||||
.filter((action) => action?.__webui__ ?? false)
|
.filter((action) => action?.__webui__ ?? false)
|
||||||
.forEach((action) => {
|
.forEach((action) => {
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
||||||
import Badge from '$lib/components/common/Badge.svelte';
|
import Badge from '$lib/components/common/Badge.svelte';
|
||||||
import Plus from '$lib/components/icons/Plus.svelte';
|
import Plus from '$lib/components/icons/Plus.svelte';
|
||||||
|
import ChevronUp from '$lib/components/icons/ChevronUp.svelte';
|
||||||
|
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
|
||||||
|
import About from '$lib/components/chat/Settings/About.svelte';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
@ -138,7 +141,7 @@
|
|||||||
<UserChatsModal bind:show={showUserChatsModal} user={selectedUser} />
|
<UserChatsModal bind:show={showUserChatsModal} user={selectedUser} />
|
||||||
|
|
||||||
{#if loaded}
|
{#if loaded}
|
||||||
<div class="mt-0.5 mb-3 gap-1 flex flex-col md:flex-row justify-between">
|
<div class="mt-0.5 mb-2 gap-1 flex flex-col md:flex-row justify-between">
|
||||||
<div class="flex md:self-center text-lg font-medium px-0.5">
|
<div class="flex md:self-center text-lg font-medium px-0.5">
|
||||||
{$i18n.t('Users')}
|
{$i18n.t('Users')}
|
||||||
<div class="flex self-center w-[1px] h-6 mx-2.5 bg-gray-50 dark:bg-gray-850" />
|
<div class="flex self-center w-[1px] h-6 mx-2.5 bg-gray-50 dark:bg-gray-850" />
|
||||||
@ -201,36 +204,69 @@
|
|||||||
class="px-3 py-1.5 cursor-pointer select-none"
|
class="px-3 py-1.5 cursor-pointer select-none"
|
||||||
on:click={() => setSortKey('role')}
|
on:click={() => setSortKey('role')}
|
||||||
>
|
>
|
||||||
{$i18n.t('Role')}
|
<div class="flex gap-1.5 items-center">
|
||||||
{#if sortKey === 'role'}
|
{$i18n.t('Role')}
|
||||||
<span class="font-normal ml-1">{sortOrder === 'asc' ? '▲' : '▼'}</span>
|
|
||||||
{:else}
|
{#if sortKey === 'role'}
|
||||||
<span class="invisible">▲</span>
|
<span class="font-normal"
|
||||||
{/if}
|
>{#if sortOrder === 'asc'}
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
{:else}
|
||||||
|
<ChevronDown className="size-2" />
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="invisible">
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
class="px-3 py-1.5 cursor-pointer select-none"
|
class="px-3 py-1.5 cursor-pointer select-none"
|
||||||
on:click={() => setSortKey('name')}
|
on:click={() => setSortKey('name')}
|
||||||
>
|
>
|
||||||
{$i18n.t('Name')}
|
<div class="flex gap-1.5 items-center">
|
||||||
{#if sortKey === 'name'}
|
{$i18n.t('Name')}
|
||||||
<span class="font-normal ml-1">{sortOrder === 'asc' ? '▲' : '▼'}</span>
|
|
||||||
{:else}
|
{#if sortKey === 'name'}
|
||||||
<span class="invisible">▲</span>
|
<span class="font-normal"
|
||||||
{/if}
|
>{#if sortOrder === 'asc'}
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
{:else}
|
||||||
|
<ChevronDown className="size-2" />
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="invisible">
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
class="px-3 py-1.5 cursor-pointer select-none"
|
class="px-3 py-1.5 cursor-pointer select-none"
|
||||||
on:click={() => setSortKey('email')}
|
on:click={() => setSortKey('email')}
|
||||||
>
|
>
|
||||||
{$i18n.t('Email')}
|
<div class="flex gap-1.5 items-center">
|
||||||
{#if sortKey === 'email'}
|
{$i18n.t('Email')}
|
||||||
<span class="font-normal ml-1">{sortOrder === 'asc' ? '▲' : '▼'}</span>
|
|
||||||
{:else}
|
{#if sortKey === 'email'}
|
||||||
<span class="invisible">▲</span>
|
<span class="font-normal"
|
||||||
{/if}
|
>{#if sortOrder === 'asc'}
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
{:else}
|
||||||
|
<ChevronDown className="size-2" />
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="invisible">
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
|
|
||||||
<th
|
<th
|
||||||
@ -238,24 +274,45 @@
|
|||||||
class="px-3 py-1.5 cursor-pointer select-none"
|
class="px-3 py-1.5 cursor-pointer select-none"
|
||||||
on:click={() => setSortKey('last_active_at')}
|
on:click={() => setSortKey('last_active_at')}
|
||||||
>
|
>
|
||||||
{$i18n.t('Last Active')}
|
<div class="flex gap-1.5 items-center">
|
||||||
{#if sortKey === 'last_active_at'}
|
{$i18n.t('Last Active')}
|
||||||
<span class="font-normal ml-1">{sortOrder === 'asc' ? '▲' : '▼'}</span>
|
|
||||||
{:else}
|
{#if sortKey === 'last_active_at'}
|
||||||
<span class="invisible">▲</span>
|
<span class="font-normal"
|
||||||
{/if}
|
>{#if sortOrder === 'asc'}
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
{:else}
|
||||||
|
<ChevronDown className="size-2" />
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="invisible">
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
class="px-3 py-1.5 cursor-pointer select-none"
|
class="px-3 py-1.5 cursor-pointer select-none"
|
||||||
on:click={() => setSortKey('created_at')}
|
on:click={() => setSortKey('created_at')}
|
||||||
>
|
>
|
||||||
{$i18n.t('Created at')}
|
<div class="flex gap-1.5 items-center">
|
||||||
{#if sortKey === 'created_at'}
|
{$i18n.t('Created at')}
|
||||||
<span class="font-normal ml-1">{sortOrder === 'asc' ? '▲' : '▼'}</span>
|
{#if sortKey === 'created_at'}
|
||||||
{:else}
|
<span class="font-normal"
|
||||||
<span class="invisible">▲</span>
|
>{#if sortOrder === 'asc'}
|
||||||
{/if}
|
<ChevronUp className="size-2" />
|
||||||
|
{:else}
|
||||||
|
<ChevronDown className="size-2" />
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="invisible">
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
|
|
||||||
<th
|
<th
|
||||||
@ -263,12 +320,23 @@
|
|||||||
class="px-3 py-1.5 cursor-pointer select-none"
|
class="px-3 py-1.5 cursor-pointer select-none"
|
||||||
on:click={() => setSortKey('oauth_sub')}
|
on:click={() => setSortKey('oauth_sub')}
|
||||||
>
|
>
|
||||||
{$i18n.t('OAuth ID')}
|
<div class="flex gap-1.5 items-center">
|
||||||
{#if sortKey === 'oauth_sub'}
|
{$i18n.t('OAuth ID')}
|
||||||
<span class="font-normal ml-1">{sortOrder === 'asc' ? '▲' : '▼'}</span>
|
|
||||||
{:else}
|
{#if sortKey === 'oauth_sub'}
|
||||||
<span class="invisible">▲</span>
|
<span class="font-normal"
|
||||||
{/if}
|
>{#if sortOrder === 'asc'}
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
{:else}
|
||||||
|
<ChevronDown className="size-2" />
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span class="invisible">
|
||||||
|
<ChevronUp className="size-2" />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</th>
|
</th>
|
||||||
|
|
||||||
<th scope="col" class="px-3 py-2 text-right" />
|
<th scope="col" class="px-3 py-2 text-right" />
|
||||||
|
Loading…
Reference in New Issue
Block a user