mirror of
https://github.com/langgenius/dify.git
synced 2026-06-26 14:51:13 +08:00
chore: file upload from config in debug
This commit is contained in:
parent
e2860d79de
commit
1fdc62087a
@ -2,8 +2,10 @@ import type { ComponentProps } from 'react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { createStore, Provider as JotaiProvider } from 'jotai'
|
||||
import { SupportUploadFileTypes } from '@/app/components/workflow/types'
|
||||
import { agentComposerModelAtom } from '@/features/agent-v2/agent-composer/store-modules/model'
|
||||
import { agentComposerPromptAtom } from '@/features/agent-v2/agent-composer/store-modules/prompt'
|
||||
import { TransferMethod } from '@/types/app'
|
||||
import { AgentChatRuntime } from '../chat-runtime'
|
||||
|
||||
const useChatMock = vi.hoisted(() => vi.fn())
|
||||
@ -267,4 +269,43 @@ describe('AgentPreviewChat', () => {
|
||||
await waitFor(() => expect(saveDraftBeforeRun).toHaveBeenCalledTimes(1))
|
||||
expect(handleSendMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should keep preview file upload disabled by default', async () => {
|
||||
renderPreviewChat()
|
||||
|
||||
await waitFor(() => expect(useChatMock).toHaveBeenCalled())
|
||||
|
||||
const config = useChatMock.mock.calls.at(-1)?.[0]
|
||||
expect(config.file_upload).toEqual(expect.objectContaining({
|
||||
enabled: false,
|
||||
allowed_file_upload_methods: [TransferMethod.local_file, TransferMethod.remote_url],
|
||||
}))
|
||||
})
|
||||
|
||||
it('should enable build chat file upload when chat features file upload is enabled', async () => {
|
||||
renderPreviewChat({
|
||||
agentSoulConfig: {
|
||||
app_features: {
|
||||
file_upload: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await waitFor(() => expect(useChatMock).toHaveBeenCalled())
|
||||
|
||||
const config = useChatMock.mock.calls.at(-1)?.[0]
|
||||
expect(config.file_upload).toEqual(expect.objectContaining({
|
||||
enabled: true,
|
||||
allowed_file_types: [SupportUploadFileTypes.image],
|
||||
allowed_file_upload_methods: [TransferMethod.local_file, TransferMethod.remote_url],
|
||||
number_limits: 3,
|
||||
}))
|
||||
expect(config.file_upload.image).toEqual(expect.objectContaining({
|
||||
enabled: true,
|
||||
transfer_methods: [TransferMethod.local_file, TransferMethod.remote_url],
|
||||
number_limits: 3,
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
@ -13,6 +13,7 @@ import type {
|
||||
} from 'react'
|
||||
import type { FeedbackType, IChatItem, ThoughtItem } from '@/app/components/base/chat/chat/type'
|
||||
import type { ChatConfig, ChatItem, ChatItemInTree, OnSend } from '@/app/components/base/chat/types'
|
||||
import type { FileUpload } from '@/app/components/base/features/types'
|
||||
import type { FileEntity } from '@/app/components/base/file-uploader/types'
|
||||
import type { DefaultModel } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import type { Inputs } from '@/models/debug'
|
||||
@ -31,7 +32,7 @@ import Loading from '@/app/components/base/loading'
|
||||
import { ModelFeatureEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import { useTextGenerationCurrentProviderAndModelAndModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||
import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils'
|
||||
import { InputVarType } from '@/app/components/workflow/types'
|
||||
import { InputVarType, SupportUploadFileTypes } from '@/app/components/workflow/types'
|
||||
import { DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
import { agentComposerModelAtom } from '@/features/agent-v2/agent-composer/store-modules/model'
|
||||
@ -70,6 +71,7 @@ const defaultSystemParameters: ChatConfig['system_parameters'] = {
|
||||
}
|
||||
|
||||
const disabledFileUploadConfig = {
|
||||
enabled: false,
|
||||
allowed_file_upload_methods: [TransferMethod.local_file, TransferMethod.remote_url],
|
||||
allowed_file_types: [],
|
||||
fileUploadConfig: defaultSystemParameters,
|
||||
@ -86,6 +88,39 @@ const disabledFileUploadConfig = {
|
||||
fileUploadConfig: ChatConfig['system_parameters']
|
||||
}
|
||||
|
||||
const defaultFileUploadMethods = [TransferMethod.local_file, TransferMethod.remote_url]
|
||||
|
||||
const toPreviewFileUploadConfig = (fileUpload: FileUpload | undefined) => {
|
||||
if (!fileUpload?.enabled)
|
||||
return disabledFileUploadConfig
|
||||
|
||||
const allowedFileUploadMethods = fileUpload.allowed_file_upload_methods?.length
|
||||
? fileUpload.allowed_file_upload_methods
|
||||
: defaultFileUploadMethods
|
||||
const numberLimits = fileUpload.number_limits ?? fileUpload.image?.number_limits ?? 3
|
||||
|
||||
return {
|
||||
...disabledFileUploadConfig,
|
||||
...fileUpload,
|
||||
enabled: true,
|
||||
allowed_file_types: fileUpload.allowed_file_types?.length
|
||||
? fileUpload.allowed_file_types
|
||||
: [SupportUploadFileTypes.image],
|
||||
allowed_file_upload_methods: allowedFileUploadMethods,
|
||||
number_limits: numberLimits,
|
||||
fileUploadConfig: fileUpload.fileUploadConfig ?? defaultSystemParameters,
|
||||
image: {
|
||||
...disabledFileUploadConfig.image,
|
||||
...fileUpload.image,
|
||||
enabled: fileUpload.image?.enabled ?? true,
|
||||
transfer_methods: fileUpload.image?.transfer_methods?.length
|
||||
? fileUpload.image.transfer_methods
|
||||
: allowedFileUploadMethods,
|
||||
number_limits: numberLimits,
|
||||
},
|
||||
} as ChatConfig['file_upload']
|
||||
}
|
||||
|
||||
const getModelSettings = (agentSoulConfig?: AgentSoulConfig) => agentSoulConfig?.model?.model_settings ?? {}
|
||||
|
||||
const toEnabledConfig = (config?: { enabled?: boolean } | null) => ({
|
||||
@ -385,7 +420,7 @@ const buildChatConfig = ({
|
||||
},
|
||||
},
|
||||
dataset_configs: toLegacyPreviewDatasetConfigs(agentSoulConfig?.knowledge),
|
||||
file_upload: disabledFileUploadConfig,
|
||||
file_upload: toPreviewFileUploadConfig(appFeatures.file_upload as FileUpload | undefined),
|
||||
system_parameters: defaultSystemParameters,
|
||||
supportCitationHitInfo: true,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user