From 4835358f24f63934eb905496142efeec85588fc8 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 15 Mar 2024 18:26:35 +0800 Subject: [PATCH] modify prompt log --- web/app/components/app/chat/answer/index.tsx | 44 ++-- web/app/components/app/chat/index.tsx | 241 +++++++++--------- web/app/components/app/chat/log/index.tsx | 31 +-- .../components/app/chat/question/index.tsx | 8 +- web/app/components/app/chat/type.ts | 3 +- web/app/components/app/log/list.tsx | 12 +- web/app/components/base/audio-btn/index.tsx | 5 +- .../base/chat/chat/answer/index.tsx | 9 +- .../base/chat/chat/answer/operation.tsx | 38 ++- web/app/components/base/chat/chat/hooks.ts | 9 +- web/app/components/base/chat/chat/index.tsx | 3 +- .../components/base/chat/chat/question.tsx | 14 +- web/i18n/en-US/app-log.ts | 2 + web/i18n/zh-Hans/app-log.ts | 2 + web/models/log.ts | 5 +- 15 files changed, 217 insertions(+), 209 deletions(-) diff --git a/web/app/components/app/chat/answer/index.tsx b/web/app/components/app/chat/answer/index.tsx index 7138aeba88..af37d60b05 100644 --- a/web/app/components/app/chat/answer/index.tsx +++ b/web/app/components/app/chat/answer/index.tsx @@ -1,13 +1,13 @@ 'use client' import type { FC, ReactNode } from 'react' -import React, { useState } from 'react' +import React, { useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { UserCircleIcon } from '@heroicons/react/24/solid' import cn from 'classnames' import type { CitationItem, DisplayScene, FeedbackFunc, Feedbacktype, IChatItem } from '../type' import OperationBtn from '../operation' import LoadingAnim from '../loading-anim' -import { EditIconSolid, RatingIcon } from '../icon-component' +import { RatingIcon } from '../icon-component' import s from '../style.module.css' import MoreInfo from '../more-info' import CopyBtn from '../copy-btn' @@ -26,16 +26,8 @@ import { MessageFast } from '@/app/components/base/icons/src/vender/solid/commun import type { Emoji } from '@/app/components/tools/types' import type { VisionFile } from '@/types/app' import ImageGallery from '@/app/components/base/image-gallery' +import Log from '@/app/components/app/chat/log' -const Divider: FC<{ name: string }> = ({ name }) => { - const { t } = useTranslation() - return
- - {t('appLog.detail.annotationTip', { user: name })} - -
-
-} const IconWrapper: FC<{ children: React.ReactNode | string }> = ({ children }) => { return
{children} @@ -64,6 +56,7 @@ export type IAnswerProps = { onAnnotationAdded?: (annotationId: string, authorName: string, question: string, answer: string, index: number) => void onAnnotationRemoved?: (index: number) => void allToolIcons?: Record + isShowPromptLog?: boolean } // The component needs to maintain its own state to control whether to display input component const Answer: FC = ({ @@ -87,12 +80,11 @@ const Answer: FC = ({ onAnnotationAdded, onAnnotationRemoved, allToolIcons, + isShowPromptLog, }) => { const { id, content, more, feedback, adminFeedback, annotation, agent_thoughts } = item const isAgentMode = !!agent_thoughts && agent_thoughts.length > 0 const hasAnnotation = !!annotation?.id - const [showEdit, setShowEdit] = useState(false) - const [loading, setLoading] = useState(false) // const [annotation, setAnnotation] = useState(initAnnotation) // const [inputValue, setInputValue] = useState(initAnnotation?.content ?? '') const [localAdminFeedback, setLocalAdminFeedback] = useState(adminFeedback) @@ -241,9 +233,11 @@ const Answer: FC = ({
) + const ref = useRef(null) + return ( // data-id for debug the item message is right -
+
{ answerIcon || ( @@ -257,7 +251,7 @@ const Answer: FC = ({ ) }
-
+
{(isResponding && (isAgentMode ? (!content && (agent_thoughts || []).filter(item => !!item.thought || !!item.tool).length === 0) : !content)) @@ -326,11 +320,21 @@ const Answer: FC = ({ className={cn(s.copyBtn, 'mr-1')} /> )} - {!item.isOpeningStatement && isShowTextToSpeech && ( - + {((isShowPromptLog && !isResponding) || (!item.isOpeningStatement && isShowTextToSpeech)) && ( +
+ {isShowPromptLog && !isResponding && ( + + )} + {!item.isOpeningStatement && isShowTextToSpeech && ( + <> +
+ + + )} +
)} {(!item.isOpeningStatement && supportAnnotation) && ( = ({ onAnnotationAdded={handleAnnotationAdded} onAnnotationRemoved={handleAnnotationRemoved} allToolIcons={allToolIcons} + isShowPromptLog={isShowPromptLog} /> } return ( @@ -316,140 +317,132 @@ const Chat: FC = ({ ) })}
- { - !isHideSendInput && ( -
- {/* Thinking is sync and can not be stopped */} - {(isResponding && canStopResponding && ((!!chatList[chatList.length - 1]?.content) || (chatList[chatList.length - 1]?.agent_thoughts && chatList[chatList.length - 1].agent_thoughts!.length > 0))) && ( -
- + {!isHideSendInput && ( +
+ {/* Thinking is sync and can not be stopped */} + {(isResponding && canStopResponding && ((!!chatList[chatList.length - 1]?.content) || (chatList[chatList.length - 1]?.agent_thoughts && chatList[chatList.length - 1].agent_thoughts!.length > 0))) && ( +
+ +
+ )} + {isShowSuggestion && ( +
+
+
+
+ {TryToAskIcon} + {t('appDebug.feature.suggestedQuestionsAfterAnswer.tryToAsk')} +
+
+ {/* has scrollbar would hide part of first item */} +
+ {suggestionList?.map((item, index) => ( +
+ +
+ ))} +
+
+ )} +
+ {visionConfig?.enabled && ( + <> +
+ = visionConfig.number_limits} + /> +
+
+
+ +
+ )} - { - isShowSuggestion && ( -
-
-
-
- {TryToAskIcon} - {t('appDebug.feature.suggestedQuestionsAfterAnswer.tryToAsk')} -
-
-
- {/* has scrollbar would hide part of first item */} -
- {suggestionList?.map((item, index) => ( -
- -
- ))} -
-
) - } -
+