Skip to content

Commit

Permalink
fix: remote engine should not allow reinit (#3284)
Browse files Browse the repository at this point in the history
* chore: local engines should not allow reinit

* fix: remote engines should not have install action
  • Loading branch information
louis-jan authored Aug 7, 2024
1 parent 105a9aa commit 98abff0
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 18 deletions.
11 changes: 11 additions & 0 deletions core/src/types/model/modelEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web/helpers/atoms/HuggingFace.atom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HuggingFaceRepoData } from '@janhq/core/.'
import { HuggingFaceRepoData } from '@janhq/core'
import { atom } from 'jotai'

// modals
Expand Down
3 changes: 2 additions & 1 deletion web/hooks/useEngineInit.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion web/hooks/useHfModelFetchAndDownload.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 2 additions & 1 deletion web/hooks/useSendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback, useRef } from 'react'
import {
ChatCompletionCreateParamsNonStreaming,
ChatCompletionMessageParam,
EngineStatus,
LocalEngines,
Message,
MessageContent,
Expand Down Expand Up @@ -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`,
Expand Down
5 changes: 3 additions & 2 deletions web/screens/HubScreen2/components/GroupInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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]
)

Expand Down
8 changes: 5 additions & 3 deletions web/screens/HubScreen2/components/HubModelCard.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions web/screens/HubScreen2/components/RemoteModelCard.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions web/screens/HubScreen2/components/RemoteModelGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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]
)

Expand Down
4 changes: 3 additions & 1 deletion web/screens/HubScreen2/components/SetUpApiKeyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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])
Expand Down
9 changes: 5 additions & 4 deletions web/screens/Settings/EngineSetting/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LlmEngine } from '@janhq/core/.'
import { EngineStatus, LlmEngine, LocalEngines } from '@janhq/core'
import {
Button,
ScrollArea,
Expand Down Expand Up @@ -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"
Expand All @@ -80,7 +81,7 @@ const EngineSetting: React.FC = () => {
)
}
>
{engineStatus.status === 'ready'
{engineStatus.status === EngineStatus.Ready
? 'Reinstall'
: 'Install'}
</Button>
Expand Down

0 comments on commit 98abff0

Please sign in to comment.