fix: model should not include file attachment tools if not supported (#6833)

This commit is contained in:
Dinh Long Nguyen 2025-10-28 16:58:18 +07:00 committed by GitHub
parent c854c54c0c
commit 62bd91a1e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,6 +26,8 @@ import {
ConfigOptions, ConfigOptions,
} from 'token.js' } from 'token.js'
import { getModelCapabilities } from '@/lib/models'
// Extended config options to include custom fetch function // Extended config options to include custom fetch function
type ExtendedConfigOptions = ConfigOptions & { type ExtendedConfigOptions = ConfigOptions & {
fetch?: typeof fetch fetch?: typeof fetch
@ -38,6 +40,7 @@ import { ExtensionManager } from './extension'
import { useAppState } from '@/hooks/useAppState' import { useAppState } from '@/hooks/useAppState'
import { injectFilesIntoPrompt } from './fileMetadata' import { injectFilesIntoPrompt } from './fileMetadata'
import { Attachment } from '@/types/attachment' import { Attachment } from '@/types/attachment'
import { ModelCapabilities } from '@/types/models'
export type ChatCompletionResponse = export type ChatCompletionResponse =
| chatCompletion | chatCompletion
@ -232,10 +235,25 @@ export const sendCompletion = async (
} }
// Inject RAG tools on-demand (not in global tools list) // Inject RAG tools on-demand (not in global tools list)
const providerModelConfig = provider.models?.find(
(model) => model.id === thread.model?.id || model.model === thread.model?.id
)
const effectiveCapabilities = Array.isArray(
providerModelConfig?.capabilities
)
? providerModelConfig?.capabilities ?? []
: getModelCapabilities(provider.provider, thread.model.id)
const modelSupportsTools = effectiveCapabilities.includes(
ModelCapabilities.TOOLS
)
let usableTools = tools let usableTools = tools
try { try {
const attachmentsEnabled = useAttachments.getState().enabled const attachmentsEnabled = useAttachments.getState().enabled
if (attachmentsEnabled && PlatformFeatures[PlatformFeature.ATTACHMENTS]) { if (
attachmentsEnabled &&
PlatformFeatures[PlatformFeature.ATTACHMENTS] &&
modelSupportsTools
) {
const ragTools = await getServiceHub().rag().getTools().catch(() => []) const ragTools = await getServiceHub().rag().getTools().catch(() => [])
if (Array.isArray(ragTools) && ragTools.length) { if (Array.isArray(ragTools) && ragTools.length) {
usableTools = [...tools, ...ragTools] usableTools = [...tools, ...ragTools]