fix: typos

This commit is contained in:
yoyocircle
2024-07-17 03:59:08 +00:00
parent 884e72b4f0
commit f6b4b4a361
5 changed files with 49 additions and 49 deletions

View File

@ -33,7 +33,7 @@ const Main: FC = () => {
* app info
*/
const [appUnavailable, setAppUnavailable] = useState<boolean>(false)
const [isUnknwonReason, setIsUnknwonReason] = useState<boolean>(false)
const [isUnknownReason, setIsUnknownReason] = useState<boolean>(false)
const [promptConfig, setPromptConfig] = useState<PromptConfig | null>(null)
const [inited, setInited] = useState<boolean>(false)
// in mobile, show sidebar by click button
@ -86,7 +86,7 @@ const Main: FC = () => {
setCurrInputs(inputs)
setChatStarted()
// parse variables in introduction
setChatList(generateNewChatListWithOpenstatement('', inputs))
setChatList(generateNewChatListWithOpenStatement('', inputs))
}
const hasSetInputs = (() => {
if (!isNewConversation)
@ -121,10 +121,10 @@ const Main: FC = () => {
}
// update chat list of current conversation
if (!isNewConversation && !conversationIdChangeBecauseOfNew && !isResponsing) {
if (!isNewConversation && !conversationIdChangeBecauseOfNew && !isResponding) {
fetchChatList(currConversationId).then((res: any) => {
const { data } = res
const newChatList: ChatItem[] = generateNewChatListWithOpenstatement(notSyncToStateIntroduction, notSyncToStateInputs)
const newChatList: ChatItem[] = generateNewChatListWithOpenStatement(notSyncToStateIntroduction, notSyncToStateInputs)
data.forEach((item: any) => {
newChatList.push({
@ -148,7 +148,7 @@ const Main: FC = () => {
}
if (isNewConversation && isChatStarted)
setChatList(generateNewChatListWithOpenstatement())
setChatList(generateNewChatListWithOpenStatement())
}
useEffect(handleConversationSwitch, [currConversationId, inited])
@ -176,7 +176,7 @@ const Main: FC = () => {
chatListDomRef.current.scrollTop = chatListDomRef.current.scrollHeight
}, [chatList, currConversationId])
// user can not edit inputs if user had send message
const canEditInpus = !chatList.some(item => item.isAnswer === false) && isNewConversation
const canEditInputs = !chatList.some(item => item.isAnswer === false) && isNewConversation
const createNewChat = () => {
// if new chat is already exist, do not create new chat
if (conversationList.some(item => item.id === '-1'))
@ -193,21 +193,21 @@ const Main: FC = () => {
}
// sometime introduction is not applied to state
const generateNewChatListWithOpenstatement = (introduction?: string, inputs?: Record<string, any> | null) => {
let caculatedIntroduction = introduction || conversationIntroduction || ''
const caculatedPromptVariables = inputs || currInputs || null
if (caculatedIntroduction && caculatedPromptVariables)
caculatedIntroduction = replaceVarWithValues(caculatedIntroduction, promptConfig?.prompt_variables || [], caculatedPromptVariables)
const generateNewChatListWithOpenStatement = (introduction?: string, inputs?: Record<string, any> | null) => {
let calculatedIntroduction = introduction || conversationIntroduction || ''
const calculatedPromptVariables = inputs || currInputs || null
if (calculatedIntroduction && calculatedPromptVariables)
calculatedIntroduction = replaceVarWithValues(calculatedIntroduction, promptConfig?.prompt_variables || [], calculatedPromptVariables)
const openstatement = {
id: `${Date.now()}`,
content: caculatedIntroduction,
content: calculatedIntroduction,
isAnswer: true,
feedbackDisabled: true,
isOpeningStatement: isShowPrompt,
}
if (caculatedIntroduction)
return [openstatement]
if (calculatedIntroduction)
return [openStatement]
return []
}
@ -255,14 +255,14 @@ const Main: FC = () => {
setAppUnavailable(true)
}
else {
setIsUnknwonReason(true)
setIsUnknownReason(true)
setAppUnavailable(true)
}
}
})()
}, [])
const [isResponsing, { setTrue: setResponsingTrue, setFalse: setResponsingFalse }] = useBoolean(false)
const [isResponding, { setTrue: setRespondingTrue, setFalse: setRespondingFalse }] = useBoolean(false)
const [abortController, setAbortController] = useState<AbortController | null>(null)
const { notify } = Toast
const logError = (message: string) => {
@ -279,8 +279,8 @@ const Main: FC = () => {
const inputLens = Object.values(currInputs).length
const promptVariablesLens = promptConfig.prompt_variables.length
const emytyInput = inputLens < promptVariablesLens || Object.values(currInputs).find(v => !v)
if (emytyInput) {
const emptyInput = inputLens < promptVariablesLens || Object.values(currInputs).find(v => !v)
if (emptyInput) {
logError(t('app.errorMessage.valueOfVarRequired'))
return false
}
@ -291,7 +291,7 @@ const Main: FC = () => {
const [openingSuggestedQuestions, setOpeningSuggestedQuestions] = useState<string[]>([])
const [messageTaskId, setMessageTaskId] = useState('')
const [hasStopResponded, setHasStopResponded, getHasStopResponded] = useGetState(false)
const [isResponsingConIsCurrCon, setIsResponsingConCurrCon, getIsResponsingConIsCurrCon] = useGetState(true)
const [isRespondingConIsCurrCon, setIsRespondingConCurrCon, getIsRespondingConIsCurrCon] = useGetState(true)
const [userQuery, setUserQuery] = useState('')
const updateCurrentQA = ({
@ -318,7 +318,7 @@ const Main: FC = () => {
}
const handleSend = async (message: string, files?: VisionFile[]) => {
if (isResponsing) {
if (isResponding) {
notify({ type: 'info', message: t('app.errorMessage.waitForResponse') })
return
}
@ -340,7 +340,7 @@ const Main: FC = () => {
})
}
// qustion
// question
const questionId = `question-${Date.now()}`
const questionItem = {
id: questionId,
@ -374,7 +374,7 @@ const Main: FC = () => {
const prevTempNewConversationId = getCurrConversationId() || '-1'
let tempNewConversationId = ''
setResponsingTrue()
setRespondingTrue()
sendChatMessage(data, {
getAbortController: (abortController) => {
setAbortController(abortController)
@ -399,7 +399,7 @@ const Main: FC = () => {
setMessageTaskId(taskId)
// has switched to other conversation
if (prevTempNewConversationId !== getCurrConversationId()) {
setIsResponsingConCurrCon(false)
setIsRespondingConCurrCon(false)
return
}
updateCurrentQA({
@ -426,7 +426,7 @@ const Main: FC = () => {
resetNewConversationInputs()
setChatNotStarted()
setCurrConversationId(tempNewConversationId, APP_ID, true)
setResponsingFalse()
setRespondingFalse()
},
onFile(file) {
const lastThought = responseItem.agent_thoughts?.[responseItem.agent_thoughts?.length - 1]
@ -465,7 +465,7 @@ const Main: FC = () => {
}
// has switched to other conversation
if (prevTempNewConversationId !== getCurrConversationId()) {
setIsResponsingConCurrCon(false)
setIsRespondingConCurrCon(false)
return false
}
@ -520,7 +520,7 @@ const Main: FC = () => {
))
},
onError() {
setResponsingFalse()
setRespondingFalse()
// role back placeholder answer
setChatList(produce(getChatList(), (draft) => {
draft.splice(draft.findIndex(item => item.id === placeholderAnswerId), 1)
@ -604,7 +604,7 @@ const Main: FC = () => {
}
if (appUnavailable)
return <AppUnavailable isUnknwonReason={isUnknwonReason} errMessage={!hasSetAppConfig ? 'Please set APP_ID and API_KEY in config/index.tsx' : ''} />
return <AppUnavailable isUnknownReason={isUnknownReason} errMessage={!hasSetAppConfig ? 'Please set APP_ID and API_KEY in config/index.tsx' : ''} />
if (!APP_ID || !APP_INFO || !promptConfig)
return <Loading type='app' />
@ -639,7 +639,7 @@ const Main: FC = () => {
siteInfo={APP_INFO}
promptConfig={promptConfig}
onStartChat={handleStartChat}
canEidtInpus={canEditInpus}
canEditInputs={canEditInputs}
savedInputs={currInputs as Record<string, any>}
onInputsChange={setCurrInputs}
></ConfigSence>
@ -652,7 +652,7 @@ const Main: FC = () => {
chatList={chatList}
onSend={handleSend}
onFeedback={handleFeedback}
isResponsing={isResponsing}
isResponding={isResponding}
checkCanSend={checkCanSend}
visionConfig={visionConfig}
/>