Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add popover introduction info for models #63

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
ListItem,
Modal,
Popover,
PopoverSelector,
Selector,
Tooltip,
showConfirm,
Expand All @@ -96,6 +97,7 @@ import { MultimodalContent } from "../client/api";
import { Template, useTemplateStore } from "../store/template";
import Image from "next/image";
import { MLCLLMContext, WebLLMContext } from "../context";
import { SelectorWithPopover } from "./SubComponent/Chat/SelectorWithPopover";

export function ScrollDownToast(prop: { show: boolean; onclick: () => void }) {
return (
Expand Down Expand Up @@ -547,12 +549,17 @@ export function ChatActions(props: {
fullWidth
/>
{showModelSelector && (
<Selector
<PopoverSelector
defaultSelectedValue={currentModel}
items={models.map((m) => ({
title: m.name,
value: m.name,
family: m.family,
items={models?.map((m) => ({
title: m?.name,
value: m?.name,
family: m?.family,
provider: m?.provider,
size: m?.size,
quantization: m?.quantization,
vram_required_MB: m?.vram_required_MB,
low_resource_required: m?.low_resource_required,
}))}
onClose={() => setShowModelSelector(false)}
onSelection={(s) => {
Expand Down
221 changes: 221 additions & 0 deletions app/components/ui-lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import Locale from "../locales";
import { createRoot } from "react-dom/client";
import React, { HTMLProps, useEffect, useState } from "react";
import { IconButton } from "./button";
import MuiPopover from "@mui/material/Popover";
import { Box, Typography } from "@mui/material";
import { ModelRecord } from "../client/api";

export function Popover(props: {
children: JSX.Element;
Expand Down Expand Up @@ -538,3 +541,221 @@ export function Selector<T>(props: {
</div>
);
}

export function PopoverSelector<T>(props: {
items: Array<{
title: string;
subTitle?: string;
value: T;
family?: string;
}>;
defaultSelectedValue?: T;
onSelection?: (selection: T[]) => void;
onClose?: () => void;
multiple?: boolean;
}) {
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const [popoverContent, setPopoverContent] = useState<string | null>(null);
const [open, setOpen] = useState(false);

const handlePopoverOpen = (
event: React.MouseEvent<HTMLElement>,
content: ModelRecord,
) => {
setAnchorEl(event.currentTarget);
setPopoverContent(content);
setOpen(true);
};

const handlePopoverClose = () => {
setAnchorEl(null);
setPopoverContent(null);
setOpen(false);
};

return (
<>
<div className={styles["selector"]} onClick={() => props.onClose?.()}>
<div className={styles["selector-content"]}>
<List>
{props.items.map((item, i) => {
const selected = props.defaultSelectedValue === item.value;
const lastOfFamily =
i < props.items.length - 1 &&
item.family !== props.items[i + 1].family;

return (
<div
key={i}
onMouseEnter={(event) => handlePopoverOpen(event, item)}
onMouseLeave={handlePopoverClose}
aria-owns={open ? "mouse-over-popover" : undefined}
aria-haspopup="true"
>
<ListItem
className={
styles["selector-item"] +
(lastOfFamily ? " " + styles["list-item-separator"] : "")
}
title={item.title}
subTitle={item.subTitle}
onClick={() => {
props.onSelection?.([item.value]);
props.onClose?.();
}}
>
{selected ? (
<div
style={{
height: 10,
width: 10,
backgroundColor: "var(--primary)",
borderRadius: 10,
}}
></div>
) : null}
</ListItem>
</div>
);
})}
</List>
</div>
</div>

<MuiPopover
id="mouse-over-popover"
sx={{ pointerEvents: "none", marginLeft: "10px" }}
open={open}
anchorEl={anchorEl}
anchorOrigin={{
vertical: "center",
horizontal: "right",
}}
transformOrigin={{
vertical: "center",
horizontal: "left",
}}
onClose={handlePopoverClose}
disableRestoreFocus
>
{popoverContent && (
<Box sx={{ padding: "8px", maxWidth: "250px" }}>
<Typography
sx={{ fontWeight: "bold", marginBottom: "6px", fontSize: "1rem" }}
>
{popoverContent.title}
</Typography>

<Box
sx={{
display: "flex",
justifyContent: "space-between",
marginBottom: "6px",
}}
>
<Typography
variant="subtitle2"
color="text.secondary"
sx={{ fontSize: "0.875rem" }}
>
Provider:
</Typography>
<Typography variant="body2" sx={{ fontSize: "0.875rem" }}>
{popoverContent.provider}
</Typography>
</Box>

<Box
sx={{
display: "flex",
justifyContent: "space-between",
marginBottom: "6px",
}}
>
<Typography
variant="subtitle2"
color="text.secondary"
sx={{ fontSize: "0.875rem" }}
>
Size:
</Typography>
<Typography variant="body2" sx={{ fontSize: "0.875rem" }}>
{popoverContent.size}
</Typography>
</Box>

<Box
sx={{
display: "flex",
justifyContent: "space-between",
marginBottom: "6px",
}}
>
<Typography
variant="subtitle2"
color="text.secondary"
sx={{ fontSize: "0.875rem" }}
>
Quantization:
</Typography>
<Typography variant="body2" sx={{ fontSize: "0.875rem" }}>
{popoverContent.quantization}
</Typography>
</Box>

<Box
sx={{
display: "flex",
justifyContent: "space-between",
marginBottom: "6px",
}}
>
<Typography
variant="subtitle2"
color="text.secondary"
sx={{ fontSize: "0.875rem" }}
>
Family:
</Typography>
<Typography variant="body2" sx={{ fontSize: "0.875rem" }}>
{popoverContent.family}
</Typography>
</Box>

<Box
sx={{
display: "flex",
justifyContent: "space-between",
marginBottom: "6px",
}}
>
<Typography
variant="subtitle2"
color="text.secondary"
sx={{ fontSize: "0.875rem" }}
>
VRAM Required:
</Typography>
<Typography variant="body2" sx={{ fontSize: "0.875rem" }}>
{popoverContent.vram_required_MB} MB
</Typography>
</Box>

<Box sx={{ display: "flex", justifyContent: "space-between" }}>
<Typography
variant="subtitle2"
color="text.secondary"
sx={{ fontSize: "0.875rem" }}
>
Low Resource Required:
</Typography>
<Typography variant="body2" sx={{ fontSize: "0.875rem" }}>
{popoverContent.low_resource_required ? "Yes" : "No"}
</Typography>
</Box>
</Box>
)}
</MuiPopover>
</>
);
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev"
},
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@fortaine/fetch-event-source": "^3.0.6",
"@hello-pangea/dnd": "^16.5.0",
"@mlc-ai/web-llm": "^0.2.62",
"@mui/material": "^6.0.2",
"@serwist/next": "^9.0.2",
"@svgr/webpack": "^6.5.1",
"emoji-picker-react": "^4.9.2",
Expand Down
Loading