mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 04:50:14 +09:00
feat: auto switch model when using use message
actions in shared conversation (#116)
This commit is contained in:
parent
8dde7c4f5f
commit
f67adede69
@ -18,6 +18,7 @@ export type ViewData = {
|
||||
name: string;
|
||||
username: string;
|
||||
time: string;
|
||||
model?: string;
|
||||
messages: Message[];
|
||||
};
|
||||
|
||||
|
@ -131,20 +131,20 @@ function ShareManagementDialog() {
|
||||
<Dialog open={open} onOpenChange={(open) => dispatch(setDialog(open))}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle className={`mb-4`}>{t("share.manage")}</DialogTitle>
|
||||
{data.length > 0 ? (
|
||||
<ScrollArea className={`max-h-[60vh]`}>
|
||||
<DialogDescription className={`share-table`}>
|
||||
<ShareTable data={data} />
|
||||
</DialogDescription>
|
||||
</ScrollArea>
|
||||
) : (
|
||||
<DialogDescription>
|
||||
<p className={`text-center select-none mt-6 mb-2`}>
|
||||
{t("conversation.empty")}
|
||||
</p>
|
||||
<DialogTitle className={`mb-4`}>{t("share.manage")}</DialogTitle>
|
||||
{data.length > 0 ? (
|
||||
<ScrollArea className={`max-h-[60vh]`}>
|
||||
<DialogDescription className={`share-table`}>
|
||||
<ShareTable data={data} />
|
||||
</DialogDescription>
|
||||
)}
|
||||
</ScrollArea>
|
||||
) : (
|
||||
<DialogDescription>
|
||||
<p className={`text-center select-none mt-6 mb-2`}>
|
||||
{t("conversation.empty")}
|
||||
</p>
|
||||
</DialogDescription>
|
||||
)}
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant={`outline`} onClick={() => dispatch(closeDialog())}>
|
||||
|
@ -40,7 +40,7 @@ function SharingForm({ data }: SharingFormProps) {
|
||||
const { t } = useTranslation();
|
||||
const { toast } = useToast();
|
||||
const mobile = useMobile();
|
||||
const { mask: setMask } = useConversationActions();
|
||||
const { mask: setMask, selected: setModel } = useConversationActions();
|
||||
const [maximized, setMaximized] = useState(false);
|
||||
const container = useRef<HTMLDivElement>(null);
|
||||
const date = new Date(data.time);
|
||||
@ -163,6 +163,11 @@ function SharingForm({ data }: SharingFormProps) {
|
||||
name: data.name,
|
||||
context: message,
|
||||
});
|
||||
setModel(data?.model);
|
||||
|
||||
console.debug(
|
||||
`[sharing] switch to conversation (name: ${data.name}, model: ${data.model})`,
|
||||
);
|
||||
await router.navigate("/");
|
||||
}}
|
||||
>
|
||||
|
@ -424,6 +424,8 @@ export function useConversationActions() {
|
||||
const current = useSelector(selectCurrent);
|
||||
const mask = useSelector(selectMaskItem);
|
||||
|
||||
const supportModels = useSelector(selectSupportModels);
|
||||
|
||||
return {
|
||||
toggle: async (id: number) => {
|
||||
const conversation = conversations[id];
|
||||
@ -478,6 +480,12 @@ export function useConversationActions() {
|
||||
dispatch(setCurrent(-1));
|
||||
}
|
||||
},
|
||||
selected: (model?: string) => {
|
||||
if (!model || model === "") return;
|
||||
if (!supportModels.map((item) => item.id).includes(model)) return;
|
||||
|
||||
dispatch(setModel(model));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ type SharedForm struct {
|
||||
Username string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
Messages []globals.Message `json:"messages"`
|
||||
Model string `json:"model"`
|
||||
Time time.Time `json:"time"`
|
||||
}
|
||||
|
||||
@ -138,12 +139,12 @@ func GetSharedConversation(db *sql.DB, hash string) (*SharedForm, error) {
|
||||
)
|
||||
if err := globals.QueryRowDb(db, `
|
||||
SELECT auth.username, sharing.refs, sharing.updated_at, conversation.conversation_name,
|
||||
sharing.user_id, sharing.conversation_id
|
||||
sharing.user_id, sharing.conversation_id, conversation.model
|
||||
FROM sharing
|
||||
INNER JOIN auth ON auth.id = sharing.user_id
|
||||
INNER JOIN conversation ON conversation.conversation_id = sharing.conversation_id AND conversation.user_id = sharing.user_id
|
||||
WHERE sharing.hash = ?
|
||||
`, hash).Scan(&shared.Username, &ref, &updated, &shared.Name, &uid, &cid); err != nil {
|
||||
`, hash).Scan(&shared.Username, &ref, &updated, &shared.Name, &uid, &cid, &shared.Model); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user