diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/annotations/page.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/annotations/page.tsx index 314b481699..0af2e945f3 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/annotations/page.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/annotations/page.tsx @@ -1,6 +1,6 @@ import React from 'react' import Main from '@/app/components/app/log-annotation' -import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type' +import { PageType } from '@/app/components/base/features/new-feature-panel/annotation-reply/type' export type IProps = { params: { appId: string } diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/logs/page.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/logs/page.tsx index 47ba846be1..244a357616 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/logs/page.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/logs/page.tsx @@ -1,6 +1,6 @@ import React from 'react' import Main from '@/app/components/app/log-annotation' -import { PageType } from '@/app/components/app/configuration/toolbox/annotation/type' +import { PageType } from '@/app/components/base/features/new-feature-panel/annotation-reply/type' const Logs = async () => { return ( diff --git a/web/app/components/app/annotation/index.tsx b/web/app/components/app/annotation/index.tsx index 7025ba9a37..f19828d827 100644 --- a/web/app/components/app/annotation/index.tsx +++ b/web/app/components/app/annotation/index.tsx @@ -18,7 +18,7 @@ import Switch from '@/app/components/base/switch' import { addAnnotation, delAnnotation, fetchAnnotationConfig as doFetchAnnotationConfig, editAnnotation, fetchAnnotationList, queryAnnotationJobStatus, updateAnnotationScore, updateAnnotationStatus } from '@/service/annotation' import Loading from '@/app/components/base/loading' import { APP_PAGE_LIMIT } from '@/config' -import ConfigParamModal from '@/app/components/app/configuration/toolbox/annotation/config-param-modal' +import ConfigParamModal from '@/app/components/base/features/new-feature-panel/annotation-reply/config-param-modal' import type { AnnotationReplyConfig } from '@/models/debug' import { sleep } from '@/utils' import { useProviderContext } from '@/context/provider-context' diff --git a/web/app/components/app/app-publisher/features-wrapper.tsx b/web/app/components/app/app-publisher/features-wrapper.tsx index c5065126f9..d34cecf55f 100644 --- a/web/app/components/app/app-publisher/features-wrapper.tsx +++ b/web/app/components/app/app-publisher/features-wrapper.tsx @@ -1,25 +1,86 @@ -import React, { useCallback } from 'react' +import React, { useCallback, useState } from 'react' +import { useTranslation } from 'react-i18next' +import produce from 'immer' import type { AppPublisherProps } from '@/app/components/app/app-publisher' +import Confirm from '@/app/components/base/confirm' import AppPublisher from '@/app/components/app/app-publisher' -import { useFeatures } from '@/app/components/base/features/hooks' +import { useFeatures, useFeaturesStore } from '@/app/components/base/features/hooks' import type { ModelAndParameter } from '@/app/components/app/configuration/debug/types' +import type { FileUpload } from '@/app/components/base/features/types' +import { Resolution } from '@/types/app' +import { FILE_EXTS } from '@/app/components/base/prompt-editor/constants' +import { SupportUploadFileTypes } from '@/app/components/workflow/types' type Props = Omit & { onPublish?: (modelAndParameter?: ModelAndParameter, features?: any) => Promise | any + publishedConfig?: any + resetAppConfig?: () => void } const FeaturesWrappedAppPublisher = (props: Props) => { + const { t } = useTranslation() const features = useFeatures(s => s.features) + const featuresStore = useFeaturesStore() + const [restoreConfirmOpen, setRestoreConfirmOpen] = useState(false) + const handleConfirm = useCallback(() => { + console.log('resetAppConfig') + props.resetAppConfig?.() + const { + features, + setFeatures, + } = featuresStore!.getState() + const newFeatures = produce(features, (draft) => { + draft.moreLikeThis = props.publishedConfig.modelConfig.more_like_this || { enabled: false } + draft.opening = { + enabled: !!props.publishedConfig.modelConfig.opening_statement, + opening_statement: props.publishedConfig.modelConfig.opening_statement || '', + suggested_questions: props.publishedConfig.modelConfig.suggested_questions || [], + } + draft.moderation = props.publishedConfig.modelConfig.sensitive_word_avoidance || { enabled: false } + draft.speech2text = props.publishedConfig.modelConfig.speech_to_text || { enabled: false } + draft.text2speech = props.publishedConfig.modelConfig.text_to_speech || { enabled: false } + draft.suggested = props.publishedConfig.modelConfig.suggested_questions_after_answer || { enabled: false } + draft.citation = props.publishedConfig.modelConfig.retriever_resource || { enabled: false } + draft.annotationReply = props.publishedConfig.modelConfig.annotation_reply || { enabled: false } + draft.file = { + image: { + detail: props.publishedConfig.modelConfig.file_upload?.image?.detail || Resolution.high, + enabled: !!props.publishedConfig.modelConfig.file_upload?.image?.enabled, + number_limits: props.publishedConfig.modelConfig.file_upload?.image?.number_limits || 3, + transfer_methods: props.publishedConfig.modelConfig.file_upload?.image?.transfer_methods || ['local_file', 'remote_url'], + }, + enabled: !!(props.publishedConfig.modelConfig.file_upload?.enabled || props.publishedConfig.modelConfig.file_upload?.image?.enabled), + allowed_file_types: props.publishedConfig.modelConfig.file_upload?.allowed_file_types || [SupportUploadFileTypes.image], + allowed_file_extensions: props.publishedConfig.modelConfig.file_upload?.allowed_file_extensions || FILE_EXTS[SupportUploadFileTypes.image].map(ext => `.${ext}`), + allowed_file_upload_methods: props.publishedConfig.modelConfig.file_upload?.allowed_file_upload_methods || props.publishedConfig.modelConfig.file_upload?.image?.transfer_methods || ['local_file', 'remote_url'], + number_limits: props.publishedConfig.modelConfig.file_upload?.number_limits || props.publishedConfig.modelConfig.file_upload?.image?.number_limits || 3, + } as FileUpload + }) + setFeatures(newFeatures) + setRestoreConfirmOpen(false) + }, [featuresStore, props]) const handlePublish = useCallback((modelAndParameter?: ModelAndParameter) => { return props.onPublish?.(modelAndParameter, features) }, [features, props]) return ( - + <> + setRestoreConfirmOpen(true), + }}/> + {restoreConfirmOpen && ( + setRestoreConfirmOpen(false)} + /> + )} + ) } diff --git a/web/app/components/app/configuration/config/index.tsx b/web/app/components/app/configuration/config/index.tsx index b569a42875..f7fd3cec80 100644 --- a/web/app/components/app/configuration/config/index.tsx +++ b/web/app/components/app/configuration/config/index.tsx @@ -7,7 +7,6 @@ import { useFormattingChangedDispatcher } from '../debug/hooks' import DatasetConfig from '../dataset-config' import HistoryPanel from '../config-prompt/conversation-histroy/history-panel' import ConfigVision from '../config-vision' -import useAnnotationConfig from '../toolbox/annotation/use-annotation-config' import AgentTools from './agent/agent-tools' import ConfigContext from '@/context/debug-configuration' import ConfigPrompt from '@/app/components/app/configuration/config-prompt' @@ -15,25 +14,18 @@ import ConfigVar from '@/app/components/app/configuration/config-var' import { type ModelConfig, type PromptVariable } from '@/models/debug' import type { AppType } from '@/types/app' import { ModelModeType } from '@/types/app' -import ConfigParamModal from '@/app/components/app/configuration/toolbox/annotation/config-param-modal' -import AnnotationFullModal from '@/app/components/billing/annotation-full/modal' const Config: FC = () => { const { - appId, mode, isAdvancedMode, modelModeType, isAgent, - // canReturnToSimpleMode, - // setPromptMode, hasSetBlockStatus, showHistoryModal, modelConfig, setModelConfig, setPrevPromptConfig, - annotationConfig, - setAnnotationConfig, } = useContext(ConfigContext) const isChatApp = ['advanced-chat', 'agent-chat', 'chat'].includes(mode) const formattingChangedDispatcher = useFormattingChangedDispatcher() @@ -61,20 +53,6 @@ const Config: FC = () => { setModelConfig(newModelConfig) } - const { - handleEnableAnnotation, - // setScore, - // handleDisableAnnotation, - isShowAnnotationConfigInit, - setIsShowAnnotationConfigInit, - isShowAnnotationFullModal, - setIsShowAnnotationFullModal, - } = useAnnotationConfig({ - appId, - annotationConfig, - setAnnotationConfig, - }) - return ( <>
{ onShowEditModal={showHistoryModal} /> )} - - { - setIsShowAnnotationConfigInit(false) - // showChooseFeatureTrue() - }} - onSave={async (embeddingModel, score) => { - await handleEnableAnnotation(embeddingModel, score) - setIsShowAnnotationConfigInit(false) - }} - annotationConfig={annotationConfig} - /> - {isShowAnnotationFullModal && ( - setIsShowAnnotationFullModal(false)} - /> - )}
) diff --git a/web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx b/web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx index b56e08333f..35289b6be2 100644 --- a/web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx +++ b/web/app/components/app/configuration/debug/debug-with-multiple-model/chat-item.tsx @@ -58,7 +58,7 @@ const ChatItem: FC = ({ file_upload: features.file, suggested_questions_after_answer: features.suggested, retriever_resource: features.citation, - // ##TODO## annotation_reply + annotation_reply: features.annotationReply, } as ChatConfig }, [configTemplate, features]) const { diff --git a/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx b/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx index c9e83da1c3..b3fef73f5b 100644 --- a/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx +++ b/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx @@ -58,7 +58,7 @@ const DebugWithSingleModel = forwardRef { setModelConfig(_publishedConfig.modelConfig) setCompletionParams(_publishedConfig.completionParams) setDataSets(modelConfig.dataSets || []) - // feature + // reset feature setIntroduction(modelConfig.opening_statement!) setMoreLikeThisConfig(modelConfig.more_like_this || { enabled: false, @@ -446,6 +446,7 @@ const Configuration: FC = () => { text2speech: modelConfig.text_to_speech || { enabled: false }, file: { image: { + detail: modelConfig.file_upload?.image?.detail || Resolution.high, enabled: !!modelConfig.file_upload?.image?.enabled, number_limits: modelConfig.file_upload?.image?.number_limits || 3, transfer_methods: modelConfig.file_upload?.image?.transfer_methods || ['local_file', 'remote_url'], @@ -741,12 +742,6 @@ const Configuration: FC = () => { return true } - const [restoreConfirmOpen, setRestoreConfirmOpen] = useState(false) - const resetAppConfig = () => { - syncToPublishedConfig(publishedConfig!) - setRestoreConfirmOpen(false) - } - const [showUseGPT4Confirm, setShowUseGPT4Confirm] = useState(false) const { @@ -907,7 +902,8 @@ const Configuration: FC = () => { debugWithMultipleModel, multipleModelConfigs, onPublish, - onRestore: () => setRestoreConfirmOpen(true), + publishedConfig: publishedConfig!, + resetAppConfig: () => syncToPublishedConfig(publishedConfig!), }} /> @@ -933,15 +929,6 @@ const Configuration: FC = () => { } - {restoreConfirmOpen && ( - setRestoreConfirmOpen(false)} - /> - )} {showUseGPT4Confirm && ( { + const { t } = useTranslation() + const router = useRouter() + const pathname = usePathname() + const matched = pathname.match(/\/app\/([^/]+)/) + const appId = (matched?.length && matched[1]) ? matched[1] : '' + const featuresStore = useFeaturesStore() + const annotationReply = useFeatures(s => s.features.annotationReply) + + const updateAnnotationReply = useCallback((newConfig: any) => { + const { + features, + setFeatures, + } = featuresStore!.getState() + const newFeatures = produce(features, (draft) => { + draft.annotationReply = newConfig + }) + setFeatures(newFeatures) + if (onChange) + onChange(newFeatures) + }, [featuresStore, onChange]) + + const { + handleEnableAnnotation, + handleDisableAnnotation, + isShowAnnotationConfigInit, + setIsShowAnnotationConfigInit, + isShowAnnotationFullModal, + setIsShowAnnotationFullModal, + } = useAnnotationConfig({ + appId, + annotationConfig: annotationReply as any || { + id: '', + enabled: false, + score_threshold: ANNOTATION_DEFAULT.score_threshold, + embedding_model: { + embedding_provider_name: '', + embedding_model_name: '', + }, + }, + setAnnotationConfig: updateAnnotationReply, + }) + + const handleSwitch = useCallback((enabled: boolean) => { + if (enabled) + setIsShowAnnotationConfigInit(true) + else + handleDisableAnnotation(annotationReply?.embedding_model as any) + }, [annotationReply?.embedding_model, handleDisableAnnotation, setIsShowAnnotationConfigInit]) + + const [isHovering, setIsHovering] = useState(false) + + return ( + <> + + + + } + title={t('appDebug.feature.annotation.title')} + value={!!annotationReply?.enabled} + onChange={state => handleSwitch(state)} + onMouseEnter={() => setIsHovering(true)} + onMouseLeave={() => setIsHovering(false)} + disabled={disabled} + > + <> + {!annotationReply?.enabled && ( +
{t('appDebug.feature.annotation.description')}
+ )} + {!!annotationReply?.enabled && ( + <> + {!isHovering && ( +
+
+
{t('appDebug.feature.annotation.scoreThreshold.title')}
+
{annotationReply.score_threshold || '-'}
+
+
+
+
{t('common.modelProvider.embeddingModel.key')}
+
{annotationReply.embedding_model?.embedding_model_name}
+
+
+ )} + {isHovering && ( +
+ + +
+ )} + + )} + +
+ { + setIsShowAnnotationConfigInit(false) + // showChooseFeatureTrue() + }} + onSave={async (embeddingModel, score) => { + await handleEnableAnnotation(embeddingModel, score) + setIsShowAnnotationConfigInit(false) + }} + annotationConfig={annotationReply as any} + /> + {isShowAnnotationFullModal && ( + setIsShowAnnotationFullModal(false)} + /> + )} + + ) +} + +export default AnnotationReply diff --git a/web/app/components/app/configuration/toolbox/score-slider/base-slider/index.tsx b/web/app/components/base/features/new-feature-panel/annotation-reply/score-slider/base-slider/index.tsx similarity index 100% rename from web/app/components/app/configuration/toolbox/score-slider/base-slider/index.tsx rename to web/app/components/base/features/new-feature-panel/annotation-reply/score-slider/base-slider/index.tsx diff --git a/web/app/components/app/configuration/toolbox/score-slider/base-slider/style.module.css b/web/app/components/base/features/new-feature-panel/annotation-reply/score-slider/base-slider/style.module.css similarity index 100% rename from web/app/components/app/configuration/toolbox/score-slider/base-slider/style.module.css rename to web/app/components/base/features/new-feature-panel/annotation-reply/score-slider/base-slider/style.module.css diff --git a/web/app/components/app/configuration/toolbox/score-slider/index.tsx b/web/app/components/base/features/new-feature-panel/annotation-reply/score-slider/index.tsx similarity index 90% rename from web/app/components/app/configuration/toolbox/score-slider/index.tsx rename to web/app/components/base/features/new-feature-panel/annotation-reply/score-slider/index.tsx index 9826cbadcf..d68db9be73 100644 --- a/web/app/components/app/configuration/toolbox/score-slider/index.tsx +++ b/web/app/components/base/features/new-feature-panel/annotation-reply/score-slider/index.tsx @@ -2,7 +2,7 @@ import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' -import Slider from '@/app/components/app/configuration/toolbox/score-slider/base-slider' +import Slider from '@/app/components/base/features/new-feature-panel/annotation-reply/score-slider/base-slider' type Props = { className?: string diff --git a/web/app/components/app/configuration/toolbox/annotation/type.ts b/web/app/components/base/features/new-feature-panel/annotation-reply/type.ts similarity index 100% rename from web/app/components/app/configuration/toolbox/annotation/type.ts rename to web/app/components/base/features/new-feature-panel/annotation-reply/type.ts diff --git a/web/app/components/app/configuration/toolbox/annotation/use-annotation-config.ts b/web/app/components/base/features/new-feature-panel/annotation-reply/use-annotation-config.ts similarity index 100% rename from web/app/components/app/configuration/toolbox/annotation/use-annotation-config.ts rename to web/app/components/base/features/new-feature-panel/annotation-reply/use-annotation-config.ts diff --git a/web/app/components/base/features/new-feature-panel/feature-bar.tsx b/web/app/components/base/features/new-feature-panel/feature-bar.tsx index 3c2d748975..92273c47ab 100644 --- a/web/app/components/base/features/new-feature-panel/feature-bar.tsx +++ b/web/app/components/base/features/new-feature-panel/feature-bar.tsx @@ -1,7 +1,7 @@ import React, { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiApps2AddLine, RiArrowRightLine, RiSparklingFill } from '@remixicon/react' -import { Citations, ContentModeration, FolderUpload, LoveMessage, Microphone01, TextToAudio, VirtualAssistant } from '@/app/components/base/icons/src/vender/features' +import { Citations, ContentModeration, FolderUpload, LoveMessage, MessageFast, Microphone01, TextToAudio, VirtualAssistant } from '@/app/components/base/icons/src/vender/features' import Button from '@/app/components/base/button' import Tooltip from '@/app/components/base/tooltip' import VoiceSettings from '@/app/components/base/features/new-feature-panel/text-to-speech/voice-settings' @@ -118,7 +118,15 @@ const FeatureBar = ({ )} - {/* ##TODO## annotation_reply */} + {isChatMode && !!features.annotationReply?.enabled && ( + +
+ +
+
+ )}
{t('appDebug.feature.bar.enableText')}
- - - + {!inWorkflow && isChatMode && ( + )} diff --git a/web/app/components/base/features/store.ts b/web/app/components/base/features/store.ts index 7fb3c9848a..9c6e242ab5 100644 --- a/web/app/components/base/features/store.ts +++ b/web/app/components/base/features/store.ts @@ -46,6 +46,7 @@ export const createFeaturesStore = (initProps?: Partial) => { file: { image: { enabled: false, + detail: 'high', number_limits: 3, transfer_methods: [TransferMethod.local_file, TransferMethod.remote_url], }, diff --git a/web/app/components/base/features/types.ts b/web/app/components/base/features/types.ts index 211ba96cd5..0b959c4aa4 100644 --- a/web/app/components/base/features/types.ts +++ b/web/app/components/base/features/types.ts @@ -30,6 +30,7 @@ export type SensitiveWordAvoidance = EnabledOrDisabled & { export type FileUpload = { image?: EnabledOrDisabled & { + detail?: 'high' | 'low' number_limits?: number transfer_methods?: TransferMethod[] }