Commit d37b7124 by 杨明

自动滚动

1 parent ef14c1db
...@@ -25,13 +25,14 @@ type AnswerProps = { ...@@ -25,13 +25,14 @@ type AnswerProps = {
answerIcon?: ReactNode answerIcon?: ReactNode
responding?: boolean responding?: boolean
showPromptLog?: boolean showPromptLog?: boolean
isLast?: boolean
chatAnswerContainerInner?: string chatAnswerContainerInner?: string
hideProcessDetail?: boolean hideProcessDetail?: boolean
appData?: AppData appData?: AppData
noChatInput?: boolean noChatInput?: boolean
switchSibling?: (siblingMessageId: string) => void switchSibling?: (siblingMessageId: string) => void
} }
const Answer: FC<AnswerProps> = ({ item, question, index, config, answerIcon, responding, showPromptLog, chatAnswerContainerInner, hideProcessDetail, appData, noChatInput, switchSibling }) => { const Answer: FC<AnswerProps> = ({ item, question, index, config, answerIcon, responding, showPromptLog, isLast, chatAnswerContainerInner, hideProcessDetail, appData, noChatInput, switchSibling }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { content, citation, agent_thoughts, more, annotation, workflowProcess, allFiles, message_files } = item const { content, citation, agent_thoughts, more, annotation, workflowProcess, allFiles, message_files } = item
const hasAgentThoughts = !!agent_thoughts?.length const hasAgentThoughts = !!agent_thoughts?.length
...@@ -81,7 +82,7 @@ const Answer: FC<AnswerProps> = ({ item, question, index, config, answerIcon, re ...@@ -81,7 +82,7 @@ const Answer: FC<AnswerProps> = ({ item, question, index, config, answerIcon, re
<div className="chat-answer-container group ml-4 w-0 grow pb-4" ref={containerRef}> <div className="chat-answer-container group ml-4 w-0 grow pb-4" ref={containerRef}>
<div className={cn('group relative pr-10', chatAnswerContainerInner)}> <div className={cn('group relative pr-10', chatAnswerContainerInner)}>
<div ref={contentRef} className={cn('body-lg-regular relative inline-block max-w-full rounded-2xl bg-chat-bubble-bg px-4 py-3 text-text-primary', workflowProcess && 'w-full')}> <div ref={contentRef} className={cn('body-lg-regular relative inline-block max-w-full rounded-2xl bg-chat-bubble-bg px-4 py-3 text-text-primary', workflowProcess && 'w-full')}>
{!responding && <Operation hasWorkflowProcess={!!workflowProcess} maxSize={containerWidth - contentWidth - 4} contentWidth={contentWidth} item={item} question={question} index={index} showPromptLog={showPromptLog} noChatInput={noChatInput} />} {!responding && <Operation hasWorkflowProcess={!!workflowProcess} maxSize={containerWidth - contentWidth - 4} contentWidth={contentWidth} item={item} isLast={isLast} question={question} index={index} showPromptLog={showPromptLog} noChatInput={noChatInput} />}
{/** Render the normal steps */} {/** Render the normal steps */}
{/* {workflowProcess && !hideProcessDetail && ( {/* {workflowProcess && !hideProcessDetail && (
<WorkflowProcessItem <WorkflowProcessItem
...@@ -118,7 +119,7 @@ const Answer: FC<AnswerProps> = ({ item, question, index, config, answerIcon, re ...@@ -118,7 +119,7 @@ const Answer: FC<AnswerProps> = ({ item, question, index, config, answerIcon, re
)} */} )} */}
<SuggestedQuestions item={item} /> <SuggestedQuestions item={item} />
{!!citation?.length && !responding && <Citation data={citation} showHitInfo={config?.supportCitationHitInfo} />} {!!citation?.length && !responding && <Citation data={citation} showHitInfo={config?.supportCitationHitInfo} />}
{item.siblingCount && item.siblingCount > 1 && item.siblingIndex !== undefined && ( {/* {item.siblingCount && item.siblingCount > 1 && item.siblingIndex !== undefined && (
<div className="flex items-center justify-center pt-3.5 text-sm"> <div className="flex items-center justify-center pt-3.5 text-sm">
<button className={`${item.prevSibling ? 'opacity-100' : 'opacity-30'}`} disabled={!item.prevSibling} onClick={() => item.prevSibling && switchSibling?.(item.prevSibling)}> <button className={`${item.prevSibling ? 'opacity-100' : 'opacity-30'}`} disabled={!item.prevSibling} onClick={() => item.prevSibling && switchSibling?.(item.prevSibling)}>
<ChevronRight className="h-[14px] w-[14px] rotate-180 text-text-primary" /> <ChevronRight className="h-[14px] w-[14px] rotate-180 text-text-primary" />
...@@ -130,7 +131,7 @@ const Answer: FC<AnswerProps> = ({ item, question, index, config, answerIcon, re ...@@ -130,7 +131,7 @@ const Answer: FC<AnswerProps> = ({ item, question, index, config, answerIcon, re
<ChevronRight className="h-[14px] w-[14px] text-text-primary" /> <ChevronRight className="h-[14px] w-[14px] text-text-primary" />
</button> </button>
</div> </div>
)} )} */}
</div> </div>
</div> </div>
<More more={more} /> <More more={more} />
......
...@@ -18,14 +18,16 @@ type OperationProps = { ...@@ -18,14 +18,16 @@ type OperationProps = {
index: number index: number
showPromptLog?: boolean showPromptLog?: boolean
maxSize: number maxSize: number
isLast?: boolean
contentWidth: number contentWidth: number
hasWorkflowProcess: boolean hasWorkflowProcess: boolean
noChatInput?: boolean noChatInput?: boolean
} }
const Operation: FC<OperationProps> = ({ item, question, index, showPromptLog, maxSize, contentWidth, hasWorkflowProcess, noChatInput }) => { const Operation: FC<OperationProps> = ({ item, isLast, question, index, showPromptLog, maxSize, contentWidth, hasWorkflowProcess, noChatInput }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { config, onAnnotationAdded, onAnnotationEdited, onAnnotationRemoved, onFeedback, onRegenerate } = useChatContext() const { config, onAnnotationAdded, onAnnotationEdited, onAnnotationRemoved, onFeedback, onRegenerate } = useChatContext()
const [isShowReplyModal, setIsShowReplyModal] = useState(false) const [isShowReplyModal, setIsShowReplyModal] = useState(false)
const [showLike, setShowLike] = useState(false)
const { id, isOpeningStatement, content: messageContent, annotation, feedback, adminFeedback, agent_thoughts } = item const { id, isOpeningStatement, content: messageContent, annotation, feedback, adminFeedback, agent_thoughts } = item
const [localFeedback, setLocalFeedback] = useState(config?.supportAnnotation ? adminFeedback : feedback) const [localFeedback, setLocalFeedback] = useState(config?.supportAnnotation ? adminFeedback : feedback)
...@@ -36,10 +38,15 @@ const Operation: FC<OperationProps> = ({ item, question, index, showPromptLog, m ...@@ -36,10 +38,15 @@ const Operation: FC<OperationProps> = ({ item, question, index, showPromptLog, m
}, [agent_thoughts, messageContent]) }, [agent_thoughts, messageContent])
const handleFeedback = async (rating: 'like' | 'dislike' | null) => { const handleFeedback = async (rating: 'like' | 'dislike' | null) => {
if (!config?.supportFeedback || !onFeedback) return if (!config?.supportFeedback || !onFeedback || showLike) return
setShowLike(true)
await onFeedback?.(id, { rating }) await onFeedback?.(id, { rating })
setShowLike(false)
setLocalFeedback({ rating }) setLocalFeedback({ rating })
Toast.notify({
type: 'success',
message: '成功',
})
} }
const operationWidth = useMemo(() => { const operationWidth = useMemo(() => {
...@@ -71,12 +78,12 @@ const Operation: FC<OperationProps> = ({ item, question, index, showPromptLog, m ...@@ -71,12 +78,12 @@ const Operation: FC<OperationProps> = ({ item, question, index, showPromptLog, m
copy(content) copy(content)
Toast.notify({ Toast.notify({
type: 'success', type: 'success',
message: t('common.actionMsg.copySuccessfully'), message: '复制成功',
}) })
}}> }}>
<RiClipboardLine className="h-4 w-4" /> <RiClipboardLine className="h-4 w-4" />
</ActionButton> </ActionButton>
{!noChatInput && ( {!noChatInput && isLast && (
<ActionButton onClick={() => onRegenerate?.(item)}> <ActionButton onClick={() => onRegenerate?.(item)}>
<RiResetLeftLine className="h-4 w-4" /> <RiResetLeftLine className="h-4 w-4" />
</ActionButton> </ActionButton>
......
...@@ -79,13 +79,11 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF ...@@ -79,13 +79,11 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF
const chatFooterRef = useRef<HTMLDivElement>(null) const chatFooterRef = useRef<HTMLDivElement>(null)
const chatFooterInnerRef = useRef<HTMLDivElement>(null) const chatFooterInnerRef = useRef<HTMLDivElement>(null)
const userScrolledRef = useRef(false) const userScrolledRef = useRef(false)
const isProgrammaticScroll = useRef(false) // 标记是否是代码触发的滚动
const handleScrollToBottom = useCallback(() => { const handleScrollToBottom = useCallback(() => {
if (chatList.length > 1 && chatContainerRef.current) { if (chatList.length > 1 && chatContainerRef.current && !userScrolledRef.current) {
chatContainerRef.current.scrollTo({ chatContainerRef.current.scrollTop = chatContainerRef.current.scrollHeight
top: chatContainerRef.current.scrollHeight, isProgrammaticScroll.current = true // 先标记为代码触发
behavior: 'smooth',
})
} }
}, [chatList.length]) }, [chatList.length])
...@@ -148,7 +146,18 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF ...@@ -148,7 +146,18 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF
const chatContainer = chatContainerRef.current const chatContainer = chatContainerRef.current
if (chatContainer) { if (chatContainer) {
const setUserScrolled = () => { const setUserScrolled = () => {
if (chatContainer) userScrolledRef.current = chatContainer.scrollHeight - chatContainer.scrollTop > chatContainer.clientHeight if (isProgrammaticScroll.current && chatContainer) {
// 如果是代码触发的滚动,重置标志
isProgrammaticScroll.current = false
userScrolledRef.current = false
} else {
// 否则就是用户手动滚动
userScrolledRef.current = true
}
if (chatContainer) {
// console.log(chatContainer.scrollHeight - chatContainer.scrollTop, chatContainer.clientHeight, 'userScrolledRef.current')
// userScrolledRef.current = chatContainer.scrollHeight - chatContainer.scrollTop > chatContainer.clientHeight
}
} }
chatContainer.addEventListener('scroll', setUserScrolled) chatContainer.addEventListener('scroll', setUserScrolled)
return () => chatContainer.removeEventListener('scroll', setUserScrolled) return () => chatContainer.removeEventListener('scroll', setUserScrolled)
...@@ -160,9 +169,14 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF ...@@ -160,9 +169,14 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF
}, [sidebarCollapseState]) }, [sidebarCollapseState])
const hasTryToAsk = config?.suggested_questions_after_answer?.enabled && !!suggestedQuestions?.length && onSend const hasTryToAsk = config?.suggested_questions_after_answer?.enabled && !!suggestedQuestions?.length && onSend
const handleSend: OnSend = (query, files) => {
if (onSend) {
onSend(query, files)
}
userScrolledRef.current = false
}
return ( return (
<ChatContextProvider config={config} chatList={chatList} isResponding={isResponding} showPromptLog={showPromptLog} questionIcon={questionIcon} answerIcon={answerIcon} onSend={onSend} onRegenerate={onRegenerate} onAnnotationAdded={onAnnotationAdded} onAnnotationEdited={onAnnotationEdited} onAnnotationRemoved={onAnnotationRemoved} onFeedback={onFeedback}> <ChatContextProvider config={config} chatList={chatList} isResponding={isResponding} showPromptLog={showPromptLog} questionIcon={questionIcon} answerIcon={answerIcon} onSend={handleSend} onRegenerate={onRegenerate} onAnnotationAdded={onAnnotationAdded} onAnnotationEdited={onAnnotationEdited} onAnnotationRemoved={onAnnotationRemoved} onFeedback={onFeedback}>
<div className="relative h-full"> <div className="relative h-full">
<div ref={chatContainerRef} className={cn('relative h-full overflow-y-auto overflow-x-hidden', chatContainerClassName)}> <div ref={chatContainerRef} className={cn('relative h-full overflow-y-auto overflow-x-hidden', chatContainerClassName)}>
{chatNode} {chatNode}
...@@ -170,7 +184,7 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF ...@@ -170,7 +184,7 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF
{chatList.map((item, index) => { {chatList.map((item, index) => {
if (item.isAnswer) { if (item.isAnswer) {
const isLast = item.id === chatList[chatList.length - 1]?.id const isLast = item.id === chatList[chatList.length - 1]?.id
return <Answer appData={appData} key={item.id} item={item} question={chatList[index - 1]?.content} index={index} config={config} answerIcon={answerIcon} responding={isLast && isResponding} showPromptLog={showPromptLog} chatAnswerContainerInner={chatAnswerContainerInner} hideProcessDetail={hideProcessDetail} noChatInput={noChatInput} switchSibling={switchSibling} /> return <Answer appData={appData} key={item.id} item={item} question={chatList[index - 1]?.content} index={index} config={config} answerIcon={answerIcon} isLast={isLast} responding={isLast && isResponding} showPromptLog={showPromptLog} chatAnswerContainerInner={chatAnswerContainerInner} hideProcessDetail={hideProcessDetail} noChatInput={noChatInput} switchSibling={switchSibling} />
} }
return <Question key={item.id} item={item} questionIcon={questionIcon} theme={themeBuilder?.theme} /> return <Question key={item.id} item={item} questionIcon={questionIcon} theme={themeBuilder?.theme} />
})} })}
...@@ -187,7 +201,7 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF ...@@ -187,7 +201,7 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF
</div> </div>
)} )}
{hasTryToAsk && <TryToAsk suggestedQuestions={suggestedQuestions} onSend={onSend} isMobile={isMobile} />} {hasTryToAsk && <TryToAsk suggestedQuestions={suggestedQuestions} onSend={onSend} isMobile={isMobile} />}
{!noChatInput && <ChatInputArea disabled={inputDisabled} showFeatureBar={showFeatureBar} showFileUpload={showFileUpload} featureBarDisabled={isResponding} onFeatureBarClick={onFeatureBarClick} visionConfig={config?.file_upload} speechToTextConfig={config?.speech_to_text} onSend={onSend} onClear={onClear} inputs={inputs} inputsForm={inputsForm} theme={themeBuilder?.theme} isResponding={isResponding} />} {!noChatInput && <ChatInputArea disabled={inputDisabled} showFeatureBar={showFeatureBar} showFileUpload={showFileUpload} featureBarDisabled={isResponding} onFeatureBarClick={onFeatureBarClick} visionConfig={config?.file_upload} speechToTextConfig={config?.speech_to_text} onSend={handleSend} onClear={onClear} inputs={inputs} inputsForm={inputsForm} theme={themeBuilder?.theme} isResponding={isResponding} />}
</div> </div>
</div> </div>
{/* {showPromptLogModal && !hideLogModal && ( {/* {showPromptLogModal && !hideLogModal && (
......
const translation = {
title: 'Annotations',
name: 'Annotation Reply',
editBy: 'Answer edited by {{author}}',
noData: {
title: 'No annotations',
description: 'You can edit annotations during app debugging or import annotations in bulk here for a high-quality response.',
},
table: {
header: {
question: 'question',
answer: 'answer',
createdAt: 'created at',
hits: 'hits',
actions: 'actions',
addAnnotation: 'Add Annotation',
bulkImport: 'Bulk Import',
bulkExport: 'Bulk Export',
clearAll: 'Clear All Annotation',
},
},
editModal: {
title: 'Edit Annotation Reply',
queryName: 'User Query',
answerName: 'Storyteller Bot',
yourAnswer: 'Your Answer',
answerPlaceholder: 'Type your answer here',
yourQuery: 'Your Query',
queryPlaceholder: 'Type your query here',
removeThisCache: 'Remove this Annotation',
createdAt: 'Created At',
},
addModal: {
title: 'Add Annotation Reply',
queryName: 'Question',
answerName: 'Answer',
answerPlaceholder: 'Type answer here',
queryPlaceholder: 'Type query here',
createNext: 'Add another annotated response',
},
batchModal: {
title: 'Bulk Import',
csvUploadTitle: 'Drag and drop your CSV file here, or ',
browse: 'browse',
tip: 'The CSV file must conform to the following structure:',
question: 'question',
answer: 'answer',
contentTitle: 'chunk content',
content: 'content',
template: 'Download the template here',
cancel: 'Cancel',
run: 'Run Batch',
runError: 'Run batch failed',
processing: 'In batch processing',
completed: 'Import completed',
error: 'Import Error',
ok: 'OK',
},
errorMessage: {
answerRequired: 'Answer is required',
queryRequired: 'Question is required',
},
viewModal: {
annotatedResponse: 'Annotation Reply',
hitHistory: 'Hit History',
hit: 'Hit',
hits: 'Hits',
noHitHistory: 'No hit history',
},
hitHistoryTable: {
query: 'Query',
match: 'Match',
response: 'Response',
source: 'Source',
score: 'Score',
time: 'Time',
},
initSetup: {
title: 'Annotation Reply Initial Setup',
configTitle: 'Annotation Reply Setup',
confirmBtn: 'Save & Enable',
configConfirmBtn: 'Save',
},
embeddingModelSwitchTip: 'Annotation text vectorization model, switching models will be re-embedded, resulting in additional costs.',
}
export default translation
/*
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:21
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-05-13 11:22:21
* @FilePath: \glsk-ai-assistant\i18n\i18next-config.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
'use client' 'use client'
import i18n from 'i18next' import i18n from 'i18next'
import { initReactI18next } from 'react-i18next' import { initReactI18next } from 'react-i18next'
...@@ -24,10 +32,10 @@ const loadLangResources = (lang: string) => ({ ...@@ -24,10 +32,10 @@ const loadLangResources = (lang: string) => ({
// register: require(`./${lang}/register`).default, // register: require(`./${lang}/register`).default,
// app: require(`./${lang}/app`).default, // app: require(`./${lang}/app`).default,
// appOverview: require(`./${lang}/app-overview`).default, // appOverview: require(`./${lang}/app-overview`).default,
// appDebug: require(`./${lang}/app-debug`).default, appDebug: require(`./${lang}/app-debug`).default,
// appApi: require(`./${lang}/app-api`).default, // appApi: require(`./${lang}/app-api`).default,
// appLog: require(`./${lang}/app-log`).default, // appLog: require(`./${lang}/app-log`).default,
// appAnnotation: require(`./${lang}/app-annotation`).default, appAnnotation: require(`./${lang}/app-annotation`).default,
share: require(`./${lang}/share-app`).default, share: require(`./${lang}/share-app`).default,
// dataset: require(`./${lang}/dataset`).default, // dataset: require(`./${lang}/dataset`).default,
// datasetDocuments: require(`./${lang}/dataset-documents`).default, // datasetDocuments: require(`./${lang}/dataset-documents`).default,
...@@ -54,12 +62,11 @@ export const resources = LanguagesSupported.reduce<Resource>((acc, lang) => { ...@@ -54,12 +62,11 @@ export const resources = LanguagesSupported.reduce<Resource>((acc, lang) => {
return acc return acc
}, {}) }, {})
i18n.use(initReactI18next) i18n.use(initReactI18next).init({
.init({ lng: undefined,
lng: undefined, fallbackLng: 'en-US',
fallbackLng: 'en-US', resources,
resources, })
})
export const changeLanguage = i18n.changeLanguage export const changeLanguage = i18n.changeLanguage
export default i18n export default i18n
const translation = {
title: '标注',
name: '标注回复',
editBy: '{{author}}编辑的答案',
noData: {
title: '没有标注',
description: '你可以在应用会话调试中编辑标注,也可以在此批量导入标注用于高质量回复。',
},
table: {
header: {
question: '提问',
match: '匹配',
response: '回复',
answer: '答案',
createdAt: '创建时间',
hits: '命中次数',
actions: '操作',
addAnnotation: '添加标注',
bulkImport: '批量导入',
bulkExport: '批量导出',
clearAll: '删除所有标注',
},
},
editModal: {
title: '编辑标注回复',
queryName: '用户提问',
answerName: '机器回复',
yourAnswer: '您的回复',
answerPlaceholder: '在这里输入您的回复',
yourQuery: '您的提问',
queryPlaceholder: '在这里输入您的提问',
removeThisCache: '删除此标注',
createdAt: '创建于',
},
addModal: {
title: '添加标注回复',
queryName: '提问',
answerName: '回复',
answerPlaceholder: '输入回复',
queryPlaceholder: '输入提问',
createNext: '添加下一个标注回复',
},
batchModal: {
title: '批量导入',
csvUploadTitle: '将您的 CSV 文件拖放到此处,或',
browse: '选择文件',
tip: 'CSV 文件必须符合以下结构:',
question: '问题',
answer: '回答',
contentTitle: '分段内容',
content: '内容',
template: '下载模板',
cancel: '取消',
run: '导入',
runError: '批量导入失败',
processing: '批量处理中',
completed: '导入完成',
error: '导入出错',
ok: '确定',
},
errorMessage: {
answerRequired: '回复不能为空',
queryRequired: '提问不能为空',
},
viewModal: {
annotatedResponse: '标注回复',
hitHistory: '命中历史',
hit: '次命中',
hits: '次命中',
noHitHistory: '没有命中历史',
},
hitHistoryTable: {
question: '问题',
query: '提问',
match: '匹配',
response: '回复',
source: '来源',
score: '分数',
time: '时间',
},
initSetup: {
title: '标注回复初始设置',
configTitle: '标注回复设置',
confirmBtn: '保存并启用',
configConfirmBtn: '保存',
},
embeddingModelSwitchTip: '标注文本向量化模型,切换模型会重新嵌入,产生额外费用消耗',
}
export default translation
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!