fix: default local model from starter screen (#4151)

* fix: default local model starter screen

* chore: update logic recommend model

* chore: cleanup import
This commit is contained in:
Faisal Amir 2024-11-28 13:49:20 +07:00 committed by GitHub
parent cd1a2746ce
commit 7bd59f0c84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 8 deletions

View File

@ -30,11 +30,14 @@ export default function useRecommendedModel() {
const downloadedModels = useAtomValue(downloadedModelsAtom)
const getAndSortDownloadedModels = useCallback(async (): Promise<Model[]> => {
const models = downloadedModels.sort((a, b) =>
a.engine !== InferenceEngine.nitro && b.engine === InferenceEngine.nitro
? 1
: -1
)
const models = downloadedModels
.filter((model) => model.engine === InferenceEngine.cortex_llamacpp)
.sort((a, b) =>
a.engine !== InferenceEngine.cortex_llamacpp &&
b.engine === InferenceEngine.cortex_llamacpp
? 1
: -1
)
setSortedModels(models)
return models
}, [downloadedModels])
@ -43,6 +46,7 @@ export default function useRecommendedModel() {
Model | undefined
> => {
const models = await getAndSortDownloadedModels()
if (!activeThread) return
const modelId = activeThread.assistants[0]?.model.id
const model = models.find((model) => model.id === modelId)

View File

@ -63,15 +63,15 @@ const ThreadLeftPanel = () => {
* This will create a new thread if there are assistants available
* and there are no threads available
*/
useEffect(() => {
if (
threadDataReady &&
assistants.length > 0 &&
threads.length === 0 &&
(downloadedModels[0] || recommendedModel)
downloadedModels.length > 0
) {
const model = downloadedModels[0] || recommendedModel
requestCreateNewThread(assistants[0], model)
requestCreateNewThread(assistants[0], recommendedModel)
} else if (threadDataReady && !activeThreadId) {
setActiveThread(threads[0])
}