Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: engine logo on model dropdown #3291

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 52 additions & 36 deletions web/containers/ModelDropdown/ModelSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { useCallback, useEffect, useState } from 'react'

import Image from 'next/image'

import { LlmEngine, Model, RemoteEngine } from '@janhq/core'
import { EngineStatus, LlmEngine, Model, RemoteEngine } from '@janhq/core'

import { Button } from '@janhq/joi'
import { useSetAtom } from 'jotai'
import { SettingsIcon } from 'lucide-react'

import { twMerge } from 'tailwind-merge'

import useEngineQuery from '@/hooks/useEngineQuery'
import useGetModelsByEngine from '@/hooks/useGetModelsByEngine'

import { getTitleByCategory } from '@/utils/model-engine'
Expand All @@ -30,6 +33,7 @@ const ModelSection: React.FC<Props> = ({
const [models, setModels] = useState<Model[]>([])
const { getModelsByEngine } = useGetModelsByEngine()
const setUpRemoteModelStage = useSetAtom(setUpRemoteModelStageAtom)
const { data: engineData } = useEngineQuery()

const engineLogo: string | undefined = models.find(
(entry) => entry?.metadata?.logo != null
Expand All @@ -56,43 +60,55 @@ const ModelSection: React.FC<Props> = ({

return (
<div className="w-full pt-2">
<h6 className="mb-1 px-3 font-medium text-[hsla(var(--text-secondary))]">
{engineName}
</h6>
<div className="flex justify-between pr-2">
<div className="flex gap-2 pl-3">
{engineLogo && (
<Image
className="h-5 w-5 flex-shrink-0 rounded-full object-cover"
width={40}
height={40}
src={engineLogo}
alt="logo"
/>
)}
<h6 className="mb-1 pr-3 font-medium text-[hsla(var(--text-secondary))]">
{engineName}
</h6>
</div>
<Button theme="icon" onClick={onSettingClick}>
<SettingsIcon
size={14}
className="text-[hsla(var(--text-secondary))]"
/>
</Button>
</div>
<ul className="pb-2">
{models.map((model) => (
<li
key={model.model}
className="flex cursor-pointer items-center gap-2 px-3 py-2 hover:bg-[hsla(var(--dropdown-menu-hover-bg))]"
onClick={() => onModelSelected(model)}
>
{model.metadata?.logo ? (
<Image
className="rounded-full object-cover"
width={20}
height={20}
src={model.metadata?.logo}
alt="logo"
/>
) : (
!model.engine?.includes('cortex.') && (
<div className="flex h-5 w-5 items-center justify-center rounded-full border border-[hsla(var(--app-border))] bg-gradient-to-r from-cyan-500 to-blue-500" />
)
)}
<div className="flex w-full items-center justify-between">
<p className="line-clamp-1">{model.name ?? model.model}</p>
{!model.engine?.includes('cortex.') && (
<Button theme="icon" onClick={onSettingClick}>
<SettingsIcon
size={14}
className="text-[hsla(var(--text-secondary))]"
/>
</Button>
{models.map((model) => {
const isEngineReady =
engineData?.find((e) => e.name === model.engine)?.status ===
EngineStatus.Ready
return (
<li
key={model.model}
className={twMerge(
'flex cursor-pointer items-center gap-2 px-3 py-2 hover:bg-[hsla(var(--dropdown-menu-hover-bg))]',
isEngineReady
? 'text-[hsla(var(--text-primary))]'
: 'cursor-not-allowed text-[hsla(var(--text-tertiary))]'
)}
</div>
<ModelLabel metadata={model.metadata} compact />
</li>
))}
onClick={() => {
if (isEngineReady) {
onModelSelected(model)
}
}}
>
<div className="flex w-full items-center justify-between">
<p className="line-clamp-1">{model.name ?? model.model}</p>
</div>
<ModelLabel metadata={model.metadata} compact />
</li>
)
})}
</ul>
</div>
)
Expand Down
Loading