Fix: 'Web Search' and 'Clear Context' don't work (#5677)

This commit is contained in:
chenxi 2025-05-05 21:04:18 +08:00 committed by GitHub
parent 197016f0db
commit bb5c6a8bb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -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)

View File

@ -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')