fix: model is started but the indicator is not stopped loading (#446)
* fix: model is started but the indicator is not stopped loading * chore: show loading indicator on the loading model row only * Update README.md --------- Co-authored-by: hiento09 <136591877+hiento09@users.noreply.github.com>
This commit is contained in:
parent
4ae4da9507
commit
ca0c5f571f
@ -5,4 +5,4 @@
|
|||||||
- index.ts: Main entry point for the plugin.
|
- index.ts: Main entry point for the plugin.
|
||||||
- module.ts: Defines the plugin module which would be executed by the main node process.
|
- module.ts: Defines the plugin module which would be executed by the main node process.
|
||||||
- package.json: Defines the plugin metadata.
|
- package.json: Defines the plugin metadata.
|
||||||
- tsconfig.json: Defines the typescript configuration.
|
- tsconfig.json: Defines the typescript configuration.
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
import React, { useState } from 'react'
|
import React from 'react'
|
||||||
import { Button } from '@uikit'
|
import { Button } from '@uikit'
|
||||||
import ModelActionMenu from '../ModelActionMenu'
|
import ModelActionMenu from '../ModelActionMenu'
|
||||||
import { useAtomValue } from 'jotai'
|
|
||||||
|
|
||||||
import { stateModel } from '@helpers/atoms/Model.atom'
|
|
||||||
|
|
||||||
export enum ModelActionType {
|
export enum ModelActionType {
|
||||||
Start = 'Start',
|
Start = 'Start',
|
||||||
@ -25,26 +22,24 @@ const modelActionMapper: Record<ModelActionType, ModelActionStyle> = {
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
|
loading?: boolean
|
||||||
type: ModelActionType
|
type: ModelActionType
|
||||||
onActionClick: (type: ModelActionType) => void
|
onActionClick: (type: ModelActionType) => void
|
||||||
onDeleteClick: () => void
|
onDeleteClick: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ModelActionButton: React.FC<Props> = ({
|
const ModelActionButton: React.FC<Props> = ({
|
||||||
disabled = false,
|
disabled,
|
||||||
|
loading,
|
||||||
type,
|
type,
|
||||||
onActionClick,
|
onActionClick,
|
||||||
onDeleteClick,
|
onDeleteClick,
|
||||||
}) => {
|
}) => {
|
||||||
const styles = modelActionMapper[type]
|
const styles = modelActionMapper[type]
|
||||||
// const { startingModel } = useStartStopModel()
|
|
||||||
|
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
onActionClick(type)
|
onActionClick(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = useAtomValue(stateModel)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<td className="whitespace-nowrap px-3 py-2 text-right">
|
<td className="whitespace-nowrap px-3 py-2 text-right">
|
||||||
<div className="flex items-center justify-end gap-x-4">
|
<div className="flex items-center justify-end gap-x-4">
|
||||||
@ -54,7 +49,7 @@ const ModelActionButton: React.FC<Props> = ({
|
|||||||
size="sm"
|
size="sm"
|
||||||
themes={styles.title === 'Start' ? 'accent' : 'default'}
|
themes={styles.title === 'Start' ? 'accent' : 'default'}
|
||||||
onClick={() => onClick()}
|
onClick={() => onClick()}
|
||||||
loading={state.loading}
|
loading={loading}
|
||||||
>
|
>
|
||||||
{styles.title} Model
|
{styles.title} Model
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { useAtomValue } from 'jotai'
|
|||||||
import ModelActionButton, { ModelActionType } from '../ModelActionButton'
|
import ModelActionButton, { ModelActionType } from '../ModelActionButton'
|
||||||
import useStartStopModel from '@hooks/useStartStopModel'
|
import useStartStopModel from '@hooks/useStartStopModel'
|
||||||
import useDeleteModel from '@hooks/useDeleteModel'
|
import useDeleteModel from '@hooks/useDeleteModel'
|
||||||
import { activeAssistantModelAtom } from '@helpers/atoms/Model.atom'
|
import { activeAssistantModelAtom, stateModel } from '@helpers/atoms/Model.atom'
|
||||||
import { toGigabytes } from '@utils/converter'
|
import { toGigabytes } from '@utils/converter'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -12,9 +12,10 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ModelRow: React.FC<Props> = ({ model }) => {
|
const ModelRow: React.FC<Props> = ({ model }) => {
|
||||||
const { loading, startModel, stopModel } = useStartStopModel()
|
const { startModel, stopModel } = useStartStopModel()
|
||||||
const activeModel = useAtomValue(activeAssistantModelAtom)
|
const activeModel = useAtomValue(activeAssistantModelAtom)
|
||||||
const { deleteModel } = useDeleteModel()
|
const { deleteModel } = useDeleteModel()
|
||||||
|
const { loading, model: currentModelState } = useAtomValue(stateModel)
|
||||||
|
|
||||||
let status = ModelStatus.Installed
|
let status = ModelStatus.Installed
|
||||||
if (activeModel && activeModel._id === model._id) {
|
if (activeModel && activeModel._id === model._id) {
|
||||||
@ -58,6 +59,7 @@ const ModelRow: React.FC<Props> = ({ model }) => {
|
|||||||
</td>
|
</td>
|
||||||
<ModelActionButton
|
<ModelActionButton
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
|
loading={currentModelState === model._id ? loading : false}
|
||||||
type={actionButtonType}
|
type={actionButtonType}
|
||||||
onActionClick={onModelActionClick}
|
onActionClick={onModelActionClick}
|
||||||
onDeleteClick={onDeleteClick}
|
onDeleteClick={onDeleteClick}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import { useState } from 'react'
|
|||||||
|
|
||||||
export default function useStartStopModel() {
|
export default function useStartStopModel() {
|
||||||
const [activeModel, setActiveModel] = useAtom(activeAssistantModelAtom)
|
const [activeModel, setActiveModel] = useAtom(activeAssistantModelAtom)
|
||||||
const [loading, setLoading] = useState<boolean>(false)
|
|
||||||
const setStateModel = useSetAtom(stateModel)
|
const setStateModel = useSetAtom(stateModel)
|
||||||
|
|
||||||
const startModel = async (modelId: string) => {
|
const startModel = async (modelId: string) => {
|
||||||
@ -24,12 +23,11 @@ export default function useStartStopModel() {
|
|||||||
if (!model) {
|
if (!model) {
|
||||||
alert(`Model ${modelId} not found! Please re-download the model first.`)
|
alert(`Model ${modelId} not found! Please re-download the model first.`)
|
||||||
setStateModel((prev) => ({ ...prev, loading: false }))
|
setStateModel((prev) => ({ ...prev, loading: false }))
|
||||||
}
|
}
|
||||||
const currentTime = Date.now()
|
const currentTime = Date.now()
|
||||||
console.debug('Init model: ', model._id)
|
console.debug('Init model: ', model._id)
|
||||||
|
|
||||||
const res = await executeSerial(InferenceService.InitModel, model._id)
|
const res = await executeSerial(InferenceService.InitModel, model._id)
|
||||||
|
|
||||||
if (res?.error) {
|
if (res?.error) {
|
||||||
const errorMessage = `Failed to init model: ${res.error}`
|
const errorMessage = `Failed to init model: ${res.error}`
|
||||||
console.error(errorMessage)
|
console.error(errorMessage)
|
||||||
@ -40,7 +38,7 @@ export default function useStartStopModel() {
|
|||||||
)
|
)
|
||||||
setActiveModel(model)
|
setActiveModel(model)
|
||||||
}
|
}
|
||||||
setLoading(false)
|
setStateModel((prev) => ({ ...prev, loading: false }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const stopModel = async (modelId: string) => {
|
const stopModel = async (modelId: string) => {
|
||||||
@ -52,5 +50,5 @@ export default function useStartStopModel() {
|
|||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { loading, startModel, stopModel }
|
return { startModel, stopModel }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user