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

enhancement: set recommend model to undefined if no model available #4296

Merged
merged 2 commits into from
Dec 19, 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
5 changes: 4 additions & 1 deletion web/hooks/useCreateNewThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import { useActiveModel } from './useActiveModel'

import useRecommendedModel from './useRecommendedModel'
import useSetActiveThread from './useSetActiveThread'

import { extensionManager } from '@/extension'
Expand All @@ -40,19 +41,19 @@

const createNewThreadAtom = atom(null, (get, set, newThread: Thread) => {
// create thread state for this new thread
const currentState = { ...get(threadStatesAtom) }

Check warning on line 44 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

44 line is not covered with tests

const threadState: ThreadState = {

Check warning on line 46 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

46 line is not covered with tests
hasMore: false,
waitingForResponse: false,
lastMessage: undefined,
}
currentState[newThread.id] = threadState
set(threadStatesAtom, currentState)

Check warning on line 52 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

51-52 lines are not covered with tests

// add the new thread on top of the thread list to the state
const threads = get(threadsAtom)
set(threadsAtom, [newThread, ...threads])

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

View workflow job for this annotation

GitHub Actions / coverage-check

55-56 lines are not covered with tests
})

export const useCreateNewThread = () => {
Expand All @@ -73,6 +74,8 @@
const threads = useAtomValue(threadsAtom)
const { stopInference } = useActiveModel()

const { recommendedModel } = useRecommendedModel()

const requestCreateNewThread = async (
assistant: (ThreadAssistantInfo & { id: string; name: string }) | Assistant,
model?: Model | undefined
Expand All @@ -81,7 +84,7 @@
setIsGeneratingResponse(false)
stopInference()

const defaultModel = model
const defaultModel = model || recommendedModel

if (!model) {
// if we have model, which means user wants to create new thread from Model hub. Allow them.
Expand Down Expand Up @@ -157,19 +160,19 @@
//TODO: Why do we have thread list then thread states? Should combine them
try {
const createdThread = await persistNewThread(thread, assistantInfo)
if (!createdThread) throw 'Thread created failed.'
createNewThread(createdThread)

Check warning on line 164 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

163-164 lines are not covered with tests

setSelectedModel(defaultModel)
setThreadModelParams(createdThread.id, {

Check warning on line 167 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

166-167 lines are not covered with tests
...defaultModel?.settings,
...defaultModel?.parameters,
...overriddenSettings,
})

// Delete the file upload state
setFileUpload(undefined)
setActiveThread(createdThread)

Check warning on line 175 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

174-175 lines are not covered with tests
} catch (ex) {
return toaster({
title: 'Thread created failed.',
Expand All @@ -180,7 +183,7 @@
}

const updateThreadExtension = (thread: Thread) => {
return extensionManager

Check warning on line 186 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

186 line is not covered with tests
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.modifyThread(thread)
}
Expand All @@ -189,7 +192,7 @@
threadId: string,
assistant: ThreadAssistantInfo
) => {
return extensionManager

Check warning on line 195 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

195 line is not covered with tests
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.modifyThreadAssistant(threadId, assistant)
}
Expand Down Expand Up @@ -224,7 +227,7 @@
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.createThread(thread)
.then(async (thread) => {
await extensionManager

Check warning on line 230 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

230 line is not covered with tests
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.createThreadAssistant(thread.id, assistantInfo)
return thread
Expand Down
1 change: 1 addition & 0 deletions web/hooks/useRecommendedModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function useRecommendedModel() {
if (models.length === 0) {
// if we have no downloaded models, then can't recommend anything
console.debug("No downloaded models, can't recommend anything")
setRecommendedModel(undefined)
return
}

Expand Down
5 changes: 2 additions & 3 deletions web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ const ChatInput = () => {
</Button>
}
disabled={
!isModelSupportRagAndTools &&
activeAssistant?.tools &&
activeAssistant?.tools[0]?.enabled
!isModelSupportRagAndTools ||
(activeAssistant?.tools && activeAssistant?.tools[0]?.enabled)
}
content={
<>
Expand Down
Loading