feat: annotation management frontend (#1764)

This commit is contained in:
Joel
2023-12-18 15:41:24 +08:00
committed by GitHub
parent 96d2de2258
commit 65fd4b39ce
122 changed files with 4718 additions and 214 deletions

View File

@@ -1,6 +1,7 @@
import { createContext } from 'use-context-selector'
import { PromptMode } from '@/models/debug'
import type {
AnnotationReplyConfig,
BlockStatus,
ChatPromptConfig,
CitationConfig,
@@ -21,7 +22,7 @@ import type { ExternalDataTool } from '@/models/common'
import type { DataSet } from '@/models/datasets'
import type { VisionSettings } from '@/types/app'
import { ModelModeType, RETRIEVE_TYPE, Resolution, TransferMethod } from '@/types/app'
import { DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config'
import { ANNOTATION_DEFAULT, DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config'
type IDebugConfiguration = {
appId: string
@@ -58,6 +59,8 @@ type IDebugConfiguration = {
setSpeechToTextConfig: (speechToTextConfig: SpeechToTextConfig) => void
citationConfig: CitationConfig
setCitationConfig: (citationConfig: CitationConfig) => void
annotationConfig: AnnotationReplyConfig
setAnnotationConfig: (annotationConfig: AnnotationReplyConfig) => void
moderationConfig: ModerationConfig
setModerationConfig: (moderationConfig: ModerationConfig) => void
externalDataToolsConfig: ExternalDataTool[]
@@ -138,13 +141,23 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
citationConfig: {
enabled: false,
},
setCitationConfig: () => {},
setCitationConfig: () => { },
moderationConfig: {
enabled: false,
},
setModerationConfig: () => {},
annotationConfig: {
id: '',
enabled: false,
score_threshold: ANNOTATION_DEFAULT.score_threshold,
embedding_model: {
embedding_model_name: '',
embedding_provider_name: '',
},
},
setAnnotationConfig: () => { },
setModerationConfig: () => { },
externalDataToolsConfig: [],
setExternalDataToolsConfig: () => {},
setExternalDataToolsConfig: () => { },
formattingChanged: false,
setFormattingChanged: () => { },
inputs: {},
@@ -189,7 +202,7 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
score_threshold_enabled: false,
score_threshold: 0.7,
},
setDatasetConfigs: () => {},
setDatasetConfigs: () => { },
hasSetContextVar: false,
isShowVisionConfig: false,
visionConfig: {
@@ -198,7 +211,7 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
detail: Resolution.low,
transfer_methods: [TransferMethod.remote_url],
},
setVisionConfig: () => {},
setVisionConfig: () => { },
})
export default DebugConfigurationContext

View File

@@ -8,6 +8,8 @@ import AccountSetting from '@/app/components/header/account-setting'
import ApiBasedExtensionModal from '@/app/components/header/account-setting/api-based-extension-page/modal'
import ModerationSettingModal from '@/app/components/app/configuration/toolbox/moderation/moderation-setting-modal'
import ExternalDataToolModal from '@/app/components/app/configuration/tools/external-data-tool-modal'
import AnnotationFullModal from '@/app/components/billing/annotation-full/modal'
import Pricing from '@/app/components/billing/pricing'
import type { ModerationConfig } from '@/models/debug'
import type {
@@ -28,13 +30,15 @@ const ModalContext = createContext<{
setShowModerationSettingModal: Dispatch<SetStateAction<ModalState<ModerationConfig> | null>>
setShowExternalDataToolModal: Dispatch<SetStateAction<ModalState<ExternalDataTool> | null>>
setShowPricingModal: Dispatch<SetStateAction<any>>
setShowAnnotationFullModal: () => void
}>({
setShowAccountSettingModal: () => {},
setShowApiBasedExtensionModal: () => {},
setShowModerationSettingModal: () => {},
setShowExternalDataToolModal: () => {},
setShowPricingModal: () => {},
})
setShowAccountSettingModal: () => { },
setShowApiBasedExtensionModal: () => { },
setShowModerationSettingModal: () => { },
setShowExternalDataToolModal: () => { },
setShowPricingModal: () => { },
setShowAnnotationFullModal: () => { },
})
export const useModalContext = () => useContext(ModalContext)
@@ -51,7 +55,7 @@ export const ModalContextProvider = ({
const searchParams = useSearchParams()
const router = useRouter()
const [showPricingModal, setShowPricingModal] = useState(searchParams.get('show-pricing') === '1')
const [showAnnotationFullModal, setShowAnnotationFullModal] = useState(false)
const handleCancelAccountSettingModal = () => {
setShowAccountSettingModal(null)
@@ -101,6 +105,7 @@ export const ModalContextProvider = ({
setShowModerationSettingModal,
setShowExternalDataToolModal,
setShowPricingModal: () => setShowPricingModal(true),
setShowAnnotationFullModal: () => setShowAnnotationFullModal(true),
}}>
<>
{children}
@@ -152,6 +157,14 @@ export const ModalContextProvider = ({
}} />
)
}
{
showAnnotationFullModal && (
<AnnotationFullModal
show={showAnnotationFullModal}
onHide={() => setShowAnnotationFullModal(false)} />
)
}
</>
</ModalContext.Provider>
)

View File

@@ -22,6 +22,7 @@ const ProviderContext = createContext<{
textGenerationDefaultModel?: BackendModel
mutateTextGenerationDefaultModel: () => void
embeddingsDefaultModel?: BackendModel
isEmbeddingsDefaultModelValid: boolean
mutateEmbeddingsDefaultModel: () => void
speech2textDefaultModel?: BackendModel
mutateSpeech2textDefaultModel: () => void
@@ -42,16 +43,17 @@ const ProviderContext = createContext<{
speech2textModelList: [],
rerankModelList: [],
agentThoughtModelList: [],
updateModelList: () => {},
updateModelList: () => { },
textGenerationDefaultModel: undefined,
mutateTextGenerationDefaultModel: () => {},
mutateTextGenerationDefaultModel: () => { },
speech2textDefaultModel: undefined,
mutateSpeech2textDefaultModel: () => {},
mutateSpeech2textDefaultModel: () => { },
embeddingsDefaultModel: undefined,
mutateEmbeddingsDefaultModel: () => {},
isEmbeddingsDefaultModelValid: false,
mutateEmbeddingsDefaultModel: () => { },
rerankDefaultModel: undefined,
isRerankDefaultModelVaild: false,
mutateRerankDefaultModel: () => {},
mutateRerankDefaultModel: () => { },
supportRetrievalMethods: [],
plan: {
type: Plan.sandbox,
@@ -59,11 +61,13 @@ const ProviderContext = createContext<{
vectorSpace: 32,
buildApps: 12,
teamMembers: 1,
annotatedResponse: 1,
},
total: {
vectorSpace: 200,
buildApps: 50,
teamMembers: 1,
annotatedResponse: 10,
},
},
isFetchedPlan: false,
@@ -97,6 +101,10 @@ export const ProviderContextProvider = ({
item => item.model_name === rerankDefaultModel?.model_name && item.model_provider.provider_name === rerankDefaultModel?.model_provider.provider_name,
)
const isEmbeddingsDefaultModelValid = !!embeddingsModelList?.find(
item => item.model_name === embeddingsDefaultModel?.model_name && item.model_provider.provider_name === embeddingsDefaultModel?.model_provider.provider_name,
)
const updateModelList = (type: ModelType) => {
if (type === ModelType.textGeneration)
mutateTextGenerationModelList()
@@ -118,6 +126,13 @@ export const ProviderContextProvider = ({
setEnableBilling(enabled)
if (enabled) {
setPlan(parseCurrentPlan(data))
// setPlan(parseCurrentPlan({
// ...data,
// annotation_quota_limit: {
// ...data.annotation_quota_limit,
// limit: 10,
// },
// }))
setIsFetchedPlan(true)
}
})()
@@ -139,6 +154,7 @@ export const ProviderContextProvider = ({
mutateSpeech2textDefaultModel,
rerankDefaultModel,
isRerankDefaultModelVaild,
isEmbeddingsDefaultModelValid,
mutateRerankDefaultModel,
supportRetrievalMethods: supportRetrievalMethods?.retrieval_method || [],
plan,