From 17a67e792246b14f97663f0348693368ceec028d Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Fri, 8 Mar 2024 13:46:14 +0800 Subject: [PATCH] remove annatation --- .../features/feature-choose/feature-modal.tsx | 13 +- .../annotation/annotation-ctrl-btn/index.tsx | 135 ----------------- .../annotation/config-param-modal.tsx | 140 ------------------ .../feature-panel/annotation/index.tsx | 124 ---------------- .../features/feature-panel/annotation/type.ts | 4 - .../annotation/use-annotation-config.ts | 89 ----------- .../base/features/feature-panel/index.tsx | 9 -- .../_base/components/panel-operator/index.tsx | 4 +- 8 files changed, 3 insertions(+), 515 deletions(-) delete mode 100644 web/app/components/base/features/feature-panel/annotation/annotation-ctrl-btn/index.tsx delete mode 100644 web/app/components/base/features/feature-panel/annotation/config-param-modal.tsx delete mode 100644 web/app/components/base/features/feature-panel/annotation/index.tsx delete mode 100644 web/app/components/base/features/feature-panel/annotation/type.ts delete mode 100644 web/app/components/base/features/feature-panel/annotation/use-annotation-config.ts diff --git a/web/app/components/base/features/feature-choose/feature-modal.tsx b/web/app/components/base/features/feature-choose/feature-modal.tsx index 3b4e66b071..a70ba3056d 100644 --- a/web/app/components/base/features/feature-choose/feature-modal.tsx +++ b/web/app/components/base/features/feature-choose/feature-modal.tsx @@ -15,10 +15,7 @@ import SuggestedQuestionsAfterAnswerIcon from '@/app/components/app/configuratio import { Microphone01, Speaker } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices' import { Citations } from '@/app/components/base/icons/src/vender/solid/editor' import { FileSearch02 } from '@/app/components/base/icons/src/vender/solid/files' -import { - MessageFast, - MessageHeartCircle, -} from '@/app/components/base/icons/src/vender/solid/communication' +import { MessageHeartCircle } from '@/app/components/base/icons/src/vender/solid/communication' import { FeatureEnum } from '@/app/components/base/features/types' import { useDefaultModel } from '@/app/components/header/account-setting/model-provider-page/hooks' @@ -137,14 +134,6 @@ const FeatureModal: FC = ({ onChange={handleChange} type={FeatureEnum.moderation} /> - } - title={t('appDebug.feature.annotation.title')} - description={t('appDebug.feature.annotation.description')} - value={!!features.annotation.enabled} - onChange={handleChange} - type={FeatureEnum.annotation} - /> diff --git a/web/app/components/base/features/feature-panel/annotation/annotation-ctrl-btn/index.tsx b/web/app/components/base/features/feature-panel/annotation/annotation-ctrl-btn/index.tsx deleted file mode 100644 index 1dcae64416..0000000000 --- a/web/app/components/base/features/feature-panel/annotation/annotation-ctrl-btn/index.tsx +++ /dev/null @@ -1,135 +0,0 @@ -'use client' -import type { FC } from 'react' -import React, { useRef, useState } from 'react' -import { useHover } from 'ahooks' -import cn from 'classnames' -import { useTranslation } from 'react-i18next' -import { MessageCheckRemove, MessageFastPlus } from '@/app/components/base/icons/src/vender/line/communication' -import { MessageFast } from '@/app/components/base/icons/src/vender/solid/communication' -import { Edit04 } from '@/app/components/base/icons/src/vender/line/general' -import RemoveAnnotationConfirmModal from '@/app/components/app/annotation/remove-annotation-confirm-modal' -import TooltipPlus from '@/app/components/base/tooltip-plus' -import { addAnnotation, delAnnotation } from '@/service/annotation' -import Toast from '@/app/components/base/toast' -import { useProviderContext } from '@/context/provider-context' -import { useModalContext } from '@/context/modal-context' - -type Props = { - appId: string - messageId?: string - annotationId?: string - className?: string - cached: boolean - query: string - answer: string - onAdded: (annotationId: string, authorName: string) => void - onEdit: () => void - onRemoved: () => void -} - -const CacheCtrlBtn: FC = ({ - className, - cached, - query, - answer, - appId, - messageId, - annotationId, - onAdded, - onEdit, - onRemoved, -}) => { - const { t } = useTranslation() - const { plan, enableBilling } = useProviderContext() - const isAnnotationFull = (enableBilling && plan.usage.annotatedResponse >= plan.total.annotatedResponse) - const { setShowAnnotationFullModal } = useModalContext() - const [showModal, setShowModal] = useState(false) - const cachedBtnRef = useRef(null) - const isCachedBtnHovering = useHover(cachedBtnRef) - const handleAdd = async () => { - if (isAnnotationFull) { - setShowAnnotationFullModal() - return - } - const res: any = await addAnnotation(appId, { - message_id: messageId, - question: query, - answer, - }) - Toast.notify({ - message: t('common.api.actionSuccess') as string, - type: 'success', - }) - onAdded(res.id, res.account?.name) - } - - const handleRemove = async () => { - await delAnnotation(appId, annotationId!) - Toast.notify({ - message: t('common.api.actionSuccess') as string, - type: 'success', - }) - onRemoved() - setShowModal(false) - } - return ( -
-
- {cached - ? ( -
-
setShowModal(true)} - > - {!isCachedBtnHovering - ? ( - <> - -
{t('appDebug.feature.annotation.cached')}
- - ) - : <> - -
{t('appDebug.feature.annotation.remove')}
- } -
-
- ) - : answer - ? ( - -
- -
-
- ) - : null - } - -
- -
-
- -
- setShowModal(false)} - onRemove={handleRemove} - /> -
- ) -} -export default React.memo(CacheCtrlBtn) diff --git a/web/app/components/base/features/feature-panel/annotation/config-param-modal.tsx b/web/app/components/base/features/feature-panel/annotation/config-param-modal.tsx deleted file mode 100644 index 999e0131c7..0000000000 --- a/web/app/components/base/features/feature-panel/annotation/config-param-modal.tsx +++ /dev/null @@ -1,140 +0,0 @@ -'use client' -import type { FC } from 'react' -import React, { useState } from 'react' -import { useTranslation } from 'react-i18next' -import ScoreSlider from '../score-slider' -import { Item } from './index' -import Modal from '@/app/components/base/modal' -import Button from '@/app/components/base/button' -import Toast from '@/app/components/base/toast' -import type { AnnotationReplyConfig } from '@/models/debug' -import { ANNOTATION_DEFAULT } from '@/config' -import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector' -import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' - -type Props = { - appId: string - isShow: boolean - onHide: () => void - onSave: (embeddingModel: { - embedding_provider_name: string - embedding_model_name: string - }, score: number) => void - isInit?: boolean - annotationConfig: AnnotationReplyConfig -} - -const ConfigParamModal: FC = ({ - isShow, - onHide: doHide, - onSave, - isInit, - annotationConfig: oldAnnotationConfig, -}) => { - const { t } = useTranslation() - const { - modelList: embeddingsModelList, - defaultModel: embeddingsDefaultModel, - currentModel: isEmbeddingsDefaultModelValid, - } = useModelListAndDefaultModelAndCurrentProviderAndModel(2) - const [annotationConfig, setAnnotationConfig] = useState(oldAnnotationConfig) - - const [isLoading, setLoading] = useState(false) - const [embeddingModel, setEmbeddingModel] = useState(oldAnnotationConfig.embedding_model - ? { - providerName: oldAnnotationConfig.embedding_model.embedding_provider_name, - modelName: oldAnnotationConfig.embedding_model.embedding_model_name, - } - : (embeddingsDefaultModel - ? { - providerName: embeddingsDefaultModel.provider.provider, - modelName: embeddingsDefaultModel.model, - } - : undefined)) - const onHide = () => { - if (!isLoading) - doHide() - } - - const handleSave = async () => { - if (!embeddingModel || !embeddingModel.modelName || (embeddingModel.modelName === embeddingsDefaultModel?.model && !isEmbeddingsDefaultModelValid)) { - Toast.notify({ - message: t('common.modelProvider.embeddingModel.required'), - type: 'error', - }) - return - } - setLoading(true) - await onSave({ - embedding_provider_name: embeddingModel.providerName, - embedding_model_name: embeddingModel.modelName, - }, annotationConfig.score_threshold) - setLoading(false) - } - - return ( - -
- {t(`appAnnotation.initSetup.${isInit ? 'title' : 'configTitle'}`)} -
- -
- - { - setAnnotationConfig({ - ...annotationConfig, - score_threshold: val / 100, - }) - }} - /> - - - -
- { - setEmbeddingModel({ - providerName: val.provider, - modelName: val.model, - }) - }} - /> -
-
-
- -
- - -
-
- ) -} -export default React.memo(ConfigParamModal) diff --git a/web/app/components/base/features/feature-panel/annotation/index.tsx b/web/app/components/base/features/feature-panel/annotation/index.tsx deleted file mode 100644 index 519f3505f9..0000000000 --- a/web/app/components/base/features/feature-panel/annotation/index.tsx +++ /dev/null @@ -1,124 +0,0 @@ -'use client' -import type { FC } from 'react' -import React from 'react' -import { useTranslation } from 'react-i18next' -import { useContext } from 'use-context-selector' -import { usePathname, useRouter } from 'next/navigation' -import ConfigParamModal from './config-param-modal' -import Panel from '@/app/components/app/configuration/base/feature-panel' -import { MessageFast } from '@/app/components/base/icons/src/vender/solid/communication' -import TooltipPlus from '@/app/components/base/tooltip-plus' -import { HelpCircle, LinkExternal02, Settings04 } from '@/app/components/base/icons/src/vender/line/general' -import ConfigContext from '@/context/debug-configuration' -import type { EmbeddingModelConfig } from '@/app/components/app/annotation/type' -import { updateAnnotationScore } from '@/service/annotation' - -export type AnnotationProps = { - onEmbeddingChange: (embeddingModel: EmbeddingModelConfig) => void - onScoreChange: (score: number, embeddingModel?: EmbeddingModelConfig) => void -} - -export const Item: FC<{ title: string; tooltip: string; children: JSX.Element }> = ({ - title, - tooltip, - children, -}) => { - return ( -
-
-
{title}
- {tooltip}
- } - > - - -
-
{children}
- - ) -} - -const AnnotationReplyConfig: FC = ({ - onEmbeddingChange, - onScoreChange, -}) => { - const { t } = useTranslation() - const router = useRouter() - const pathname = usePathname() - const matched = pathname.match(/\/app\/([^/]+)/) - const appId = (matched?.length && matched[1]) ? matched[1] : '' - const { - annotationConfig, - } = useContext(ConfigContext) - - const [isShowEdit, setIsShowEdit] = React.useState(false) - - return ( - <> - - } - title={t('appDebug.feature.annotation.title')} - headerRight={ -
-
{ setIsShowEdit(true) }} - > - -
- - {t('common.operation.params')} -
-
-
{ - router.push(`/app/${appId}/annotations`) - }}> -
{t('appDebug.feature.annotation.cacheManagement')}
- -
-
- } - noBodySpacing - /> - {isShowEdit && ( - { - setIsShowEdit(false) - }} - onSave={async (embeddingModel, score) => { - let isEmbeddingModelChanged = false - if ( - embeddingModel.embedding_model_name !== annotationConfig.embedding_model.embedding_model_name - && embeddingModel.embedding_provider_name !== annotationConfig.embedding_model.embedding_provider_name - ) { - await onEmbeddingChange(embeddingModel) - isEmbeddingModelChanged = true - } - - if (score !== annotationConfig.score_threshold) { - await updateAnnotationScore(appId, annotationConfig.id, score) - if (isEmbeddingModelChanged) - onScoreChange(score, embeddingModel) - - else - onScoreChange(score) - } - - setIsShowEdit(false) - }} - annotationConfig={annotationConfig} - /> - )} - - ) -} -export default React.memo(AnnotationReplyConfig) diff --git a/web/app/components/base/features/feature-panel/annotation/type.ts b/web/app/components/base/features/feature-panel/annotation/type.ts deleted file mode 100644 index 910453478c..0000000000 --- a/web/app/components/base/features/feature-panel/annotation/type.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum PageType { - log = 'log', - annotation = 'annotation', -} diff --git a/web/app/components/base/features/feature-panel/annotation/use-annotation-config.ts b/web/app/components/base/features/feature-panel/annotation/use-annotation-config.ts deleted file mode 100644 index 540302cb27..0000000000 --- a/web/app/components/base/features/feature-panel/annotation/use-annotation-config.ts +++ /dev/null @@ -1,89 +0,0 @@ -import React, { useState } from 'react' -import produce from 'immer' -import type { AnnotationReplyConfig } from '@/models/debug' -import { queryAnnotationJobStatus, updateAnnotationStatus } from '@/service/annotation' -import type { EmbeddingModelConfig } from '@/app/components/app/annotation/type' -import { AnnotationEnableStatus, JobStatus } from '@/app/components/app/annotation/type' -import { sleep } from '@/utils' -import { ANNOTATION_DEFAULT } from '@/config' -import { useProviderContext } from '@/context/provider-context' - -type Params = { - appId: string - annotationConfig: AnnotationReplyConfig - setAnnotationConfig: (annotationConfig: AnnotationReplyConfig) => void -} -const useAnnotationConfig = ({ - appId, - annotationConfig, - setAnnotationConfig, -}: Params) => { - const { plan, enableBilling } = useProviderContext() - const isAnnotationFull = (enableBilling && plan.usage.annotatedResponse >= plan.total.annotatedResponse) - const [isShowAnnotationFullModal, setIsShowAnnotationFullModal] = useState(false) - const [isShowAnnotationConfigInit, doSetIsShowAnnotationConfigInit] = React.useState(false) - const setIsShowAnnotationConfigInit = (isShow: boolean) => { - if (isShow) { - if (isAnnotationFull) { - setIsShowAnnotationFullModal(true) - return - } - } - doSetIsShowAnnotationConfigInit(isShow) - } - const ensureJobCompleted = async (jobId: string, status: AnnotationEnableStatus) => { - let isCompleted = false - while (!isCompleted) { - const res: any = await queryAnnotationJobStatus(appId, status, jobId) - isCompleted = res.job_status === JobStatus.completed - if (isCompleted) - break - - await sleep(2000) - } - } - - const handleEnableAnnotation = async (embeddingModel: EmbeddingModelConfig, score?: number) => { - if (isAnnotationFull) - return - - const { job_id: jobId }: any = await updateAnnotationStatus(appId, AnnotationEnableStatus.enable, embeddingModel, score) - await ensureJobCompleted(jobId, AnnotationEnableStatus.enable) - setAnnotationConfig(produce(annotationConfig, (draft: AnnotationReplyConfig) => { - draft.enabled = true - draft.embedding_model = embeddingModel - if (!draft.score_threshold) - draft.score_threshold = ANNOTATION_DEFAULT.score_threshold - })) - } - - const setScore = (score: number, embeddingModel?: EmbeddingModelConfig) => { - setAnnotationConfig(produce(annotationConfig, (draft: AnnotationReplyConfig) => { - draft.score_threshold = score - if (embeddingModel) - draft.embedding_model = embeddingModel - })) - } - - const handleDisableAnnotation = async (embeddingModel: EmbeddingModelConfig) => { - if (!annotationConfig.enabled) - return - - await updateAnnotationStatus(appId, AnnotationEnableStatus.disable, embeddingModel) - setAnnotationConfig(produce(annotationConfig, (draft: AnnotationReplyConfig) => { - draft.enabled = false - })) - } - - return { - handleEnableAnnotation, - handleDisableAnnotation, - isShowAnnotationConfigInit, - setIsShowAnnotationConfigInit, - isShowAnnotationFullModal, - setIsShowAnnotationFullModal, - setScore, - } -} - -export default useAnnotationConfig diff --git a/web/app/components/base/features/feature-panel/index.tsx b/web/app/components/base/features/feature-panel/index.tsx index 2f0905bb05..b8836f8e8f 100644 --- a/web/app/components/base/features/feature-panel/index.tsx +++ b/web/app/components/base/features/feature-panel/index.tsx @@ -12,18 +12,14 @@ import TextToSpeech from './text-to-speech' import SpeechToText from './speech-to-text' import Citation from './citation' import Moderation from './moderation' -import Annotation from './annotation' -import type { AnnotationProps } from './annotation' export type FeaturePanelProps = { onChange?: OnFeaturesChange openingStatementProps: OpeningStatementProps - annotationProps: AnnotationProps } const FeaturePanel = ({ onChange, openingStatementProps, - annotationProps, }: FeaturePanelProps) => { const { t } = useTranslation() const features = useFeatures(s => s.features) @@ -98,11 +94,6 @@ const FeaturePanel = ({ ) } - { - features.annotation.enabled && ( - - ) - } ) diff --git a/web/app/components/workflow/nodes/_base/components/panel-operator/index.tsx b/web/app/components/workflow/nodes/_base/components/panel-operator/index.tsx index 289c4e5380..19a536f1bd 100644 --- a/web/app/components/workflow/nodes/_base/components/panel-operator/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/panel-operator/index.tsx @@ -54,14 +54,14 @@ const PanelOperator = ({ }, [toolsets, data.provider_id]) const handleGetAbout = useCallback(() => { - if (data.provider_id && !toolsMap[data.provider_id]?.length) { + if (data.provider_id && !toolsMap[data.provider_id]?.length && open) { fetchToolList(data.provider_id).then((list: any) => { setToolsMap(produce(toolsMap, (draft) => { draft[data.provider_id as string] = list })) }) } - }, [data, toolsMap, fetchToolList, setToolsMap]) + }, [data, toolsMap, fetchToolList, setToolsMap, open]) useEffect(() => { handleGetAbout() }, [handleGetAbout])