Skip to content

Commit

Permalink
chore: rebase main
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Nov 28, 2023
1 parent eeb2690 commit 9d0fa64
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 112 deletions.
3 changes: 1 addition & 2 deletions core/src/plugins/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ export abstract class ModelPlugin extends JanPlugin {

/**
* Cancels the download of a specific model.
* @param {string} name - The name of the model to cancel the download for.
* @param {string} modelId - The ID of the model to cancel the download for.
* @returns {Promise<void>} A promise that resolves when the download has been cancelled.
*/
abstract cancelModelDownload(name: string, modelId: string): Promise<void>;
abstract cancelModelDownload(modelId: string): Promise<void>;

/**
* Deletes a model.
Expand Down
6 changes: 3 additions & 3 deletions plugins/model-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export default class JanModelPlugin implements ModelPlugin {
* @param {string} modelId - The ID of the model whose download is to be cancelled.
* @returns {Promise<void>} A promise that resolves when the download has been cancelled.
*/
async cancelModelDownload(name: string, modelId: string): Promise<void> {
return abortDownload(join(JanModelPlugin._homeDir, name, modelId)).then(
async cancelModelDownload(modelId: string): Promise<void> {
return abortDownload(join(JanModelPlugin._homeDir, modelId, modelId)).then(
() => {
fs.deleteFile(join(JanModelPlugin._homeDir, name, modelId))
fs.rmdir(join(JanModelPlugin._homeDir, modelId))
}
)
}
Expand Down
17 changes: 6 additions & 11 deletions web/containers/Providers/EventHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'

import {
addNewMessageAtom,
chatMessages,
updateMessageAtom,
} from '@/helpers/atoms/ChatMessage.atom'
import {
Expand All @@ -35,15 +34,12 @@ export default function EventHandler({ children }: { children: ReactNode }) {

const updateConvWaiting = useSetAtom(updateConversationWaitingForResponseAtom)
const models = useAtomValue(downloadingModelsAtom)
const messages = useAtomValue(chatMessages)
const conversations = useAtomValue(threadsAtom)
const messagesRef = useRef(messages)
const convoRef = useRef(conversations)
const threads = useAtomValue(threadsAtom)
const threadsRef = useRef(threads)

useEffect(() => {
messagesRef.current = messages
convoRef.current = conversations
}, [messages, conversations])
threadsRef.current = threads
}, [threads])

async function handleNewMessageResponse(message: ThreadMessage) {
addNewMessage(message)
Expand All @@ -59,7 +55,6 @@ export default function EventHandler({ children }: { children: ReactNode }) {
}

async function handleMessageResponseFinished(message: ThreadMessage) {
if (!convoRef.current) return
updateConvWaiting(message.thread_id, false)

if (message.id && message.content) {
Expand All @@ -70,8 +65,7 @@ export default function EventHandler({ children }: { children: ReactNode }) {
MessageStatus.Ready
)
}

const thread = convoRef.current.find((e) => e.id == message.thread_id)
const thread = threadsRef.current?.find((e) => e.id == message.thread_id)
if (thread) {
const messageContent = message.content[0]?.text.value ?? ''
const metadata = {
Expand All @@ -93,6 +87,7 @@ export default function EventHandler({ children }: { children: ReactNode }) {

function handleDownloadUpdate(state: any) {
if (!state) return
state.fileName = state.fileName.split('/').pop() ?? ''
setDownloadState(state)
}

Expand Down
4 changes: 2 additions & 2 deletions web/hooks/useDeleteConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function useDeleteThread() {
const deleteMessages = useSetAtom(deleteConversationMessage)
const cleanMessages = useSetAtom(cleanConversationMessages)

const cleanConvo = async () => {
const cleanThread = async () => {
if (activeThreadId) {
const currentConversation = userConversations.filter(
(c) => c.id === activeThreadId
Expand Down Expand Up @@ -76,7 +76,7 @@ export default function useDeleteThread() {
}

return {
cleanConvo,
cleanThread,
deleteThread,
}
}
1 change: 0 additions & 1 deletion web/hooks/useDownloadState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const setDownloadStateAtom = atom(null, (get, set, state: DownloadState) => {
console.debug(
`current download state for ${state.fileName} is ${JSON.stringify(state)}`
)
state.fileName = state.fileName.replace('models/', '')
currentState[state.fileName] = state
set(modelDownloadStateAtom, currentState)
})
Expand Down
9 changes: 7 additions & 2 deletions web/hooks/useGetDownloadedModels.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useEffect, useState } from 'react'
import { useEffect } from 'react'

import { PluginType } from '@janhq/core'
import { ModelPlugin } from '@janhq/core/lib/plugins'
import { Model } from '@janhq/core/lib/types'

import { atom, useAtom } from 'jotai'

import { pluginManager } from '@/plugin/PluginManager'

const downloadedModelsAtom = atom<Model[]>([])

export function useGetDownloadedModels() {
const [downloadedModels, setDownloadedModels] = useState<Model[]>([])
const [downloadedModels, setDownloadedModels] = useAtom(downloadedModelsAtom)

useEffect(() => {
getDownloadedModels().then((downloadedModels) => {
Expand All @@ -22,5 +26,6 @@ export async function getDownloadedModels(): Promise<Model[]> {
const models = await pluginManager
.get<ModelPlugin>(PluginType.Model)
?.getDownloadedModels()

return models ?? []
}
2 changes: 0 additions & 2 deletions web/screens/Chat/ChatBody/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useAtomValue } from 'jotai'

import ChatInstruction from '../ChatInstruction'
import ChatItem from '../ChatItem'

import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
Expand All @@ -12,7 +11,6 @@ const ChatBody: React.FC = () => {
{messages.map((message) => (
<ChatItem {...message} key={message.id} />
))}
{messages.length === 0 && <ChatInstruction />}
</div>
)
}
Expand Down
80 changes: 0 additions & 80 deletions web/screens/Chat/ChatInstruction/index.tsx

This file was deleted.

14 changes: 5 additions & 9 deletions web/screens/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fragment, useContext, useEffect, useRef, useState } from 'react'
import { Fragment, useEffect, useRef, useState } from 'react'

import { Button, Badge, Textarea } from '@janhq/uikit'

Expand All @@ -11,10 +11,6 @@ import { currentPromptAtom } from '@/containers/Providers/Jotai'

import ShortCut from '@/containers/Shortcut'

import { toaster } from '@/containers/Toast'

import { FeatureToggleContext } from '@/context/FeatureToggle'

import { MainViewState } from '@/constants/screens'

import { useActiveModel } from '@/hooks/useActiveModel'
Expand Down Expand Up @@ -43,7 +39,7 @@ import { activeThreadStateAtom } from '@/helpers/atoms/Conversation.atom'
const ChatScreen = () => {
const currentConvo = useAtomValue(activeThreadAtom)
const { downloadedModels } = useGetDownloadedModels()
const { deleteThread, cleanConvo } = useDeleteThread()
const { deleteThread, cleanThread } = useDeleteThread()
const { activeModel, stateModel } = useActiveModel()
const { setMainViewState } = useMainViewState()

Expand Down Expand Up @@ -142,13 +138,13 @@ const ChatScreen = () => {
<Paintbrush
size={16}
className="cursor-pointer text-muted-foreground"
onClick={() => cleanConvo()}
onClick={() => cleanThread()}
/>
<Trash2Icon
size={16}
className="cursor-pointer text-muted-foreground"
onClick={() => deleteThread()}
/>
onClick={() => deleteThread()}
/>
</div>
</div>
</div>
Expand Down

0 comments on commit 9d0fa64

Please sign in to comment.