refactor & perf: import { noop } from 'lodash-es' across web (#17439)

This commit is contained in:
yusheng chen
2025-04-06 17:56:08 +08:00
committed by GitHub
parent 7016ccef10
commit c05e03fc09
87 changed files with 271 additions and 184 deletions

View File

@@ -12,6 +12,7 @@ import type { ICurrentWorkspace, LangGeniusVersionResponse, UserProfileResponse
import MaintenanceNotice from '@/app/components/header/maintenance-notice'
import type { SystemFeatures } from '@/types/feature'
import { defaultSystemFeatures } from '@/types/feature'
import { noop } from 'lodash-es'
export type AppContextValue = {
apps: App[]
@@ -54,7 +55,7 @@ const initialWorkspaceInfo: ICurrentWorkspace = {
const AppContext = createContext<AppContextValue>({
systemFeatures: defaultSystemFeatures,
apps: [],
mutateApps: () => { },
mutateApps: noop,
userProfile: {
id: '',
name: '',
@@ -68,8 +69,8 @@ const AppContext = createContext<AppContextValue>({
isCurrentWorkspaceOwner: false,
isCurrentWorkspaceEditor: false,
isCurrentWorkspaceDatasetOperator: false,
mutateUserProfile: () => { },
mutateCurrentWorkspace: () => { },
mutateUserProfile: noop,
mutateCurrentWorkspace: noop,
pageContainerRef: createRef(),
langeniusVersionInfo: initialLangeniusVersionInfo,
useSelector,

View File

@@ -2,6 +2,7 @@
import { createContext, useContext } from 'use-context-selector'
import type { DataSet } from '@/models/datasets'
import { noop } from 'lodash-es'
export type DatasetsContextValue = {
datasets: DataSet[]
@@ -11,7 +12,7 @@ export type DatasetsContextValue = {
const DatasetsContext = createContext<DatasetsContextValue>({
datasets: [],
mutateDatasets: () => {},
mutateDatasets: noop,
currentDataset: undefined,
})

View File

@@ -26,6 +26,7 @@ import { ModelModeType, RETRIEVE_TYPE, Resolution, TransferMethod } from '@/type
import { ANNOTATION_DEFAULT, DEFAULT_AGENT_SETTING, DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config'
import type { FormValue } from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { Collection } from '@/app/components/tools/types'
import { noop } from 'lodash-es'
type IDebugConfiguration = {
appId: string
@@ -112,64 +113,64 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
mode: '',
modelModeType: ModelModeType.chat,
promptMode: PromptMode.simple,
setPromptMode: () => { },
setPromptMode: noop,
isAdvancedMode: false,
isAgent: false,
isFunctionCall: false,
isOpenAI: false,
collectionList: [],
canReturnToSimpleMode: false,
setCanReturnToSimpleMode: () => { },
setCanReturnToSimpleMode: noop,
chatPromptConfig: DEFAULT_CHAT_PROMPT_CONFIG,
completionPromptConfig: DEFAULT_COMPLETION_PROMPT_CONFIG,
currentAdvancedPrompt: [],
showHistoryModal: () => { },
showHistoryModal: noop,
conversationHistoriesRole: {
user_prefix: 'user',
assistant_prefix: 'assistant',
},
setConversationHistoriesRole: () => { },
setCurrentAdvancedPrompt: () => { },
setConversationHistoriesRole: noop,
setCurrentAdvancedPrompt: noop,
hasSetBlockStatus: {
context: false,
history: false,
query: false,
},
conversationId: '',
setConversationId: () => { },
setConversationId: noop,
introduction: '',
setIntroduction: () => { },
setIntroduction: noop,
suggestedQuestions: [],
setSuggestedQuestions: () => { },
setSuggestedQuestions: noop,
controlClearChatMessage: 0,
setControlClearChatMessage: () => { },
setControlClearChatMessage: noop,
prevPromptConfig: {
prompt_template: '',
prompt_variables: [],
},
setPrevPromptConfig: () => { },
setPrevPromptConfig: noop,
moreLikeThisConfig: {
enabled: false,
},
setMoreLikeThisConfig: () => { },
setMoreLikeThisConfig: noop,
suggestedQuestionsAfterAnswerConfig: {
enabled: false,
},
setSuggestedQuestionsAfterAnswerConfig: () => { },
setSuggestedQuestionsAfterAnswerConfig: noop,
speechToTextConfig: {
enabled: false,
},
setSpeechToTextConfig: () => { },
setSpeechToTextConfig: noop,
textToSpeechConfig: {
enabled: false,
voice: '',
language: '',
},
setTextToSpeechConfig: () => { },
setTextToSpeechConfig: noop,
citationConfig: {
enabled: false,
},
setCitationConfig: () => { },
setCitationConfig: noop,
moderationConfig: {
enabled: false,
},
@@ -182,16 +183,16 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
embedding_provider_name: '',
},
},
setAnnotationConfig: () => { },
setModerationConfig: () => { },
setAnnotationConfig: noop,
setModerationConfig: noop,
externalDataToolsConfig: [],
setExternalDataToolsConfig: () => { },
setExternalDataToolsConfig: noop,
formattingChanged: false,
setFormattingChanged: () => { },
setFormattingChanged: noop,
inputs: {},
setInputs: () => { },
setInputs: noop,
query: '',
setQuery: () => { },
setQuery: noop,
completionParams: {
max_tokens: 16,
temperature: 1, // 0-2
@@ -199,7 +200,7 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
presence_penalty: 1, // -2-2
frequency_penalty: 1, // -2-2
},
setCompletionParams: () => { },
setCompletionParams: noop,
modelConfig: {
provider: 'OPENAI', // 'OPENAI'
model_id: 'gpt-3.5-turbo', // 'gpt-3.5-turbo'
@@ -221,10 +222,10 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
dataSets: [],
agentConfig: DEFAULT_AGENT_SETTING,
},
setModelConfig: () => { },
setModelConfig: noop,
dataSets: [],
showSelectDataSet: () => { },
setDataSets: () => { },
showSelectDataSet: noop,
setDataSets: noop,
datasetConfigs: {
retrieval_model: RETRIEVE_TYPE.multiWay,
reranking_model: {
@@ -241,7 +242,7 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
datasetConfigsRef: {
current: null,
},
setDatasetConfigs: () => { },
setDatasetConfigs: noop,
hasSetContextVar: false,
isShowVisionConfig: false,
visionConfig: {
@@ -250,11 +251,11 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
detail: Resolution.low,
transfer_methods: [TransferMethod.remote_url],
},
setVisionConfig: () => { },
setVisionConfig: noop,
isAllowVideoUpload: false,
isShowDocumentConfig: false,
rerankSettingModalOpen: false,
setRerankSettingModalOpen: () => { },
setRerankSettingModalOpen: noop,
})
export const useDebugConfigurationContext = () => useContext(DebugConfigurationContext)

View File

@@ -1,5 +1,6 @@
import { createContext } from 'use-context-selector'
import type { InstalledApp } from '@/models/explore'
import { noop } from 'lodash-es'
type IExplore = {
controlUpdateInstalledApps: number
@@ -11,10 +12,10 @@ type IExplore = {
const ExploreContext = createContext<IExplore>({
controlUpdateInstalledApps: 0,
setControlUpdateInstalledApps: () => { },
setControlUpdateInstalledApps: noop,
hasEditPermission: false,
installedApps: [],
setInstalledApps: () => { },
setInstalledApps: noop,
})
export default ExploreContext

View File

@@ -36,6 +36,7 @@ import type { InputVar } from '@/app/components/workflow/types'
import type { UpdatePluginPayload } from '@/app/components/plugins/types'
import UpdatePlugin from '@/app/components/plugins/update-plugin'
import { removeSpecificQueryParam } from '@/utils'
import { noop } from 'lodash-es'
export type ModalState<T> = {
payload: T
@@ -77,18 +78,18 @@ export type ModalContextState = {
setShowUpdatePluginModal: Dispatch<SetStateAction<ModalState<UpdatePluginPayload> | null>>
}
const ModalContext = createContext<ModalContextState>({
setShowAccountSettingModal: () => { },
setShowApiBasedExtensionModal: () => { },
setShowModerationSettingModal: () => { },
setShowExternalDataToolModal: () => { },
setShowPricingModal: () => { },
setShowAnnotationFullModal: () => { },
setShowModelModal: () => { },
setShowExternalKnowledgeAPIModal: () => { },
setShowModelLoadBalancingModal: () => { },
setShowModelLoadBalancingEntryModal: () => { },
setShowOpeningModal: () => { },
setShowUpdatePluginModal: () => { },
setShowAccountSettingModal: noop,
setShowApiBasedExtensionModal: noop,
setShowModerationSettingModal: noop,
setShowExternalDataToolModal: noop,
setShowPricingModal: noop,
setShowAnnotationFullModal: noop,
setShowModelModal: noop,
setShowExternalKnowledgeAPIModal: noop,
setShowModelLoadBalancingModal: noop,
setShowModelLoadBalancingEntryModal: noop,
setShowOpeningModal: noop,
setShowUpdatePluginModal: noop,
})
export const useModalContext = () => useContext(ModalContext)

View File

@@ -25,6 +25,7 @@ import Toast from '@/app/components/base/toast'
import {
useEducationStatus,
} from '@/service/use-education'
import { noop } from 'lodash-es'
type ProviderContextState = {
modelProviders: ModelProvider[]
@@ -49,7 +50,7 @@ type ProviderContextState = {
}
const ProviderContext = createContext<ProviderContextState>({
modelProviders: [],
refreshModelProviders: () => { },
refreshModelProviders: noop,
textGenerationModelList: [],
supportRetrievalMethods: [],
isAPIKeySet: true,
@@ -72,7 +73,7 @@ const ProviderContext = createContext<ProviderContextState>({
},
isFetchedPlan: false,
enableBilling: false,
onPlanInfoChanged: () => { },
onPlanInfoChanged: noop,
enableReplaceWebAppLogo: false,
modelLoadBalancingEnabled: false,
datasetOperatorEnabled: false,