Update convo state when user change model
This commit is contained in:
parent
59ea9b3639
commit
ac1c7018d8
@ -12,7 +12,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&-outline {
|
&-outline {
|
||||||
@apply border-input hover:bg-accent hover:text-accent-foreground border bg-transparent;
|
@apply border-input hover:bg-primary hover:text-primary-foreground border bg-transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-secondary {
|
&-secondary {
|
||||||
@ -20,7 +20,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&-ghost {
|
&-ghost {
|
||||||
@apply hover:bg-accent hover:text-accent-foreground;
|
@apply hover:bg-primary hover:text-primary-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-sm {
|
&-sm {
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&-list-item {
|
&-list-item {
|
||||||
@apply text-foreground aria-selected:bg-accent relative flex cursor-pointer select-none items-center rounded-md px-2 py-2 text-sm outline-none;
|
@apply text-foreground aria-selected:bg-primary relative flex cursor-pointer select-none items-center rounded-md px-2 py-2 text-sm outline-none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-empty {
|
&-empty {
|
||||||
|
|||||||
@ -27,7 +27,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--background: 0 0% 100%;
|
--background: 0 0% 100%;
|
||||||
--foreground: 20 14.3% 4.1%;
|
--foreground: 20 14.3% 4.1%;
|
||||||
@ -35,9 +34,6 @@
|
|||||||
--muted: 60 4.8% 95.9%;
|
--muted: 60 4.8% 95.9%;
|
||||||
--muted-foreground: 240 3.8% 46.1%;
|
--muted-foreground: 240 3.8% 46.1%;
|
||||||
|
|
||||||
--accent: 60 4.8% 95.9%;
|
|
||||||
--accent-foreground: 24 9.8% 10%;
|
|
||||||
|
|
||||||
--danger: 346.8 77.2% 49.8%;
|
--danger: 346.8 77.2% 49.8%;
|
||||||
--danger-foreground: 355.7 100% 97.3%;
|
--danger-foreground: 355.7 100% 97.3%;
|
||||||
|
|
||||||
@ -77,9 +73,6 @@
|
|||||||
--muted: 12 6.5% 15.1%;
|
--muted: 12 6.5% 15.1%;
|
||||||
--muted-foreground: 24 5.4% 63.9%;
|
--muted-foreground: 24 5.4% 63.9%;
|
||||||
|
|
||||||
--accent: 12 6.5% 15.1%;
|
|
||||||
--accent-foreground: 60 9.1% 97.8%;
|
|
||||||
|
|
||||||
--danger: 346.8 77.2% 49.8%;
|
--danger: 346.8 77.2% 49.8%;
|
||||||
--danger-foreground: 355.7 100% 97.3%;
|
--danger-foreground: 355.7 100% 97.3%;
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,7 @@ export default function CommandListDownloadedModel() {
|
|||||||
<div className="flex w-full items-center justify-between">
|
<div className="flex w-full items-center justify-between">
|
||||||
<span>{model.name}</span>
|
<span>{model.name}</span>
|
||||||
{activeModel && activeModel._id === model._id && (
|
{activeModel && activeModel._id === model._id && (
|
||||||
<Badge>Active</Badge>
|
<Badge themes="secondary">Active</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CommandItem>
|
</CommandItem>
|
||||||
|
|||||||
@ -40,6 +40,7 @@ export function useGetConfiguredModels() {
|
|||||||
// TODO allow user for filter
|
// TODO allow user for filter
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchModels()
|
fetchModels()
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return { loading, models }
|
return { loading, models }
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
import { Conversation, Model } from '@janhq/core/lib/types'
|
import { Conversation, Model } from '@janhq/core/lib/types'
|
||||||
import { Button } from '@janhq/uikit'
|
import { Badge, Button } from '@janhq/uikit'
|
||||||
import { motion as m } from 'framer-motion'
|
import { motion as m } from 'framer-motion'
|
||||||
import { useAtomValue, useSetAtom } from 'jotai'
|
import { useAtomValue, useSetAtom } from 'jotai'
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ export default function HistoryList() {
|
|||||||
<div className="sticky top-0 z-20 flex flex-col border-b border-border bg-background px-4 py-3">
|
<div className="sticky top-0 z-20 flex flex-col border-b border-border bg-background px-4 py-3">
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
themes="outline"
|
themes="secondary"
|
||||||
onClick={handleClickConversation}
|
onClick={handleClickConversation}
|
||||||
disabled={!activeModel}
|
disabled={!activeModel}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { Fragment, useEffect } from 'react'
|
|||||||
import { Model } from '@janhq/core/lib/types'
|
import { Model } from '@janhq/core/lib/types'
|
||||||
import { ScrollArea, Input, Button, Badge } from '@janhq/uikit'
|
import { ScrollArea, Input, Button, Badge } from '@janhq/uikit'
|
||||||
|
|
||||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
|
import { useAtom, useAtomValue } from 'jotai'
|
||||||
import { Trash2Icon } from 'lucide-react'
|
import { Trash2Icon } from 'lucide-react'
|
||||||
|
|
||||||
import { currentPromptAtom } from '@/containers/Providers/Jotai'
|
import { currentPromptAtom } from '@/containers/Providers/Jotai'
|
||||||
@ -17,6 +17,7 @@ import useDeleteConversation from '@/hooks/useDeleteConversation'
|
|||||||
|
|
||||||
import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'
|
import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'
|
||||||
|
|
||||||
|
import useGetUserConversations from '@/hooks/useGetUserConversations'
|
||||||
import { useMainViewState } from '@/hooks/useMainViewState'
|
import { useMainViewState } from '@/hooks/useMainViewState'
|
||||||
|
|
||||||
import useSendChatMessage from '@/hooks/useSendChatMessage'
|
import useSendChatMessage from '@/hooks/useSendChatMessage'
|
||||||
@ -28,6 +29,7 @@ import HistoryList from '@/screens/Chat/HistoryList'
|
|||||||
import {
|
import {
|
||||||
currentConversationAtom,
|
currentConversationAtom,
|
||||||
getActiveConvoIdAtom,
|
getActiveConvoIdAtom,
|
||||||
|
userConversationsAtom,
|
||||||
waitingToSendMessage,
|
waitingToSendMessage,
|
||||||
} from '@/helpers/atoms/Conversation.atom'
|
} from '@/helpers/atoms/Conversation.atom'
|
||||||
|
|
||||||
@ -40,7 +42,6 @@ const ChatScreen = () => {
|
|||||||
const { activeModel, stateModel } = useActiveModel()
|
const { activeModel, stateModel } = useActiveModel()
|
||||||
const { setMainViewState } = useMainViewState()
|
const { setMainViewState } = useMainViewState()
|
||||||
|
|
||||||
const isEnableChat = currentConvo && activeModel
|
|
||||||
const [currentPrompt, setCurrentPrompt] = useAtom(currentPromptAtom)
|
const [currentPrompt, setCurrentPrompt] = useAtom(currentPromptAtom)
|
||||||
const currentConvoState = useAtomValue(currentConvoStateAtom)
|
const currentConvoState = useAtomValue(currentConvoStateAtom)
|
||||||
const { sendChatMessage } = useSendChatMessage()
|
const { sendChatMessage } = useSendChatMessage()
|
||||||
@ -49,6 +50,14 @@ const ChatScreen = () => {
|
|||||||
const activeConversationId = useAtomValue(getActiveConvoIdAtom)
|
const activeConversationId = useAtomValue(getActiveConvoIdAtom)
|
||||||
const [isWaitingToSend, setIsWaitingToSend] = useAtom(waitingToSendMessage)
|
const [isWaitingToSend, setIsWaitingToSend] = useAtom(waitingToSendMessage)
|
||||||
const { requestCreateConvo } = useCreateConversation()
|
const { requestCreateConvo } = useCreateConversation()
|
||||||
|
const { getUserConversations } = useGetUserConversations()
|
||||||
|
const conversations = useAtomValue(userConversationsAtom)
|
||||||
|
const isEnableChat = (currentConvo && activeModel) || conversations.length > 0
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getUserConversations()
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [])
|
||||||
|
|
||||||
const handleMessageChange = (value: string) => {
|
const handleMessageChange = (value: string) => {
|
||||||
setCurrentPrompt(value)
|
setCurrentPrompt(value)
|
||||||
@ -81,6 +90,8 @@ const ChatScreen = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(currentConvo)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full">
|
<div className="flex h-full">
|
||||||
<div className="flex h-full w-64 flex-shrink-0 flex-col border-r border-border">
|
<div className="flex h-full w-64 flex-shrink-0 flex-col border-r border-border">
|
||||||
@ -91,14 +102,34 @@ const ChatScreen = () => {
|
|||||||
<div className="relative flex h-full w-full flex-col bg-muted/10">
|
<div className="relative flex h-full w-full flex-col bg-muted/10">
|
||||||
<div className="flex h-full w-full flex-col justify-between">
|
<div className="flex h-full w-full flex-col justify-between">
|
||||||
{isEnableChat && (
|
{isEnableChat && (
|
||||||
<div className="h-[53px] flex-shrink-0 border-b border-border p-4">
|
<div className="h-[53px] flex-shrink-0 border-b border-border bg-background p-4">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span>{currentConvo?.name ?? ''}</span>
|
<span>{currentConvo?.name ?? ''}</span>
|
||||||
<Trash2Icon
|
{downloadedModels.find((x) => x.name === currentConvo?.name) ||
|
||||||
size={16}
|
activeModel?._id === currentConvo?.modelId ? (
|
||||||
className="cursor-pointer text-muted-foreground"
|
<Fragment>
|
||||||
onClick={() => deleteConvo()}
|
{!stateModel.loading && (
|
||||||
/>
|
<Trash2Icon
|
||||||
|
size={16}
|
||||||
|
className="cursor-pointer text-muted-foreground"
|
||||||
|
onClick={() => deleteConvo()}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Fragment>
|
||||||
|
) : (
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
themes="secondary"
|
||||||
|
size="sm"
|
||||||
|
className="-mt-1"
|
||||||
|
onClick={() => {
|
||||||
|
setMainViewState(MainViewState.ExploreModels)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Download Model
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -140,7 +171,11 @@ const ChatScreen = () => {
|
|||||||
className="h-10"
|
className="h-10"
|
||||||
onKeyDown={(e) => handleKeyDown(e)}
|
onKeyDown={(e) => handleKeyDown(e)}
|
||||||
placeholder="Type your message ..."
|
placeholder="Type your message ..."
|
||||||
disabled={!activeModel || stateModel.loading}
|
disabled={
|
||||||
|
!activeModel ||
|
||||||
|
stateModel.loading ||
|
||||||
|
activeModel._id !== currentConvo?.modelId
|
||||||
|
}
|
||||||
value={currentPrompt}
|
value={currentPrompt}
|
||||||
onChange={(e) => handleMessageChange(e.target.value)}
|
onChange={(e) => handleMessageChange(e.target.value)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export default function ExploreModelList(props: Props) {
|
|||||||
const { models } = props
|
const { models } = props
|
||||||
return (
|
return (
|
||||||
<div className="relative h-full w-full flex-shrink-0">
|
<div className="relative h-full w-full flex-shrink-0">
|
||||||
{models?.map((item) => <ExploreModelItem key={item._id} model={item} />)}
|
{models?.map((item, i) => <ExploreModelItem key={i} model={item} />)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,7 +113,8 @@ const MyModelsScreen = () => {
|
|||||||
<Button
|
<Button
|
||||||
themes="danger"
|
themes="danger"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
|
await stopModel(model._id)
|
||||||
deleteModel(model)
|
deleteModel(model)
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user