jan/web/screens/Settings/Engines/LocalEngineItem.tsx
Faisal Amir 2a0601f75a
feat: remote engine management (#4364)
* feat: remote engine management

* chore: fix linter issue

* chore: remove unused imports

* fix: populate engines, models and legacy settings (#4403)

* fix: populate engines, models and legacy settings

* chore: legacy logics update configured remote engine

* fix: check exist path before reading

* fix: engines and models persist - race condition

* chore: update issue state

* test: update test cases

* chore: bring back Cortex extension settings

* chore: setup button gear / plus based apikey

* chore: fix remote engine from welcome screen

* chore: resolve linter issue

* chore: support request headers template

* chore: update engines using header_template instead of api_key_template

* chore: update models on changes

* fix: anthropic response template

* chore: fix welcome screen and debounce update value input

* chore: update engines list on changes

* chore: update engines list on change

* chore: update desc form add modal remote engines

* chore: bump cortex version to latest RC

* chore: fix linter

* fix: transform payload of Anthropic and OpenAI

* fix: typo

* fix: openrouter model id for auto routing

* chore: remove remote engine URL setting

* chore: add cohere engine and model support

* fix: should not clean on app launch - models list display issue

* fix: local engine check logic

* chore: bump app version to latest release 0.5.13

* test: fix failed tests

---------

Co-authored-by: Louis <louis@jan.ai>
2025-01-14 17:29:56 +07:00

89 lines
2.9 KiB
TypeScript

import React, { useCallback } from 'react'
import { InferenceEngine } from '@janhq/core'
import { Button, Switch, Badge } from '@janhq/joi'
import { useAtom, useSetAtom } from 'jotai'
import { SettingsIcon } from 'lucide-react'
import { useGetDefaultEngineVariant } from '@/hooks/useEngineManagement'
import { getTitleByEngine } from '@/utils/modelEngine'
import { showSettingActiveLocalEngineAtom } from '@/helpers/atoms/Extension.atom'
import { selectedSettingAtom } from '@/helpers/atoms/Setting.atom'
const LocalEngineItems = ({ engine }: { engine: InferenceEngine }) => {
const { defaultEngineVariant } = useGetDefaultEngineVariant(engine)
const manualDescription = (engine: string) => {
switch (engine) {
case InferenceEngine.cortex_llamacpp:
return 'Fast, efficient local inference engine that runs GGUF models directly on your device'
default:
break
}
}
const setSelectedSetting = useSetAtom(selectedSettingAtom)
const [showSettingActiveLocalEngine, setShowSettingActiveLocalEngineAtom] =
useAtom(showSettingActiveLocalEngineAtom)
const onSwitchChange = useCallback(
(name: string) => {
if (showSettingActiveLocalEngine.includes(name)) {
setShowSettingActiveLocalEngineAtom(
[...showSettingActiveLocalEngine].filter((x) => x !== name)
)
} else {
setShowSettingActiveLocalEngineAtom([
...showSettingActiveLocalEngine,
name,
])
}
},
[showSettingActiveLocalEngine, setShowSettingActiveLocalEngineAtom]
)
return (
<div className="flex w-full flex-col items-start justify-between border-b border-[hsla(var(--app-border))] py-3 sm:flex-row">
<div className="w-full flex-shrink-0 space-y-1.5">
<div className="flex items-center justify-between gap-x-2">
<div>
<div className="flex items-center gap-2">
<h6 className="line-clamp-1 font-semibold capitalize">
{getTitleByEngine(engine as InferenceEngine)}
</h6>
<Badge variant="outline" theme="secondary">
{defaultEngineVariant?.version}
</Badge>
</div>
<div className="mt-2 w-full font-medium leading-relaxed text-[hsla(var(--text-secondary))]">
<p>{manualDescription(engine)}</p>
</div>
</div>
<div className="flex items-center gap-x-3">
<Switch
checked={!showSettingActiveLocalEngine.includes(engine)}
onChange={() => onSwitchChange(engine)}
/>
<Button
theme="icon"
variant="outline"
onClick={() => setSelectedSetting(engine)}
>
<SettingsIcon
size={14}
className="text-[hsla(var(--text-secondary))]"
/>
</Button>
</div>
</div>
</div>
</div>
)
}
export default LocalEngineItems