Skip to content

Commit

Permalink
fix: comment from QA regarding import model (janhq#2213)
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
Co-authored-by: James <[email protected]>
  • Loading branch information
namchuai and James authored Mar 3, 2024
1 parent 52f84dc commit b70e7fb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 52 deletions.
6 changes: 3 additions & 3 deletions electron/handlers/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ export function handleAppIPCs() {
const { canceled, filePaths } = await dialog.showOpenDialog(mainWindow, {
title: 'Select model files',
buttonLabel: 'Select',
properties: ['openFile', 'multiSelections'],
properties: ['openFile', 'openDirectory', 'multiSelections'],
})
if (canceled) {
return
} else {
return filePaths
}

return filePaths
})
}
29 changes: 0 additions & 29 deletions web/containers/ItemCardSidebar/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion web/hooks/useDropModelBinaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function useDropModelBinaries() {
}))
if (unsupportedFiles.length > 0) {
snackbar({
description: `File has to be a .gguf file`,
description: `Only files with .gguf extension can be imported.`,
type: 'error',
})
}
Expand Down
25 changes: 16 additions & 9 deletions web/screens/Settings/EditModelInfoModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ const EditModelInfoModal: React.FC = () => {
return null
}

const onTagsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const tags = e.target.value.split(',')
setTags(tags)
}

return (
<Modal
open={importModelStage === 'EDIT_MODEL_INFO'}
Expand All @@ -128,21 +133,23 @@ const EditModelInfoModal: React.FC = () => {

<div className="flex flex-row space-x-4 rounded-xl border p-4">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-blue-400">
<Paperclip />
<Paperclip color="#fff" />
</div>

<div className="flex flex-col">
<div className="flex flex-1 flex-col">
<p>{editingModel.name}</p>
<div className="flex flex-row">
<span className="mr-2 text-sm text-[#71717A]">
{toGibibytes(editingModel.size)}
</span>
<span className="text-sm font-semibold text-[#71717A]">
Format:{' '}
</span>
<span className="text-sm font-normal text-[#71717A]">
{editingModel.format.toUpperCase()}
</span>
<div className="flex flex-row space-x-1">
<span className="text-sm font-semibold text-[#71717A]">
Format:
</span>
<span className="text-sm font-normal text-[#71717A]">
{editingModel.format.toUpperCase()}
</span>
</div>
</div>
<div className="mt-1 flex flex-row items-center space-x-2">
<span className="line-clamp-1 text-xs font-normal text-[#71717A]">
Expand Down Expand Up @@ -189,7 +196,7 @@ const EditModelInfoModal: React.FC = () => {
</div>
<div className="flex flex-col">
<label className="mb-1">Tags</label>
<Input />
<Input value={tags.join(',')} onChange={onTagsChange} />
</div>
</form>

Expand Down
37 changes: 27 additions & 10 deletions web/screens/Settings/SelectingModelModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react'
import { useDropzone } from 'react-dropzone'

import { ImportingModel, baseName, fs } from '@janhq/core'
import { ImportingModel, baseName, fs, joinPath } from '@janhq/core'
import { Modal, ModalContent, ModalHeader, ModalTitle } from '@janhq/uikit'
import { useAtomValue, useSetAtom } from 'jotai'

Expand Down Expand Up @@ -34,14 +34,31 @@ const SelectingModelModal: React.FC = () => {
const sanitizedFilePaths: FilePathWithSize[] = []
for (const filePath of filePaths) {
const fileStats = await fs.fileStat(filePath, true)
if (!fileStats || fileStats.isDirectory) continue

const fileName = await baseName(filePath)
sanitizedFilePaths.push({
path: filePath,
name: fileName,
size: fileStats.size,
})
if (!fileStats) continue

if (!fileStats.isDirectory) {
const fileName = await baseName(filePath)
sanitizedFilePaths.push({
path: filePath,
name: fileName,
size: fileStats.size,
})
} else {
// allowing only one level of directory
const files = await fs.readdirSync(filePath)

for (const file of files) {
const fullPath = await joinPath([filePath, file])
const fileStats = await fs.fileStat(fullPath, true)
if (!fileStats || fileStats.isDirectory) continue

sanitizedFilePaths.push({
path: fullPath,
name: file,
size: fileStats.size,
})
}
}
}

const unsupportedFiles = sanitizedFilePaths.filter(
Expand All @@ -68,7 +85,7 @@ const SelectingModelModal: React.FC = () => {
)
if (unsupportedFiles.length > 0) {
snackbar({
description: `File has to be a .gguf file`,
description: `Only files with .gguf extension can be imported.`,
type: 'error',
})
}
Expand Down

0 comments on commit b70e7fb

Please sign in to comment.