Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show prompt send to LLM for assistant answer #2098 #2142

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 135 additions & 1 deletion web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"react18-json-view": "^0.2.8",
"reactflow": "^11.11.2",
"recharts": "^2.12.4",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0",
"umi": "^4.0.90",
"umi-request": "^1.4.0",
Expand Down
27 changes: 27 additions & 0 deletions web/src/assets/svg/prompt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions web/src/components/highlight-markdown/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.text {
.chunkText;
}
5 changes: 5 additions & 0 deletions web/src/components/highlight-markdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Markdown from 'react-markdown';
import SyntaxHighlighter from 'react-syntax-highlighter';
import rehypeRaw from 'rehype-raw';
import remarkGfm from 'remark-gfm';

import styles from './index.less';

const HightLightMarkdown = ({
children,
}: {
Expand All @@ -10,6 +13,8 @@ const HightLightMarkdown = ({
return (
<Markdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeRaw]}
className={styles.text}
components={
{
code(props: any) {
Expand Down
27 changes: 26 additions & 1 deletion web/src/components/message-item/group-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CopyToClipboard from '@/components/copy-to-clipboard';
import { useSetModalState } from '@/hooks/common-hooks';
import {
DeleteOutlined,
DislikeOutlined,
Expand All @@ -8,17 +9,29 @@ import {
} from '@ant-design/icons';
import { Radio } from 'antd';
import { useCallback } from 'react';
import SvgIcon from '../svg-icon';
import FeedbackModal from './feedback-modal';
import { useSendFeedback } from './hooks';
import PromptModal from './prompt-modal';

interface IProps {
messageId: string;
content: string;
prompt?: string;
}

export const AssistantGroupButton = ({ messageId, content }: IProps) => {
export const AssistantGroupButton = ({
messageId,
content,
prompt,
}: IProps) => {
const { visible, hideModal, showModal, onFeedbackOk, loading } =
useSendFeedback(messageId);
const {
visible: promptVisible,
hideModal: hidePromptModal,
showModal: showPromptModal,
} = useSetModalState();

const handleLike = useCallback(() => {
onFeedbackOk({ thumbup: true });
Expand All @@ -39,6 +52,11 @@ export const AssistantGroupButton = ({ messageId, content }: IProps) => {
<Radio.Button value="d" onClick={showModal}>
<DislikeOutlined />
</Radio.Button>
{prompt && (
<Radio.Button value="e" onClick={showPromptModal}>
<SvgIcon name={`prompt`} width={16}></SvgIcon>
</Radio.Button>
)}
</Radio.Group>
{visible && (
<FeedbackModal
Expand All @@ -48,6 +66,13 @@ export const AssistantGroupButton = ({ messageId, content }: IProps) => {
loading={loading}
></FeedbackModal>
)}
{promptVisible && (
<PromptModal
visible={promptVisible}
hideModal={hidePromptModal}
prompt={prompt}
></PromptModal>
)}
</>
);
};
Expand Down
1 change: 1 addition & 0 deletions web/src/components/message-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const MessageItem = ({
<AssistantGroupButton
messageId={item.id}
content={item.content}
prompt={item.prompt}
></AssistantGroupButton>
) : (
<UserGroupButton></UserGroupButton>
Expand Down
30 changes: 30 additions & 0 deletions web/src/components/message-item/prompt-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IModalProps } from '@/interfaces/common';
import { IFeedbackRequestBody } from '@/interfaces/request/chat';
import { Modal, Space } from 'antd';
import HightLightMarkdown from '../highlight-markdown';
import SvgIcon from '../svg-icon';

const PromptModal = ({
visible,
hideModal,
prompt,
}: IModalProps<IFeedbackRequestBody> & { prompt?: string }) => {
return (
<Modal
title={
<Space>
<SvgIcon name={`prompt`} width={18}></SvgIcon>
Prompt
</Space>
}
width={'80%'}
open={visible}
onCancel={hideModal}
footer={null}
>
<HightLightMarkdown>{prompt}</HightLightMarkdown>
</Modal>
);
};

export default PromptModal;
4 changes: 4 additions & 0 deletions web/src/interfaces/database/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export interface Message {
content: string;
role: MessageType;
doc_ids?: string[];
prompt?: string;
id?: string;
}

export interface IReference {
Expand All @@ -80,6 +82,8 @@ export interface IAnswer {
answer: string;
reference: IReference;
conversationId?: string;
prompt?: string;
id?: string;
}

export interface Docagg {
Expand Down