fix: model should not include file attachment tools if not supported (#6833)
This commit is contained in:
parent
c854c54c0c
commit
62bd91a1e1
@ -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]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user