annotation config

This commit is contained in:
JzoNg 2024-10-31 08:43:12 +08:00
parent 339dfe5e02
commit 633768cd2a
7 changed files with 14 additions and 172 deletions

View File

@ -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 { Settings04 } from '@/app/components/base/icons/src/vender/line/general'
import type { App } from '@/types/app' import type { App } from '@/types/app'
interface Props { type Props = {
appDetail: App appDetail: App
} }
@ -283,6 +283,7 @@ const Annotation: FC<Props> = ({
if ( if (
embeddingModel.embedding_model_name !== annotationConfig?.embedding_model?.embedding_model_name embeddingModel.embedding_model_name !== annotationConfig?.embedding_model?.embedding_model_name
|| embeddingModel.embedding_provider_name !== annotationConfig?.embedding_model?.embedding_provider_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) const { job_id: jobId }: any = await updateAnnotationStatus(appDetail.id, AnnotationEnableStatus.enable, embeddingModel, score)
await ensureJobCompleted(jobId, AnnotationEnableStatus.enable) await ensureJobCompleted(jobId, AnnotationEnableStatus.enable)

View File

@ -23,8 +23,9 @@ export type HitHistoryItem = {
} }
export type EmbeddingModelConfig = { export type EmbeddingModelConfig = {
embedding_provider_name: string plugin_id: string
embedding_model_name: string embedding_model_name: string
embedding_provider_name: string
} }
export enum AnnotationEnableStatus { export enum AnnotationEnableStatus {

View File

@ -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 (
<div>
<div className='flex items-center space-x-1'>
<div>{title}</div>
<Tooltip
popupContent={
<div className='max-w-[200px] leading-[18px] text-[13px] font-medium text-gray-800'>{tooltip}</div>
}
/>
</div>
<div>{children}</div>
</div>
)
}
const AnnotationReplyConfig: FC<Props> = ({
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 (
<>
<Panel
className="mt-4"
headerIcon={
<MessageFast className='w-4 h-4 text-[#444CE7]' />
}
title={t('appDebug.feature.annotation.title')}
headerRight={
<div className='flex items-center'>
<div
className='flex items-center rounded-md h-7 px-3 space-x-1 text-gray-700 cursor-pointer hover:bg-gray-200'
onClick={() => { setIsShowEdit(true) }}
>
<Settings04 className="w-[14px] h-[14px]" />
<div className='text-xs font-medium'>
{t('common.operation.params')}
</div>
</div>
<div
className='ml-1 flex items-center h-7 px-3 space-x-1 leading-[18px] text-xs font-medium text-gray-700 rounded-md cursor-pointer hover:bg-gray-200'
onClick={() => {
router.push(`/app/${appId}/annotations`)
}}>
<div>{t('appDebug.feature.annotation.cacheManagement')}</div>
<LinkExternal02 className='w-3.5 h-3.5' />
</div>
</div>
}
noBodySpacing
/>
{isShowEdit && (
<ConfigParamModal
appId={appId}
isShow
onHide={() => {
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)

View File

@ -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<ToolboxProps> = ({
showModerationSettings,
showAnnotation,
onEmbeddingChange,
onScoreChange,
}) => {
const { t } = useTranslation()
return (
<div className='mt-7'>
<GroupName name={t('appDebug.feature.toolbox.title')} />
{
showModerationSettings && (
<Moderation />
)
}
{
showAnnotation && (
<Annotation
onEmbeddingChange={onEmbeddingChange}
onScoreChange={onScoreChange}
/>
)
}
</div>
)
}
export default React.memo(Toolbox)

View File

@ -18,6 +18,7 @@ type Props = {
isShow: boolean isShow: boolean
onHide: () => void onHide: () => void
onSave: (embeddingModel: { onSave: (embeddingModel: {
plugin_id: string
embedding_provider_name: string embedding_provider_name: string
embedding_model_name: string embedding_model_name: string
}, score: number) => void }, score: number) => void
@ -43,11 +44,13 @@ const ConfigParamModal: FC<Props> = ({
const [isLoading, setLoading] = useState(false) const [isLoading, setLoading] = useState(false)
const [embeddingModel, setEmbeddingModel] = useState(oldAnnotationConfig.embedding_model const [embeddingModel, setEmbeddingModel] = useState(oldAnnotationConfig.embedding_model
? { ? {
plugin_id: oldAnnotationConfig.embedding_model.plugin_id,
providerName: oldAnnotationConfig.embedding_model.embedding_provider_name, providerName: oldAnnotationConfig.embedding_model.embedding_provider_name,
modelName: oldAnnotationConfig.embedding_model.embedding_model_name, modelName: oldAnnotationConfig.embedding_model.embedding_model_name,
} }
: (embeddingsDefaultModel : (embeddingsDefaultModel
? { ? {
plugin_id: embeddingsDefaultModel.provider.plugin_id,
providerName: embeddingsDefaultModel.provider.provider, providerName: embeddingsDefaultModel.provider.provider,
modelName: embeddingsDefaultModel.model, modelName: embeddingsDefaultModel.model,
} }
@ -67,6 +70,7 @@ const ConfigParamModal: FC<Props> = ({
} }
setLoading(true) setLoading(true)
await onSave({ await onSave({
plugin_id: embeddingModel.plugin_id,
embedding_provider_name: embeddingModel.providerName, embedding_provider_name: embeddingModel.providerName,
embedding_model_name: embeddingModel.modelName, embedding_model_name: embeddingModel.modelName,
}, annotationConfig.score_threshold) }, annotationConfig.score_threshold)
@ -107,12 +111,14 @@ const ConfigParamModal: FC<Props> = ({
<div className='pt-1'> <div className='pt-1'>
<ModelSelector <ModelSelector
defaultModel={embeddingModel && { defaultModel={embeddingModel && {
plugin_id: '',
provider: embeddingModel.providerName, provider: embeddingModel.providerName,
model: embeddingModel.modelName, model: embeddingModel.modelName,
}} }}
modelList={embeddingsModelList} modelList={embeddingsModelList}
onSelect={(val) => { onSelect={(val) => {
setEmbeddingModel({ setEmbeddingModel({
plugin_id: val.plugin_id,
providerName: val.provider, providerName: val.provider,
modelName: val.model, modelName: val.model,
}) })

View File

@ -93,6 +93,7 @@ export type AnnotationReplyConfig = {
enabled: boolean enabled: boolean
score_threshold: number score_threshold: number
embedding_model: { embedding_model: {
plugin_id: string
embedding_provider_name: string embedding_provider_name: string
embedding_model_name: string embedding_model_name: string
} }

View File

@ -13,7 +13,9 @@ export const updateAnnotationStatus = (appId: string, action: AnnotationEnableSt
if (embeddingModel) { if (embeddingModel) {
body = { body = {
...body, ...body,
...embeddingModel, embedding_model_plugin_id: embeddingModel.plugin_id,
embedding_provider_name: embeddingModel.embedding_provider_name,
embedding_model_name: embeddingModel.embedding_model_name,
} }
} }