diff --git a/web/containers/ModelDropdown/ModelSection.tsx b/web/containers/ModelDropdown/ModelSection.tsx index a2072c410d..d4132b6bb7 100644 --- a/web/containers/ModelDropdown/ModelSection.tsx +++ b/web/containers/ModelDropdown/ModelSection.tsx @@ -1,8 +1,12 @@ -import { useEffect, useState } from 'react' +import { useCallback, useEffect, useState } from 'react' import Image from 'next/image' -import { LlmEngine, Model } from '@janhq/core' +import { LlmEngine, Model, RemoteEngine } from '@janhq/core' + +import { Button } from '@janhq/joi' +import { useSetAtom } from 'jotai' +import { SettingsIcon } from 'lucide-react' import useGetModelsByEngine from '@/hooks/useGetModelsByEngine' @@ -10,6 +14,8 @@ import { getTitleByCategory } from '@/utils/model-engine' import ModelLabel from '../ModelLabel' +import { setUpRemoteModelStageAtom } from '@/helpers/atoms/SetupRemoteModel.atom' + type Props = { engine: LlmEngine searchText: string @@ -23,6 +29,22 @@ const ModelSection: React.FC = ({ }) => { const [models, setModels] = useState([]) const { getModelsByEngine } = useGetModelsByEngine() + const setUpRemoteModelStage = useSetAtom(setUpRemoteModelStageAtom) + + const engineLogo: string | undefined = models.find( + (entry) => entry?.metadata?.logo != null + )?.metadata?.logo + + const apiKeyUrl: string | undefined = models.find( + (entry) => entry?.metadata?.api_key_url != null + )?.metadata?.api_key_url + + const onSettingClick = useCallback(() => { + setUpRemoteModelStage('SETUP_API_KEY', engine as unknown as RemoteEngine, { + logo: engineLogo, + api_key_url: apiKeyUrl, + }) + }, [apiKeyUrl, engine, engineLogo, setUpRemoteModelStage]) useEffect(() => { const matchedModels = getModelsByEngine(engine, searchText) @@ -44,7 +66,7 @@ const ModelSection: React.FC = ({ 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 && ( + {model.metadata?.logo ? ( = ({ src={model.metadata?.logo} alt="logo" /> + ) : ( + !model.engine?.includes('cortex.') && ( +
+ ) )} -

{model.name ?? model.model}

+
+

{model.name ?? model.model}

+ {!model.engine?.includes('cortex.') && ( + + )} +
))}