fix: thread title does not set on remote models

This commit is contained in:
Louis 2025-04-20 15:48:58 +07:00
parent eda0d639f0
commit 92d7e33b7e
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -16,24 +16,18 @@ import {
EngineManager, EngineManager,
InferenceEngine, InferenceEngine,
extractInferenceParams, extractInferenceParams,
ModelExtension,
} from '@janhq/core' } from '@janhq/core'
import { useAtom, useAtomValue, useSetAtom } from 'jotai' import { useAtom, useAtomValue, useSetAtom } from 'jotai'
import { ulid } from 'ulidx' import { ulid } from 'ulidx'
import { activeModelAtom, stateModelAtom } from '@/hooks/useActiveModel' import { activeModelAtom, stateModelAtom } from '@/hooks/useActiveModel'
import { useGetEngines } from '@/hooks/useEngineManagement'
import { isLocalEngine } from '@/utils/modelEngine'
import { extensionManager } from '@/extension' import { extensionManager } from '@/extension'
import { import {
getCurrentChatMessagesAtom, getCurrentChatMessagesAtom,
addNewMessageAtom, addNewMessageAtom,
updateMessageAtom, updateMessageAtom,
tokenSpeedAtom, tokenSpeedAtom,
deleteMessageAtom,
subscribedGeneratingMessageAtom, subscribedGeneratingMessageAtom,
} from '@/helpers/atoms/ChatMessage.atom' } from '@/helpers/atoms/ChatMessage.atom'
import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom' import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom'
@ -54,7 +48,6 @@ export default function ModelHandler() {
const addNewMessage = useSetAtom(addNewMessageAtom) const addNewMessage = useSetAtom(addNewMessageAtom)
const updateMessage = useSetAtom(updateMessageAtom) const updateMessage = useSetAtom(updateMessageAtom)
const downloadedModels = useAtomValue(downloadedModelsAtom) const downloadedModels = useAtomValue(downloadedModelsAtom)
const deleteMessage = useSetAtom(deleteMessageAtom)
const activeModel = useAtomValue(activeModelAtom) const activeModel = useAtomValue(activeModelAtom)
const setActiveModel = useSetAtom(activeModelAtom) const setActiveModel = useSetAtom(activeModelAtom)
const setStateModel = useSetAtom(stateModelAtom) const setStateModel = useSetAtom(stateModelAtom)
@ -77,7 +70,6 @@ export default function ModelHandler() {
const activeModelParamsRef = useRef(activeModelParams) const activeModelParamsRef = useRef(activeModelParams)
const [tokenSpeed, setTokenSpeed] = useAtom(tokenSpeedAtom) const [tokenSpeed, setTokenSpeed] = useAtom(tokenSpeedAtom)
const { engines } = useGetEngines()
const tokenSpeedRef = useRef(tokenSpeed) const tokenSpeedRef = useRef(tokenSpeed)
useEffect(() => { useEffect(() => {
@ -292,16 +284,14 @@ export default function ModelHandler() {
const generateThreadTitle = (message: ThreadMessage, thread: Thread) => { const generateThreadTitle = (message: ThreadMessage, thread: Thread) => {
// If this is the first ever prompt in the thread // If this is the first ever prompt in the thread
if ( if ((thread.title ?? thread.metadata?.title)?.trim() !== defaultThreadTitle)
!activeModelRef.current ||
(thread.title ?? thread.metadata?.title)?.trim() !== defaultThreadTitle
)
return return
// Check model engine; we don't want to generate a title when it's not a local engine. remote model using first promp // Check model engine; we don't want to generate a title when it's not a local engine. remote model using first promp
if ( if (
activeModelRef.current?.engine !== InferenceEngine.cortex && !activeModelRef.current ||
activeModelRef.current?.engine !== InferenceEngine.cortex_llamacpp (activeModelRef.current?.engine !== InferenceEngine.cortex &&
activeModelRef.current?.engine !== InferenceEngine.cortex_llamacpp)
) { ) {
const updatedThread: Thread = { const updatedThread: Thread = {
...thread, ...thread,