Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

chore: make utils sanitize modelId

Faisal Amirace8214d4d30
diff --git a/web-app/src/lib/utils.ts b/web-app/src/lib/utils.ts
index dd3301e03..38d3dd672 100644
--- a/web-app/src/lib/utils.ts
+++ b/web-app/src/lib/utils.ts
@@ -155,3 +155,7 @@ export function formatDuration(startTime: number, endTime?: number): string {
return `${durationMs}ms`
}
}
+
+export function sanitizeModelId(modelId: string): string {
+ return modelId.replace(/[^a-zA-Z0-9/_\-.]/g, '')
+}
diff --git a/web-app/src/routes/hub/index.tsx b/web-app/src/routes/hub/index.tsx
index bf6e06157..7ee5d0799 100644
--- a/web-app/src/routes/hub/index.tsx
+++ b/web-app/src/routes/hub/index.tsx
@@ -3,7 +3,7 @@ import { useVirtualizer } from '@tanstack/react-virtual'
import { createFileRoute, useNavigate, useSearch } from '@tanstack/react-router'
import { route } from '@/constants/routes'
import { useModelSources } from '@/hooks/useModelSources'
-import { cn } from '@/lib/utils'
+import { cn, sanitizeModelId } from '@/lib/utils'
import {
useState,
useMemo,
@@ -287,8 +287,8 @@ function Hub() {
const handleDownload = () => {
// Immediately set local downloading state
- addLocalDownloadingModel(modelId.replace(/[^a-zA-Z0-9/_\-.]/g, ''))
- pullModel(modelId.replace(/[^a-zA-Z0-9/_\-.]/g, ''), modelUrl)
+ addLocalDownloadingModel(sanitizeModelId(modelId))
+ pullModel(sanitizeModelId(modelId), modelUrl)
}
return (
@@ -745,16 +745,10 @@ function Hub() {
title={t('hub:downloadModel')}
onClick={() => {
addLocalDownloadingModel(
- variant.model_id.replace(
- /[^a-zA-Z0-9/_\-.]/g,
- ''
- )
+ sanitizeModelId(variant.model_id)
)
pullModel(
- variant.model_id.replace(
- /[^a-zA-Z0-9/_\-.]/g,
- ''
- ),
+ sanitizeModelId(variant.model_id),
variant.path
)
}}
diff --git a/web-app/src/services/models.ts b/web-app/src/services/models.ts
index d4156dc98..36b72c895 100644
--- a/web-app/src/services/models.ts
+++ b/web-app/src/services/models.ts
@@ -5,6 +5,7 @@ import {
SettingComponentProps,
} from '@janhq/core'
import { Model as CoreModel } from '@janhq/core'
+import { sanitizeModelId } from '@/lib/utils'
// Types for model catalog
export interface ModelQuant {
model_id: string
@@ -162,9 +163,7 @@ export const convertHfRepoToCatalogModel = (
}
// Generate model_id from filename (remove .gguf extension, case-insensitive)
- const modelId = file.rfilename
- .replace(/\.gguf$/i, '')
- .replace(/[^a-zA-Z0-9/_\-.]/g, '')
+ const modelId = sanitizeModelId(file.rfilename.replace(/\.gguf$/i, ''))
return {
model_id: modelId,