mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 16:49:07 +08:00
fix: do not reset citation block (#9383)
* fix: do not reset citation block id * refactor: disable external websearch for mandatory websearch models * refactor: predicate * refactor: include openrouter perplexity
This commit is contained in:
parent
1c0e29f029
commit
4191d878f2
@ -3004,6 +3004,21 @@ export function isWebSearchModel(model: Model): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
export function isMandatoryWebSearchModel(model: Model): boolean {
|
||||
if (!model) {
|
||||
return false
|
||||
}
|
||||
|
||||
const provider = getProviderByModel(model)
|
||||
const modelId = getLowerBaseModelName(model.id)
|
||||
|
||||
if (provider.id === 'perplexity' || provider.id === 'openrouter') {
|
||||
return PERPLEXITY_SEARCH_MODELS.includes(modelId)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export function isOpenRouterBuiltInWebSearchModel(model: Model): boolean {
|
||||
if (!model) {
|
||||
return false
|
||||
|
||||
@ -5,6 +5,7 @@ import TranslateButton from '@renderer/components/TranslateButton'
|
||||
import {
|
||||
isGenerateImageModel,
|
||||
isGenerateImageModels,
|
||||
isMandatoryWebSearchModel,
|
||||
isSupportedDisableGenerationModel,
|
||||
isSupportedReasoningEffortModel,
|
||||
isSupportedThinkingTokenModel,
|
||||
@ -767,7 +768,10 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
if (!isWebSearchModel(model) && assistant.enableWebSearch) {
|
||||
updateAssistant({ ...assistant, enableWebSearch: false })
|
||||
}
|
||||
if (assistant.webSearchProviderId && !WebSearchService.isWebSearchEnabled(assistant.webSearchProviderId)) {
|
||||
if (
|
||||
assistant.webSearchProviderId &&
|
||||
(!WebSearchService.isWebSearchEnabled(assistant.webSearchProviderId) || isMandatoryWebSearchModel(model))
|
||||
) {
|
||||
updateAssistant({ ...assistant, webSearchProviderId: undefined })
|
||||
}
|
||||
if (!isGenerateImageModel(model) && assistant.enableGenerateImage) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { DragDropContext, Draggable, Droppable, DropResult } from '@hello-pangea/dnd'
|
||||
import { QuickPanelListItem } from '@renderer/components/QuickPanel'
|
||||
import { isGenerateImageModel } from '@renderer/config/models'
|
||||
import { isGenerateImageModel, isMandatoryWebSearchModel } from '@renderer/config/models'
|
||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||
import { setIsCollapsed, setToolOrder } from '@renderer/store/inputTools'
|
||||
import { Assistant, FileType, KnowledgeBase, Model } from '@renderer/types'
|
||||
@ -340,7 +340,8 @@ const InputbarTools = ({
|
||||
{
|
||||
key: 'web_search',
|
||||
label: t('chat.input.web_search.label'),
|
||||
component: <WebSearchButton ref={webSearchButtonRef} assistant={assistant} ToolbarButton={ToolbarButton} />
|
||||
component: <WebSearchButton ref={webSearchButtonRef} assistant={assistant} ToolbarButton={ToolbarButton} />,
|
||||
condition: !isMandatoryWebSearchModel(model)
|
||||
},
|
||||
{
|
||||
key: 'url_context',
|
||||
|
||||
@ -120,9 +120,6 @@ export const createCitationCallbacks = (deps: CitationCallbacksDependencies) =>
|
||||
},
|
||||
|
||||
// 暴露给外部的方法,用于textCallbacks中获取citationBlockId
|
||||
getCitationBlockId: () => citationBlockId,
|
||||
setCitationBlockId: (id: string | null) => {
|
||||
citationBlockId = id
|
||||
}
|
||||
getCitationBlockId: () => citationBlockId
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,8 +59,7 @@ export const createCallbacks = (deps: CallbacksDependencies) => {
|
||||
blockManager,
|
||||
getState,
|
||||
assistantMsgId,
|
||||
getCitationBlockId: citationCallbacks.getCitationBlockId,
|
||||
setCitationBlockId: citationCallbacks.setCitationBlockId
|
||||
getCitationBlockId: citationCallbacks.getCitationBlockId
|
||||
})
|
||||
|
||||
// 组合所有回调
|
||||
|
||||
@ -12,11 +12,10 @@ interface TextCallbacksDependencies {
|
||||
getState: any
|
||||
assistantMsgId: string
|
||||
getCitationBlockId: () => string | null
|
||||
setCitationBlockId: (id: string | null) => void
|
||||
}
|
||||
|
||||
export const createTextCallbacks = (deps: TextCallbacksDependencies) => {
|
||||
const { blockManager, getState, assistantMsgId, getCitationBlockId, setCitationBlockId } = deps
|
||||
const { blockManager, getState, assistantMsgId, getCitationBlockId } = deps
|
||||
|
||||
// 内部维护的状态
|
||||
let mainTextBlockId: string | null = null
|
||||
@ -63,7 +62,6 @@ export const createTextCallbacks = (deps: TextCallbacksDependencies) => {
|
||||
}
|
||||
blockManager.smartBlockUpdate(mainTextBlockId, changes, MessageBlockType.MAIN_TEXT, true)
|
||||
mainTextBlockId = null
|
||||
setCitationBlockId(null)
|
||||
} else {
|
||||
logger.warn(
|
||||
`[onTextComplete] Received text.complete but last block was not MAIN_TEXT (was ${blockManager.lastBlockType}) or lastBlockId is null.`
|
||||
|
||||
Loading…
Reference in New Issue
Block a user