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

81 lines
2.6 KiB
TypeScript

import { Tooltip, Button, Badge } from '@janhq/joi'
import { useAtom, useAtomValue } from 'jotai'
import { useActiveModel } from '@/hooks/useActiveModel'
import { toGibibytes } from '@/utils/converter'
import { isLocalEngine } from '@/utils/modelEngine'
import { installedEnginesAtom } from '@/helpers/atoms/Engines.atom'
import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'
const TableActiveModel = () => {
const { activeModel, stateModel, stopModel } = useActiveModel()
const engines = useAtomValue(installedEnginesAtom)
const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom)
return (
<div className="w-1/2">
<div className="overflow-hidden border-b border-[hsla(var(--app-border))]">
<table className="w-full px-8">
{activeModel &&
engines &&
isLocalEngine(engines, activeModel.engine) ? (
<tbody>
<tr>
<td
className="max-w-[200px] px-4 py-2 font-medium"
title={activeModel.name}
>
<p className="line-clamp-2">{activeModel.name}</p>
</td>
<td className="px-4 py-2">
<Badge theme="secondary">
{activeModel.metadata?.size
? toGibibytes(activeModel.metadata?.size)
: '-'}
</Badge>
</td>
<td className="px-4 py-2 text-right">
<Tooltip
trigger={
<Button
theme={
stateModel.state === 'stop'
? 'destructive'
: 'primary'
}
onClick={() => {
stopModel()
window.core?.api?.stopServer()
setServerEnabled(false)
}}
>
Stop
</Button>
}
content="The API server is running, stop the model will
also stop the server"
disabled={!serverEnabled}
/>
</td>
</tr>
</tbody>
) : (
<tbody>
<tr className="text-[hsla(var(--text-secondary))]">
<td className="p-4">No models are loaded into memory</td>
</tr>
</tbody>
)}
</table>
</div>
</div>
)
}
export default TableActiveModel