From 633768cd2aae52929372ab5cdb11fd90a7920320 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Thu, 31 Oct 2024 08:43:12 +0800 Subject: [PATCH] annotation config --- web/app/components/app/annotation/index.tsx | 3 +- web/app/components/app/annotation/type.ts | 3 +- .../toolbox/annotation/config-param.tsx | 124 ------------------ .../app/configuration/toolbox/index.tsx | 45 ------- .../annotation-reply/config-param-modal.tsx | 6 + web/models/debug.ts | 1 + web/service/annotation.ts | 4 +- 7 files changed, 14 insertions(+), 172 deletions(-) delete mode 100644 web/app/components/app/configuration/toolbox/annotation/config-param.tsx delete mode 100644 web/app/components/app/configuration/toolbox/index.tsx diff --git a/web/app/components/app/annotation/index.tsx b/web/app/components/app/annotation/index.tsx index 46ecdd5480..e287f6970f 100644 --- a/web/app/components/app/annotation/index.tsx +++ b/web/app/components/app/annotation/index.tsx @@ -27,7 +27,7 @@ import AnnotationFullModal from '@/app/components/billing/annotation-full/modal' import { Settings04 } from '@/app/components/base/icons/src/vender/line/general' import type { App } from '@/types/app' -interface Props { +type Props = { appDetail: App } @@ -283,6 +283,7 @@ const Annotation: FC = ({ if ( embeddingModel.embedding_model_name !== annotationConfig?.embedding_model?.embedding_model_name || embeddingModel.embedding_provider_name !== annotationConfig?.embedding_model?.embedding_provider_name + || embeddingModel.plugin_id !== annotationConfig?.embedding_model?.plugin_id ) { const { job_id: jobId }: any = await updateAnnotationStatus(appDetail.id, AnnotationEnableStatus.enable, embeddingModel, score) await ensureJobCompleted(jobId, AnnotationEnableStatus.enable) diff --git a/web/app/components/app/annotation/type.ts b/web/app/components/app/annotation/type.ts index 5df6f51ace..28811f4617 100644 --- a/web/app/components/app/annotation/type.ts +++ b/web/app/components/app/annotation/type.ts @@ -23,8 +23,9 @@ export type HitHistoryItem = { } export type EmbeddingModelConfig = { - embedding_provider_name: string + plugin_id: string embedding_model_name: string + embedding_provider_name: string } export enum AnnotationEnableStatus { diff --git a/web/app/components/app/configuration/toolbox/annotation/config-param.tsx b/web/app/components/app/configuration/toolbox/annotation/config-param.tsx deleted file mode 100644 index e418a76c34..0000000000 --- a/web/app/components/app/configuration/toolbox/annotation/config-param.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 Tooltip from '@/app/components/base/tooltip' -import { 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 { fetchAnnotationConfig, updateAnnotationScore } from '@/service/annotation' -import type { AnnotationReplyConfig as AnnotationReplyConfigType } from '@/models/debug' - -type Props = { - 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) => { - const annotationConfig = await fetchAnnotationConfig(appId) as AnnotationReplyConfigType - 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/app/configuration/toolbox/index.tsx b/web/app/components/app/configuration/toolbox/index.tsx deleted file mode 100644 index 00ea301a42..0000000000 --- a/web/app/components/app/configuration/toolbox/index.tsx +++ /dev/null @@ -1,45 +0,0 @@ -'use client' - -import type { FC } from 'react' -import React from 'react' -import { useTranslation } from 'react-i18next' -import GroupName from '../base/group-name' -import Moderation from './moderation' -import Annotation from './annotation/config-param' -import type { EmbeddingModelConfig } from '@/app/components/app/annotation/type' - -export type ToolboxProps = { - showModerationSettings: boolean - showAnnotation: boolean - onEmbeddingChange: (embeddingModel: EmbeddingModelConfig) => void - onScoreChange: (score: number, embeddingModel?: EmbeddingModelConfig) => void -} - -const Toolbox: FC = ({ - showModerationSettings, - showAnnotation, - onEmbeddingChange, - onScoreChange, -}) => { - const { t } = useTranslation() - - return ( -
- - { - showModerationSettings && ( - - ) - } - { - showAnnotation && ( - - ) - } -
- ) -} -export default React.memo(Toolbox) diff --git a/web/app/components/base/features/new-feature-panel/annotation-reply/config-param-modal.tsx b/web/app/components/base/features/new-feature-panel/annotation-reply/config-param-modal.tsx index 801f1348ee..6309498d20 100644 --- a/web/app/components/base/features/new-feature-panel/annotation-reply/config-param-modal.tsx +++ b/web/app/components/base/features/new-feature-panel/annotation-reply/config-param-modal.tsx @@ -18,6 +18,7 @@ type Props = { isShow: boolean onHide: () => void onSave: (embeddingModel: { + plugin_id: string embedding_provider_name: string embedding_model_name: string }, score: number) => void @@ -43,11 +44,13 @@ const ConfigParamModal: FC = ({ const [isLoading, setLoading] = useState(false) const [embeddingModel, setEmbeddingModel] = useState(oldAnnotationConfig.embedding_model ? { + plugin_id: oldAnnotationConfig.embedding_model.plugin_id, providerName: oldAnnotationConfig.embedding_model.embedding_provider_name, modelName: oldAnnotationConfig.embedding_model.embedding_model_name, } : (embeddingsDefaultModel ? { + plugin_id: embeddingsDefaultModel.provider.plugin_id, providerName: embeddingsDefaultModel.provider.provider, modelName: embeddingsDefaultModel.model, } @@ -67,6 +70,7 @@ const ConfigParamModal: FC = ({ } setLoading(true) await onSave({ + plugin_id: embeddingModel.plugin_id, embedding_provider_name: embeddingModel.providerName, embedding_model_name: embeddingModel.modelName, }, annotationConfig.score_threshold) @@ -107,12 +111,14 @@ const ConfigParamModal: FC = ({
{ setEmbeddingModel({ + plugin_id: val.plugin_id, providerName: val.provider, modelName: val.model, }) diff --git a/web/models/debug.ts b/web/models/debug.ts index 64a6cb7f84..fe85544fa7 100644 --- a/web/models/debug.ts +++ b/web/models/debug.ts @@ -93,6 +93,7 @@ export type AnnotationReplyConfig = { enabled: boolean score_threshold: number embedding_model: { + plugin_id: string embedding_provider_name: string embedding_model_name: string } diff --git a/web/service/annotation.ts b/web/service/annotation.ts index 5096a4f58a..868f82bedc 100644 --- a/web/service/annotation.ts +++ b/web/service/annotation.ts @@ -13,7 +13,9 @@ export const updateAnnotationStatus = (appId: string, action: AnnotationEnableSt if (embeddingModel) { body = { ...body, - ...embeddingModel, + embedding_model_plugin_id: embeddingModel.plugin_id, + embedding_provider_name: embeddingModel.embedding_provider_name, + embedding_model_name: embeddingModel.embedding_model_name, } }