'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)