Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove filter on recommend model #4156

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions web/hooks/useRecommendedModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
const downloadedModels = useAtomValue(downloadedModelsAtom)

const getAndSortDownloadedModels = useCallback(async (): Promise<Model[]> => {
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
)
const models = downloadedModels.sort((a, b) =>
a.engine !== InferenceEngine.cortex_llamacpp &&

Check warning on line 34 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

34 line is not covered with tests
b.engine === InferenceEngine.cortex_llamacpp
? 1
: -1
)
setSortedModels(models)
return models
}, [downloadedModels])
Expand All @@ -48,40 +46,40 @@
const models = await getAndSortDownloadedModels()

if (!activeThread) return
const modelId = activeThread.assistants[0]?.model.id
const model = models.find((model) => model.id === modelId)

Check warning on line 50 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

49-50 lines are not covered with tests

if (model) {
setRecommendedModel(model)

Check warning on line 53 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

52-53 lines are not covered with tests
}

if (activeModel) {

Check warning on line 56 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

56 line is not covered with tests
// if we have active model alr, then we can just use that
console.debug(`Using active model ${activeModel.id}`)
setRecommendedModel(activeModel)
return

Check warning on line 60 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

58-60 lines are not covered with tests
}

// sort the model, for display purpose

if (models.length === 0) {

Check warning on line 65 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

65 line is not covered with tests
// if we have no downloaded models, then can't recommend anything
console.debug("No downloaded models, can't recommend anything")
return

Check warning on line 68 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

67-68 lines are not covered with tests
}

// otherwise, get the last used model id
const lastUsedModelId = localStorage.getItem(LAST_USED_MODEL_ID)

Check warning on line 72 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

72 line is not covered with tests

// if we don't have [lastUsedModelId], then we can just use the first model
// in the downloaded list
if (!lastUsedModelId) {
setRecommendedModel(models[0])
return

Check warning on line 78 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

76-78 lines are not covered with tests
}

const lastUsedModel = models.find((model) => model.id === lastUsedModelId)
if (!lastUsedModel) {

Check warning on line 82 in web/hooks/useRecommendedModel.ts

View workflow job for this annotation

GitHub Actions / coverage-check

81-82 lines are not covered with tests
// if we can't find the last used model, then we can just use the first model
// in the downloaded list
console.debug(
Expand Down
8 changes: 6 additions & 2 deletions web/screens/Thread/ThreadLeftPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useState } from 'react'

import { Thread } from '@janhq/core'
import { InferenceEngine, Thread } from '@janhq/core'

import { Button } from '@janhq/joi'
import { useAtomValue, useSetAtom } from 'jotai'
Expand Down Expand Up @@ -71,7 +71,11 @@ const ThreadLeftPanel = () => {
threads.length === 0 &&
downloadedModels.length > 0
) {
requestCreateNewThread(assistants[0], recommendedModel)
const model = downloadedModels.filter(
(model) => model.engine === InferenceEngine.cortex_llamacpp
)
const selectedModel = model[0] || recommendedModel
requestCreateNewThread(assistants[0], selectedModel)
} else if (threadDataReady && !activeThreadId) {
setActiveThread(threads[0])
}
Expand Down
Loading