mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
Fix: 'Web Search' and 'Clear Context' don't work (#5677)
This commit is contained in:
parent
197016f0db
commit
bb5c6a8bb9
@ -43,9 +43,14 @@ export function useAssistant(id: string) {
|
|||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const { defaultModel } = useDefaultModel()
|
const { defaultModel } = useDefaultModel()
|
||||||
|
|
||||||
|
const model = assistant?.model ?? assistant?.defaultModel ?? defaultModel
|
||||||
|
if (!model) {
|
||||||
|
throw new Error(`Assistant model is not set for assistant with name: ${assistant?.name ?? 'unknown'}`)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
assistant,
|
assistant: { ...assistant, model },
|
||||||
model: assistant?.model ?? assistant?.defaultModel ?? defaultModel,
|
model,
|
||||||
addTopic: (topic: Topic) => dispatch(addTopic({ assistantId: assistant.id, topic })),
|
addTopic: (topic: Topic) => dispatch(addTopic({ assistantId: assistant.id, topic })),
|
||||||
removeTopic: (topic: Topic) => {
|
removeTopic: (topic: Topic) => {
|
||||||
TopicManager.removeTopic(topic.id)
|
TopicManager.removeTopic(topic.id)
|
||||||
|
|||||||
@ -247,6 +247,9 @@ export async function fetchChatCompletion({
|
|||||||
console.log('[DEBUG] Got assistant provider:', provider.id)
|
console.log('[DEBUG] Got assistant provider:', provider.id)
|
||||||
const AI = new AiProvider(provider)
|
const AI = new AiProvider(provider)
|
||||||
|
|
||||||
|
// Make sure that 'Clear Context' works for all scenarios including external tool and normal chat.
|
||||||
|
messages = filterContextMessages(messages)
|
||||||
|
|
||||||
const lastUserMessage = findLast(messages, (m) => m.role === 'user')
|
const lastUserMessage = findLast(messages, (m) => m.role === 'user')
|
||||||
const lastAnswer = findLast(messages, (m) => m.role === 'assistant')
|
const lastAnswer = findLast(messages, (m) => m.role === 'assistant')
|
||||||
if (!lastUserMessage) {
|
if (!lastUserMessage) {
|
||||||
@ -258,7 +261,7 @@ export async function fetchChatCompletion({
|
|||||||
// They will be retrieved and used by the messageThunk later to create CitationBlocks.
|
// They will be retrieved and used by the messageThunk later to create CitationBlocks.
|
||||||
const { mcpTools } = await fetchExternalTool(lastUserMessage, assistant, onChunkReceived, lastAnswer)
|
const { mcpTools } = await fetchExternalTool(lastUserMessage, assistant, onChunkReceived, lastAnswer)
|
||||||
|
|
||||||
const filteredMessages = filterUsefulMessages(filterContextMessages(messages))
|
const filteredMessages = filterUsefulMessages(messages)
|
||||||
|
|
||||||
// --- Call AI Completions ---
|
// --- Call AI Completions ---
|
||||||
console.log('[DEBUG] Calling AI.completions')
|
console.log('[DEBUG] Calling AI.completions')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user