From 9908a8bf1fde94221ec2cf11d26746dbde7cf2f3 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 15 Mar 2024 19:54:50 +0800 Subject: [PATCH] prompt log --- web/app/components/app/chat/answer/index.tsx | 27 ++++++++++++++--- web/app/components/app/chat/log/index.tsx | 30 ++----------------- .../base/chat/chat/answer/index.tsx | 27 +++++++++++++++-- .../base/chat/chat/answer/operation.tsx | 8 ++--- .../base/prompt-log-modal/index.tsx | 7 +++-- 5 files changed, 59 insertions(+), 40 deletions(-) diff --git a/web/app/components/app/chat/answer/index.tsx b/web/app/components/app/chat/answer/index.tsx index af37d60b05..ae3fd18429 100644 --- a/web/app/components/app/chat/answer/index.tsx +++ b/web/app/components/app/chat/answer/index.tsx @@ -1,6 +1,6 @@ 'use client' import type { FC, ReactNode } from 'react' -import React, { useRef, useState } from 'react' +import React, { useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { UserCircleIcon } from '@heroicons/react/24/solid' import cn from 'classnames' @@ -27,6 +27,7 @@ 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' +import PromptLogModal from '@/app/components/base/prompt-log-modal' const IconWrapper: FC<{ children: React.ReactNode | string }> = ({ children }) => { return
@@ -233,7 +234,19 @@ const Answer: FC = ({
) - const ref = useRef(null) + const [showPromptLogModal, setShowPromptLogModal] = useState(false) + const [width, setWidth] = useState(0) + + const ref = useRef(null) + + const adjustModalWidth = () => { + if (ref.current) + setWidth(document.body.clientWidth - (ref.current?.clientWidth + 56 + 16)) + } + + useEffect(() => { + adjustModalWidth() + }, []) return ( // data-id for debug the item message is right @@ -323,7 +336,7 @@ const Answer: FC = ({ {((isShowPromptLog && !isResponding) || (!item.isOpeningStatement && isShowTextToSpeech)) && (
{isShowPromptLog && !isResponding && ( - + )} {!item.isOpeningStatement && isShowTextToSpeech && ( <> @@ -373,7 +386,13 @@ const Answer: FC = ({ {!feedbackDisabled && renderFeedbackRating(feedback?.rating, !isHideFeedbackEdit, displayScene !== 'console')}
- + {showPromptLogModal && ( + setShowPromptLogModal(false)} + /> + )} {more && } diff --git a/web/app/components/app/chat/log/index.tsx b/web/app/components/app/chat/log/index.tsx index 0ef14162d9..cb7e6520de 100644 --- a/web/app/components/app/chat/log/index.tsx +++ b/web/app/components/app/chat/log/index.tsx @@ -1,8 +1,6 @@ -import type { Dispatch, FC, ReactNode, RefObject, SetStateAction } from 'react' -import { useEffect, useState } from 'react' +import type { Dispatch, FC, ReactNode, SetStateAction } from 'react' import { useTranslation } from 'react-i18next' import { File02 } from '@/app/components/base/icons/src/vender/line/files' -import PromptLogModal from '@/app/components/base/prompt-log-modal' export type LogData = { role: string @@ -10,29 +8,16 @@ export type LogData = { } type LogProps = { - containerRef: RefObject - log: LogData[] runID?: string + setShowModal: Dispatch> children?: (v: Dispatch>) => ReactNode } const Log: FC = ({ - containerRef, children, - log, runID, + setShowModal, }) => { const { t } = useTranslation() - const [showModal, setShowModal] = useState(false) - const [width, setWidth] = useState(0) - - const adjustModalWidth = () => { - if (containerRef.current) - setWidth(document.body.clientWidth - (containerRef.current?.clientWidth + 56 + 16)) - } - - useEffect(() => { - adjustModalWidth() - }, []) return ( <> @@ -52,15 +37,6 @@ const Log: FC = ({ ) } - { - showModal && ( - setShowModal(false)} - /> - ) - } ) } diff --git a/web/app/components/base/chat/chat/answer/index.tsx b/web/app/components/base/chat/chat/answer/index.tsx index 581b031bab..d50a978654 100644 --- a/web/app/components/base/chat/chat/answer/index.tsx +++ b/web/app/components/base/chat/chat/answer/index.tsx @@ -2,7 +2,7 @@ import type { FC, ReactNode, } from 'react' -import { memo, useRef } from 'react' +import { memo, useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import type { ChatConfig, @@ -18,6 +18,7 @@ import LoadingAnim from '@/app/components/app/chat/loading-anim' import Citation from '@/app/components/app/chat/citation' import { EditTitle } from '@/app/components/app/annotation/edit-annotation-modal/edit-item' import type { Emoji } from '@/app/components/tools/types' +import PromptLogModal from '@/app/components/base/prompt-log-modal' type AnswerProps = { item: ChatItem @@ -40,7 +41,6 @@ const Answer: FC = ({ showPromptLog, }) => { const { t } = useTranslation() - const ref = useRef(null) const { content, citation, @@ -50,6 +50,20 @@ const Answer: FC = ({ } = item const hasAgentThoughts = !!agent_thoughts?.length + const [showPromptLogModal, setShowPromptLogModal] = useState(false) + const [width, setWidth] = useState(0) + + const ref = useRef(null) + + const adjustModalWidth = () => { + if (ref.current) + setWidth(document.body.clientWidth - (ref.current?.clientWidth + 56 + 16)) + } + + useEffect(() => { + adjustModalWidth() + }, []) + return (
@@ -79,7 +93,7 @@ const Answer: FC = ({ question={question} index={index} showPromptLog={showPromptLog} - containerRef={ref} + setShowPromptLogModal={setShowPromptLogModal} /> ) } @@ -122,6 +136,13 @@ const Answer: FC = ({
+ {showPromptLogModal && ( + setShowPromptLogModal(false)} + /> + )} ) } diff --git a/web/app/components/base/chat/chat/answer/operation.tsx b/web/app/components/base/chat/chat/answer/operation.tsx index aeed0c9e4f..e824b051e8 100644 --- a/web/app/components/base/chat/chat/answer/operation.tsx +++ b/web/app/components/base/chat/chat/answer/operation.tsx @@ -1,4 +1,4 @@ -import type { FC, RefObject } from 'react' +import type { Dispatch, FC, SetStateAction } from 'react' import { memo, useMemo, @@ -24,14 +24,14 @@ type OperationProps = { question: string index: number showPromptLog?: boolean - containerRef: RefObject + setShowPromptLogModal: Dispatch> } const Operation: FC = ({ item, question, index, showPromptLog, - containerRef, + setShowPromptLogModal, }) => { const { t } = useTranslation() const { @@ -79,7 +79,7 @@ const Operation: FC = ({
{showPromptLog && ( - + )} {(!isOpeningStatement && config?.text_to_speech?.enabled) && ( <> diff --git a/web/app/components/base/prompt-log-modal/index.tsx b/web/app/components/base/prompt-log-modal/index.tsx index 2948e9f067..f0e5b27dde 100644 --- a/web/app/components/base/prompt-log-modal/index.tsx +++ b/web/app/components/base/prompt-log-modal/index.tsx @@ -4,9 +4,10 @@ import { useClickAway } from 'ahooks' import Card from './card' import { CopyFeedbackNew } from '@/app/components/base/copy-feedback' import { XClose } from '@/app/components/base/icons/src/vender/line/general' +import type { VisionFile } from '@/types/app' type PromptLogModalProps = { - log: { role: string; text: string }[] + log: { role: string; text: string; files?: VisionFile[] }[] width: number onCancel: () => void } @@ -19,8 +20,10 @@ const PromptLogModal: FC = ({ const [mounted, setMounted] = useState(false) useClickAway(() => { - if (mounted) + if (mounted) { + console.log(111) onCancel() + } }, ref) useEffect(() => {