jan/web/hooks/useGetConfiguredModels.ts
Louis 96dba2690d feat: class-based plugin manager
chore: add facades

refactor: core module export

refactor: inference plugin - deprecate function registering (#537)

* refactor: revamp inference plugin as class - deprecate function registering

* refactor: monitoring plugin - deprecate service registering (#538)

refactor: revamp inference plugin as class - deprecate function registering

chore: update import

refactor: plugin revamp - model management

chore: update build steps and remove experimental plugins

refactor: remove pluggable electron

chore: add sorting for conversations

chore: build plugins for testing

chore: consistent plugin directory name

chore: docs

chore: fix CI

chore: update conversation prefix
2023-11-06 13:46:01 +07:00

37 lines
1.0 KiB
TypeScript

import { useEffect, useState } from 'react'
import { ModelCatalog } from '@janhq/core/lib/types'
import { pluginManager } from '@plugin/PluginManager'
import { ModelPlugin } from '@janhq/core/lib/plugins'
import { PluginType } from '@janhq/core'
import { dummyModel } from '@utils/dummy'
export default function useGetConfiguredModels() {
const [loading, setLoading] = useState<boolean>(false)
const [models, setModels] = useState<ModelCatalog[]>([])
async function getConfiguredModels(): Promise<ModelCatalog[]> {
return (
((await pluginManager
.get<ModelPlugin>(PluginType.Model)
?.getConfiguredModels()) as ModelCatalog[]) ?? []
)
}
const fetchModels = async () => {
setLoading(true)
let models = await getConfiguredModels()
if (process.env.NODE_ENV === 'development') {
models = [dummyModel, ...models]
}
setLoading(false)
setModels(models)
}
// TODO allow user for filter
useEffect(() => {
fetchModels()
}, [])
return { loading, models }
}