wwf
3 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'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)