mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 22:39:36 +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
|
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 {
|
export function isOpenRouterBuiltInWebSearchModel(model: Model): boolean {
|
||||||
if (!model) {
|
if (!model) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import TranslateButton from '@renderer/components/TranslateButton'
|
|||||||
import {
|
import {
|
||||||
isGenerateImageModel,
|
isGenerateImageModel,
|
||||||
isGenerateImageModels,
|
isGenerateImageModels,
|
||||||
|
isMandatoryWebSearchModel,
|
||||||
isSupportedDisableGenerationModel,
|
isSupportedDisableGenerationModel,
|
||||||
isSupportedReasoningEffortModel,
|
isSupportedReasoningEffortModel,
|
||||||
isSupportedThinkingTokenModel,
|
isSupportedThinkingTokenModel,
|
||||||
@ -767,7 +768,10 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
|||||||
if (!isWebSearchModel(model) && assistant.enableWebSearch) {
|
if (!isWebSearchModel(model) && assistant.enableWebSearch) {
|
||||||
updateAssistant({ ...assistant, enableWebSearch: false })
|
updateAssistant({ ...assistant, enableWebSearch: false })
|
||||||
}
|
}
|
||||||
if (assistant.webSearchProviderId && !WebSearchService.isWebSearchEnabled(assistant.webSearchProviderId)) {
|
if (
|
||||||
|
assistant.webSearchProviderId &&
|
||||||
|
(!WebSearchService.isWebSearchEnabled(assistant.webSearchProviderId) || isMandatoryWebSearchModel(model))
|
||||||
|
) {
|
||||||
updateAssistant({ ...assistant, webSearchProviderId: undefined })
|
updateAssistant({ ...assistant, webSearchProviderId: undefined })
|
||||||
}
|
}
|
||||||
if (!isGenerateImageModel(model) && assistant.enableGenerateImage) {
|
if (!isGenerateImageModel(model) && assistant.enableGenerateImage) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { DragDropContext, Draggable, Droppable, DropResult } from '@hello-pangea/dnd'
|
import { DragDropContext, Draggable, Droppable, DropResult } from '@hello-pangea/dnd'
|
||||||
import { QuickPanelListItem } from '@renderer/components/QuickPanel'
|
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 { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||||
import { setIsCollapsed, setToolOrder } from '@renderer/store/inputTools'
|
import { setIsCollapsed, setToolOrder } from '@renderer/store/inputTools'
|
||||||
import { Assistant, FileType, KnowledgeBase, Model } from '@renderer/types'
|
import { Assistant, FileType, KnowledgeBase, Model } from '@renderer/types'
|
||||||
@ -340,7 +340,8 @@ const InputbarTools = ({
|
|||||||
{
|
{
|
||||||
key: 'web_search',
|
key: 'web_search',
|
||||||
label: t('chat.input.web_search.label'),
|
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',
|
key: 'url_context',
|
||||||
|
|||||||
@ -120,9 +120,6 @@ export const createCitationCallbacks = (deps: CitationCallbacksDependencies) =>
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 暴露给外部的方法,用于textCallbacks中获取citationBlockId
|
// 暴露给外部的方法,用于textCallbacks中获取citationBlockId
|
||||||
getCitationBlockId: () => citationBlockId,
|
getCitationBlockId: () => citationBlockId
|
||||||
setCitationBlockId: (id: string | null) => {
|
|
||||||
citationBlockId = id
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,8 +59,7 @@ export const createCallbacks = (deps: CallbacksDependencies) => {
|
|||||||
blockManager,
|
blockManager,
|
||||||
getState,
|
getState,
|
||||||
assistantMsgId,
|
assistantMsgId,
|
||||||
getCitationBlockId: citationCallbacks.getCitationBlockId,
|
getCitationBlockId: citationCallbacks.getCitationBlockId
|
||||||
setCitationBlockId: citationCallbacks.setCitationBlockId
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 组合所有回调
|
// 组合所有回调
|
||||||
|
|||||||
@ -12,11 +12,10 @@ interface TextCallbacksDependencies {
|
|||||||
getState: any
|
getState: any
|
||||||
assistantMsgId: string
|
assistantMsgId: string
|
||||||
getCitationBlockId: () => string | null
|
getCitationBlockId: () => string | null
|
||||||
setCitationBlockId: (id: string | null) => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createTextCallbacks = (deps: TextCallbacksDependencies) => {
|
export const createTextCallbacks = (deps: TextCallbacksDependencies) => {
|
||||||
const { blockManager, getState, assistantMsgId, getCitationBlockId, setCitationBlockId } = deps
|
const { blockManager, getState, assistantMsgId, getCitationBlockId } = deps
|
||||||
|
|
||||||
// 内部维护的状态
|
// 内部维护的状态
|
||||||
let mainTextBlockId: string | null = null
|
let mainTextBlockId: string | null = null
|
||||||
@ -63,7 +62,6 @@ export const createTextCallbacks = (deps: TextCallbacksDependencies) => {
|
|||||||
}
|
}
|
||||||
blockManager.smartBlockUpdate(mainTextBlockId, changes, MessageBlockType.MAIN_TEXT, true)
|
blockManager.smartBlockUpdate(mainTextBlockId, changes, MessageBlockType.MAIN_TEXT, true)
|
||||||
mainTextBlockId = null
|
mainTextBlockId = null
|
||||||
setCitationBlockId(null)
|
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`[onTextComplete] Received text.complete but last block was not MAIN_TEXT (was ${blockManager.lastBlockType}) or lastBlockId is null.`
|
`[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