Skip to content

Commit

Permalink
fix(JanHub): #1158 sort model list
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
James committed Jan 4, 2024
1 parent 97c0fee commit 943cff6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
67 changes: 39 additions & 28 deletions web/screens/ExploreModels/ExploreModelList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Model } from '@janhq/core'

import ExploreModelItem from '@/screens/ExploreModels/ExploreModelItem'
Expand All @@ -8,33 +7,45 @@ type Props = {
}

const ExploreModelList: React.FC<Props> = ({ models }) => {
const sortOrder: Record<string, number> = {
'7b': 1,
'13b': 2,
'34b': 3,
'70b': 4,
'120b': 5,
'tiny': 6,
}
const sortedModels = models?.sort((a, b) => {
const aIsFeatured = a.metadata.tags.includes('Featured')
const bIsFeatured = b.metadata.tags.includes('Featured')
const aIsRecommended = a.metadata.tags.includes('Recommended')
const bIsRecommended = b.metadata.tags.includes('Recommended')
const aNumericTag =
a.metadata.tags.find((tag) => !!sortOrder[tag.toLowerCase()]) ?? 'Tiny'
const bNumericTag =
b.metadata.tags.find((tag) => !!sortOrder[tag.toLowerCase()]) ?? 'Tiny'

if (aIsFeatured !== bIsFeatured) return aIsFeatured ? -1 : 1
if (aNumericTag !== bNumericTag)
return (
sortOrder[aNumericTag.toLowerCase()] -
sortOrder[bNumericTag.toLowerCase()]
)
if (aIsRecommended !== bIsRecommended) return aIsRecommended ? -1 : 1
return a.metadata.size - b.metadata.size
})
const takenModelIds: string[] = []
const featuredModels = models
.filter((m) => {
if (m.metadata.tags.includes('Featured')) {
takenModelIds.push(m.id)
return m
}
})
.sort((m1, m2) => m1.metadata.size - m2.metadata.size)

const recommendedModels = models
.filter((m) => {
if (m.metadata.tags.includes('Recommended')) {
takenModelIds.push(m.id)
return m
}
})
.sort((m1, m2) => m1.metadata.size - m2.metadata.size)

const openAiModels = models
.filter((m) => {
if (m.engine === 'openai') {
takenModelIds.push(m.id)
return m
}
})
.sort((m1: Model, m2: Model) => m1.name.localeCompare(m2.name))

const remainingModels = models
.filter((m) => !takenModelIds.includes(m.id))
.sort((m1, m2) => m1.metadata.size - m2.metadata.size)

const sortedModels: Model[] = [
...featuredModels,
...recommendedModels,
...openAiModels,
...remainingModels,
]

return (
<div className="relative h-full w-full flex-shrink-0">
{sortedModels?.map((model) => (
Expand Down
14 changes: 9 additions & 5 deletions web/screens/ExploreModels/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react'

import { openExternalUrl } from '@janhq/core'
import {
Input,
ScrollArea,
Expand Down Expand Up @@ -44,6 +45,10 @@ const ExploreModelsScreen = () => {
}
})

const onHowToImportModelClick = () => {
openExternalUrl('https://jan.ai/guides/using-models/import-manually/')
}

if (loading) return <Loader description="loading ..." />

return (
Expand Down Expand Up @@ -72,13 +77,12 @@ const ExploreModelsScreen = () => {
/>
</div>
<div className="mt-2 text-center">
<a
href="https://jan.ai/guides/using-models/import-manually/"
target="_blank"
className="font-semibold text-white underline"
<p
onClick={onHowToImportModelClick}
className="cursor-pointer font-semibold text-white underline"
>
How to manually import models
</a>
</p>
</div>
</div>
</div>
Expand Down

0 comments on commit 943cff6

Please sign in to comment.