Skip to content

Commit

Permalink
fix: download state in footer bar and variant status
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Dec 27, 2024
1 parent 0b619ac commit 2be92c7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
5 changes: 4 additions & 1 deletion extensions/inference-cortex-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
)

if (data.task.type === 'Engine') {
events.emit(EngineEvent.OnEngineUpdate, {})
events.emit(EngineEvent.OnEngineUpdate, {
type: data.type,
percent: percent,
})
} else {
if (data.type === DownloadTypes.DownloadSuccess) {
// Delay for the state update from cortex.cpp
Expand Down
11 changes: 7 additions & 4 deletions web/containers/Providers/EventListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ const EventListener = () => {
const onFileDownloadSuccess = useCallback(
async (state: DownloadState) => {
console.debug('onFileDownloadSuccess', state)
if (
state.downloadType !== 'extension' &&
state.downloadType !== 'Engine'
) {
if (state.downloadType !== 'extension') {
// Update model metadata accordingly
const model = ModelManager.instance().models.get(state.modelId)
if (model) {
Expand All @@ -111,6 +108,12 @@ const EventListener = () => {
...model.parameters,
} as Partial<Model>)
.catch((e) => console.debug(e))

toaster({
title: 'Download Completed',
description: `Download ${state.modelId} completed`,
type: 'success',
})
}
state.downloadState = 'end'
setDownloadState(state)
Expand Down
5 changes: 0 additions & 5 deletions web/hooks/useDownloadState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ export const setDownloadStateAtom = atom(
(e) => e.id === state.modelId
)
if (model) set(downloadedModelsAtom, (prev) => [...prev, model])
toaster({
title: 'Download Completed',
description: `Download ${state.modelId} completed`,
type: 'success',
})
}
} else if (state.downloadState === 'error') {
// download error
Expand Down
12 changes: 10 additions & 2 deletions web/screens/Settings/Engines/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, { useCallback, useEffect, useState } from 'react'
import React, { useCallback, useEffect, useMemo, useState } from 'react'

import { EngineEvent, events, InferenceEngine } from '@janhq/core'
import { Button, ScrollArea, Badge, Select } from '@janhq/joi'
Expand Down Expand Up @@ -67,6 +67,14 @@ const EngineSettings = ({ engine }: { engine: InferenceEngine }) => {
defaultEngineVariant?.variant
)

const selectedVariant = useMemo(
() =>
options?.map((e) => e.value).includes(selectedVariants)
? selectedVariants
: undefined,
[selectedVariants, options]
)

useEffect(() => {
if (defaultEngineVariant?.variant) {
setSelectedVariants(defaultEngineVariant.variant || '')
Expand Down Expand Up @@ -157,7 +165,7 @@ const EngineSettings = ({ engine }: { engine: InferenceEngine }) => {
<div className="flex flex-shrink-0 items-center gap-x-3">
<div className="flex w-full min-w-[180px]">
<Select
value={selectedVariants}
value={selectedVariant}
placeholder="Select variant"
onValueChange={(e) => handleChangeVariant(e)}
options={options}
Expand Down

0 comments on commit 2be92c7

Please sign in to comment.