fix: remote engine should not allow reinit (#3284)
* chore: local engines should not allow reinit * fix: remote engines should not have install action
This commit is contained in:
parent
105a9aa1a1
commit
98abff0da3
@ -19,6 +19,17 @@ export type LlmEngine = (typeof LlmEngines)[number]
|
||||
export type LocalEngine = (typeof LocalEngines)[number]
|
||||
export type RemoteEngine = (typeof RemoteEngines)[number]
|
||||
|
||||
/**
|
||||
* The available engine statuses.
|
||||
*/
|
||||
export enum EngineStatus {
|
||||
Ready = 'ready',
|
||||
MissingConfiguration = 'missing_configuration',
|
||||
NotInitialized = 'not_initialized',
|
||||
NotSupported = 'not_supported',
|
||||
Error = 'error',
|
||||
}
|
||||
|
||||
export type ModelArtifact = {
|
||||
filename: string
|
||||
url: string
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { HuggingFaceRepoData } from '@janhq/core/.'
|
||||
import { HuggingFaceRepoData } from '@janhq/core'
|
||||
import { atom } from 'jotai'
|
||||
|
||||
// modals
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Engine } from '@cortexso/cortex.js/resources'
|
||||
import { EngineStatus } from '@janhq/core'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
|
||||
import useCortex from './useCortex'
|
||||
@ -22,7 +23,7 @@ const useEngineInit = () => {
|
||||
const engineStatuses = queryCacheData as Engine[]
|
||||
engineStatuses.forEach((engine) => {
|
||||
if (engine.name === engineName) {
|
||||
engine.status = 'ready'
|
||||
engine.status = EngineStatus.Ready
|
||||
}
|
||||
})
|
||||
console.debug(`Updated engine status: ${engineStatuses}`)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { useCallback } from 'react'
|
||||
|
||||
import { HuggingFaceRepoData } from '@janhq/core/.'
|
||||
import { HuggingFaceRepoData } from '@janhq/core'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
|
||||
import { useSetAtom } from 'jotai'
|
||||
|
||||
@ -3,6 +3,7 @@ import { useCallback, useRef } from 'react'
|
||||
import {
|
||||
ChatCompletionCreateParamsNonStreaming,
|
||||
ChatCompletionMessageParam,
|
||||
EngineStatus,
|
||||
LocalEngines,
|
||||
Message,
|
||||
MessageContent,
|
||||
@ -193,7 +194,7 @@ const useSendMessage = () => {
|
||||
return false
|
||||
}
|
||||
|
||||
if (engineStatus.status !== 'ready') {
|
||||
if (engineStatus.status !== EngineStatus.Ready) {
|
||||
toaster({
|
||||
title: errorTitle,
|
||||
description: `Engine ${engineStatus.name} is not ready`,
|
||||
|
||||
@ -2,7 +2,7 @@ import { useCallback, useMemo } from 'react'
|
||||
|
||||
import Image from 'next/image'
|
||||
|
||||
import { RemoteEngine, RemoteEngines } from '@janhq/core'
|
||||
import { EngineStatus, RemoteEngine, RemoteEngines } from '@janhq/core'
|
||||
|
||||
import { Button } from '@janhq/joi'
|
||||
import { useSetAtom } from 'jotai'
|
||||
@ -70,7 +70,8 @@ const SetUpComponent: React.FC<SetUpProps> = ({
|
||||
() =>
|
||||
engineData == null
|
||||
? false
|
||||
: engineData.find((e) => e.name === engine)?.status === 'ready',
|
||||
: engineData.find((e) => e.name === engine)?.status ===
|
||||
EngineStatus.Ready,
|
||||
[engineData, engine]
|
||||
)
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React, { useCallback, useMemo } from 'react'
|
||||
|
||||
import { LocalEngines, RemoteEngine } from '@janhq/core'
|
||||
import { EngineStatus, LocalEngines, RemoteEngine } from '@janhq/core'
|
||||
|
||||
import { Button } from '@janhq/joi'
|
||||
import { useAtomValue, useSetAtom } from 'jotai'
|
||||
@ -54,7 +54,8 @@ const HubModelCard: React.FC<HfModelEntry> = ({ name, downloads, model }) => {
|
||||
const isEngineConfigured: boolean =
|
||||
engineData == null || model?.engine == null
|
||||
? false
|
||||
: engineData.find((e) => e.name === model.engine)?.status === 'ready'
|
||||
: engineData.find((e) => e.name === model.engine)?.status ===
|
||||
EngineStatus.Ready
|
||||
|
||||
const isModelDownloaded = downloadedModels.find(
|
||||
(m) => m.model === model!.model
|
||||
@ -78,7 +79,8 @@ const HubModelCard: React.FC<HfModelEntry> = ({ name, downloads, model }) => {
|
||||
const isApiKeyAdded: boolean =
|
||||
engineData == null || model?.engine == null
|
||||
? false
|
||||
: engineData.find((e) => e.name === model.engine)?.status === 'ready'
|
||||
: engineData.find((e) => e.name === model.engine)?.status ===
|
||||
EngineStatus.Ready
|
||||
|
||||
const isModelDownloaded = downloadedModels.find(
|
||||
(m) => m.model === model.model
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React, { useCallback } from 'react'
|
||||
|
||||
import { RemoteEngine } from '@janhq/core'
|
||||
import { EngineStatus, RemoteEngine } from '@janhq/core'
|
||||
import { useAtomValue, useSetAtom } from 'jotai'
|
||||
|
||||
import { toaster } from '@/containers/Toast'
|
||||
@ -38,7 +38,8 @@ const RemoteModelCard: React.FC<HfModelEntry> = ({ name, model }) => {
|
||||
const isApiKeyAdded: boolean =
|
||||
engineData == null || model?.engine == null
|
||||
? false
|
||||
: engineData.find((e) => e.name === model.engine)?.status === 'ready'
|
||||
: engineData.find((e) => e.name === model.engine)?.status ===
|
||||
EngineStatus.Ready
|
||||
|
||||
const isModelDownloaded = downloadedModels.find(
|
||||
(m) => m.model === model.model
|
||||
|
||||
@ -4,7 +4,7 @@ import React from 'react'
|
||||
|
||||
import Image from 'next/image'
|
||||
|
||||
import { RemoteEngine } from '@janhq/core'
|
||||
import { EngineStatus, RemoteEngine } from '@janhq/core'
|
||||
import { Button } from '@janhq/joi'
|
||||
|
||||
import { useSetAtom } from 'jotai'
|
||||
@ -47,7 +47,8 @@ const RemoteModelGroup: React.FC<Props> = ({ data, engine, onSeeAllClick }) => {
|
||||
() =>
|
||||
engineData == null || engine == null
|
||||
? false
|
||||
: engineData.find((e) => e.name === engine)?.status === 'ready',
|
||||
: engineData.find((e) => e.name === engine)?.status ===
|
||||
EngineStatus.Ready,
|
||||
[engineData, engine]
|
||||
)
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ import { Fragment, useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import Image from 'next/image'
|
||||
|
||||
import { EngineStatus } from '@janhq/core'
|
||||
import { Button, Input, Modal } from '@janhq/joi'
|
||||
import { useAtom, useSetAtom } from 'jotai'
|
||||
import { ArrowUpRight } from 'lucide-react'
|
||||
@ -28,7 +29,8 @@ const SetUpApiKeyModal: React.FC = () => {
|
||||
useEffect(() => {
|
||||
if (!remoteEngine || !engineData) return
|
||||
const isEngineReady =
|
||||
engineData.find((e) => e.name === remoteEngine)?.status === 'ready'
|
||||
engineData.find((e) => e.name === remoteEngine)?.status ===
|
||||
EngineStatus.Ready
|
||||
const fakeApiKey = '******************************************'
|
||||
setApiKey(isEngineReady ? fakeApiKey : '')
|
||||
}, [remoteEngine, engineData])
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { LlmEngine } from '@janhq/core/.'
|
||||
import { EngineStatus, LlmEngine, LocalEngines } from '@janhq/core'
|
||||
import {
|
||||
Button,
|
||||
ScrollArea,
|
||||
@ -69,8 +69,9 @@ const EngineSetting: React.FC = () => {
|
||||
</TableCell>
|
||||
<TableCell>{getStatusTitle(engineStatus.status)}</TableCell>
|
||||
<TableCell>
|
||||
{['ready', 'not_initialized'].includes(
|
||||
engineStatus.status
|
||||
{LocalEngines.some((e) => e === engineStatus.name) &&
|
||||
[EngineStatus.Ready, EngineStatus.NotInitialized].includes(
|
||||
engineStatus.status as EngineStatus
|
||||
) ? (
|
||||
<Button
|
||||
theme="primary"
|
||||
@ -80,7 +81,7 @@ const EngineSetting: React.FC = () => {
|
||||
)
|
||||
}
|
||||
>
|
||||
{engineStatus.status === 'ready'
|
||||
{engineStatus.status === EngineStatus.Ready
|
||||
? 'Reinstall'
|
||||
: 'Install'}
|
||||
</Button>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user