balibabu commited on
Commit
c947a89
·
1 Parent(s): 864d034

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

Browse files

### What problem does this PR solve?

feat: Show prompt send to LLM for assistant answer #2098
### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/package-lock.json CHANGED
@@ -39,6 +39,7 @@
39
  "react18-json-view": "^0.2.8",
40
  "reactflow": "^11.11.2",
41
  "recharts": "^2.12.4",
 
42
  "remark-gfm": "^4.0.0",
43
  "umi": "^4.0.90",
44
  "umi-request": "^1.4.0",
@@ -13955,11 +13956,82 @@
13955
  "node": ">= 0.4"
13956
  }
13957
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13958
  "node_modules/hast-util-parse-selector": {
13959
  "version": "2.2.5",
13960
  "resolved": "https://registry.npmmirror.com/hast-util-parse-selector/-/hast-util-parse-selector-2.2.5.tgz",
13961
  "integrity": "sha512-7j6mrk/qqkSehsM92wQjdIgWM2/BW61u/53G6xmC8i1OmEdKLHbk419QKQUjz6LglWsfqoiHmyMRkP1BGjecNQ=="
13962
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13963
  "node_modules/hast-util-to-jsx-runtime": {
13964
  "version": "2.3.0",
13965
  "resolved": "https://registry.npmmirror.com/hast-util-to-jsx-runtime/-/hast-util-to-jsx-runtime-2.3.0.tgz",
@@ -13982,6 +14054,24 @@
13982
  "vfile-message": "^4.0.0"
13983
  }
13984
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13985
  "node_modules/hast-util-whitespace": {
13986
  "version": "3.0.0",
13987
  "resolved": "https://registry.npmmirror.com/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz",
@@ -14229,6 +14319,15 @@
14229
  "resolved": "https://registry.npmmirror.com/html-url-attributes/-/html-url-attributes-3.0.0.tgz",
14230
  "integrity": "sha512-/sXbVCWayk6GDVg3ctOX6nxaVj7So40FcFAnWlWGNAB1LpYKcV5Cd10APjPjW80O7zYW2MsjBV4zZ7IZO5fVow=="
14231
  },
 
 
 
 
 
 
 
 
 
14232
  "node_modules/html-webpack-plugin": {
14233
  "version": "5.5.0",
14234
  "resolved": "https://registry.npmmirror.com/html-webpack-plugin/-/html-webpack-plugin-5.5.0.tgz",
@@ -20729,7 +20828,6 @@
20729
  "version": "7.1.2",
20730
  "resolved": "https://registry.npmmirror.com/parse5/-/parse5-7.1.2.tgz",
20731
  "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==",
20732
- "dev": true,
20733
  "dependencies": {
20734
  "entities": "^4.4.0"
20735
  }
@@ -23751,6 +23849,20 @@
23751
  "node": ">= 0.4"
23752
  }
23753
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23754
  "node_modules/relateurl": {
23755
  "version": "0.2.7",
23756
  "resolved": "https://registry.npmmirror.com/relateurl/-/relateurl-0.2.7.tgz",
@@ -26790,6 +26902,19 @@
26790
  "vfile-message": "^4.0.0"
26791
  }
26792
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
26793
  "node_modules/vfile-message": {
26794
  "version": "4.0.2",
26795
  "resolved": "https://registry.npmmirror.com/vfile-message/-/vfile-message-4.0.2.tgz",
@@ -27310,6 +27435,15 @@
27310
  "minimalistic-assert": "^1.0.0"
27311
  }
27312
  },
 
 
 
 
 
 
 
 
 
27313
  "node_modules/web-streams-polyfill": {
27314
  "version": "3.3.2",
27315
  "resolved": "https://registry.npmmirror.com/web-streams-polyfill/-/web-streams-polyfill-3.3.2.tgz",
 
39
  "react18-json-view": "^0.2.8",
40
  "reactflow": "^11.11.2",
41
  "recharts": "^2.12.4",
42
+ "rehype-raw": "^7.0.0",
43
  "remark-gfm": "^4.0.0",
44
  "umi": "^4.0.90",
45
  "umi-request": "^1.4.0",
 
13956
  "node": ">= 0.4"
13957
  }
13958
  },
13959
+ "node_modules/hast-util-from-parse5": {
13960
+ "version": "8.0.1",
13961
+ "resolved": "https://registry.npmmirror.com/hast-util-from-parse5/-/hast-util-from-parse5-8.0.1.tgz",
13962
+ "integrity": "sha512-Er/Iixbc7IEa7r/XLtuG52zoqn/b3Xng/w6aZQ0xGVxzhw5xUFxcRqdPzP6yFi/4HBYRaifaI5fQ1RH8n0ZeOQ==",
13963
+ "dependencies": {
13964
+ "@types/hast": "^3.0.0",
13965
+ "@types/unist": "^3.0.0",
13966
+ "devlop": "^1.0.0",
13967
+ "hastscript": "^8.0.0",
13968
+ "property-information": "^6.0.0",
13969
+ "vfile": "^6.0.0",
13970
+ "vfile-location": "^5.0.0",
13971
+ "web-namespaces": "^2.0.0"
13972
+ },
13973
+ "funding": {
13974
+ "type": "opencollective",
13975
+ "url": "https://opencollective.com/unified"
13976
+ }
13977
+ },
13978
+ "node_modules/hast-util-from-parse5/node_modules/hast-util-parse-selector": {
13979
+ "version": "4.0.0",
13980
+ "resolved": "https://registry.npmmirror.com/hast-util-parse-selector/-/hast-util-parse-selector-4.0.0.tgz",
13981
+ "integrity": "sha512-wkQCkSYoOGCRKERFWcxMVMOcYE2K1AaNLU8DXS9arxnLOUEWbOXKXiJUNzEpqZ3JOKpnha3jkFrumEjVliDe7A==",
13982
+ "dependencies": {
13983
+ "@types/hast": "^3.0.0"
13984
+ },
13985
+ "funding": {
13986
+ "type": "opencollective",
13987
+ "url": "https://opencollective.com/unified"
13988
+ }
13989
+ },
13990
+ "node_modules/hast-util-from-parse5/node_modules/hastscript": {
13991
+ "version": "8.0.0",
13992
+ "resolved": "https://registry.npmmirror.com/hastscript/-/hastscript-8.0.0.tgz",
13993
+ "integrity": "sha512-dMOtzCEd3ABUeSIISmrETiKuyydk1w0pa+gE/uormcTpSYuaNJPbX1NU3JLyscSLjwAQM8bWMhhIlnCqnRvDTw==",
13994
+ "dependencies": {
13995
+ "@types/hast": "^3.0.0",
13996
+ "comma-separated-tokens": "^2.0.0",
13997
+ "hast-util-parse-selector": "^4.0.0",
13998
+ "property-information": "^6.0.0",
13999
+ "space-separated-tokens": "^2.0.0"
14000
+ },
14001
+ "funding": {
14002
+ "type": "opencollective",
14003
+ "url": "https://opencollective.com/unified"
14004
+ }
14005
+ },
14006
  "node_modules/hast-util-parse-selector": {
14007
  "version": "2.2.5",
14008
  "resolved": "https://registry.npmmirror.com/hast-util-parse-selector/-/hast-util-parse-selector-2.2.5.tgz",
14009
  "integrity": "sha512-7j6mrk/qqkSehsM92wQjdIgWM2/BW61u/53G6xmC8i1OmEdKLHbk419QKQUjz6LglWsfqoiHmyMRkP1BGjecNQ=="
14010
  },
14011
+ "node_modules/hast-util-raw": {
14012
+ "version": "9.0.4",
14013
+ "resolved": "https://registry.npmmirror.com/hast-util-raw/-/hast-util-raw-9.0.4.tgz",
14014
+ "integrity": "sha512-LHE65TD2YiNsHD3YuXcKPHXPLuYh/gjp12mOfU8jxSrm1f/yJpsb0F/KKljS6U9LJoP0Ux+tCe8iJ2AsPzTdgA==",
14015
+ "dependencies": {
14016
+ "@types/hast": "^3.0.0",
14017
+ "@types/unist": "^3.0.0",
14018
+ "@ungap/structured-clone": "^1.0.0",
14019
+ "hast-util-from-parse5": "^8.0.0",
14020
+ "hast-util-to-parse5": "^8.0.0",
14021
+ "html-void-elements": "^3.0.0",
14022
+ "mdast-util-to-hast": "^13.0.0",
14023
+ "parse5": "^7.0.0",
14024
+ "unist-util-position": "^5.0.0",
14025
+ "unist-util-visit": "^5.0.0",
14026
+ "vfile": "^6.0.0",
14027
+ "web-namespaces": "^2.0.0",
14028
+ "zwitch": "^2.0.0"
14029
+ },
14030
+ "funding": {
14031
+ "type": "opencollective",
14032
+ "url": "https://opencollective.com/unified"
14033
+ }
14034
+ },
14035
  "node_modules/hast-util-to-jsx-runtime": {
14036
  "version": "2.3.0",
14037
  "resolved": "https://registry.npmmirror.com/hast-util-to-jsx-runtime/-/hast-util-to-jsx-runtime-2.3.0.tgz",
 
14054
  "vfile-message": "^4.0.0"
14055
  }
14056
  },
14057
+ "node_modules/hast-util-to-parse5": {
14058
+ "version": "8.0.0",
14059
+ "resolved": "https://registry.npmmirror.com/hast-util-to-parse5/-/hast-util-to-parse5-8.0.0.tgz",
14060
+ "integrity": "sha512-3KKrV5ZVI8if87DVSi1vDeByYrkGzg4mEfeu4alwgmmIeARiBLKCZS2uw5Gb6nU9x9Yufyj3iudm6i7nl52PFw==",
14061
+ "dependencies": {
14062
+ "@types/hast": "^3.0.0",
14063
+ "comma-separated-tokens": "^2.0.0",
14064
+ "devlop": "^1.0.0",
14065
+ "property-information": "^6.0.0",
14066
+ "space-separated-tokens": "^2.0.0",
14067
+ "web-namespaces": "^2.0.0",
14068
+ "zwitch": "^2.0.0"
14069
+ },
14070
+ "funding": {
14071
+ "type": "opencollective",
14072
+ "url": "https://opencollective.com/unified"
14073
+ }
14074
+ },
14075
  "node_modules/hast-util-whitespace": {
14076
  "version": "3.0.0",
14077
  "resolved": "https://registry.npmmirror.com/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz",
 
14319
  "resolved": "https://registry.npmmirror.com/html-url-attributes/-/html-url-attributes-3.0.0.tgz",
14320
  "integrity": "sha512-/sXbVCWayk6GDVg3ctOX6nxaVj7So40FcFAnWlWGNAB1LpYKcV5Cd10APjPjW80O7zYW2MsjBV4zZ7IZO5fVow=="
14321
  },
14322
+ "node_modules/html-void-elements": {
14323
+ "version": "3.0.0",
14324
+ "resolved": "https://registry.npmmirror.com/html-void-elements/-/html-void-elements-3.0.0.tgz",
14325
+ "integrity": "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==",
14326
+ "funding": {
14327
+ "type": "github",
14328
+ "url": "https://github.com/sponsors/wooorm"
14329
+ }
14330
+ },
14331
  "node_modules/html-webpack-plugin": {
14332
  "version": "5.5.0",
14333
  "resolved": "https://registry.npmmirror.com/html-webpack-plugin/-/html-webpack-plugin-5.5.0.tgz",
 
20828
  "version": "7.1.2",
20829
  "resolved": "https://registry.npmmirror.com/parse5/-/parse5-7.1.2.tgz",
20830
  "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==",
 
20831
  "dependencies": {
20832
  "entities": "^4.4.0"
20833
  }
 
23849
  "node": ">= 0.4"
23850
  }
23851
  },
23852
+ "node_modules/rehype-raw": {
23853
+ "version": "7.0.0",
23854
+ "resolved": "https://registry.npmmirror.com/rehype-raw/-/rehype-raw-7.0.0.tgz",
23855
+ "integrity": "sha512-/aE8hCfKlQeA8LmyeyQvQF3eBiLRGNlfBJEvWH7ivp9sBqs7TNqBL5X3v157rM4IFETqDnIOO+z5M/biZbo9Ww==",
23856
+ "dependencies": {
23857
+ "@types/hast": "^3.0.0",
23858
+ "hast-util-raw": "^9.0.0",
23859
+ "vfile": "^6.0.0"
23860
+ },
23861
+ "funding": {
23862
+ "type": "opencollective",
23863
+ "url": "https://opencollective.com/unified"
23864
+ }
23865
+ },
23866
  "node_modules/relateurl": {
23867
  "version": "0.2.7",
23868
  "resolved": "https://registry.npmmirror.com/relateurl/-/relateurl-0.2.7.tgz",
 
26902
  "vfile-message": "^4.0.0"
26903
  }
26904
  },
26905
+ "node_modules/vfile-location": {
26906
+ "version": "5.0.3",
26907
+ "resolved": "https://registry.npmmirror.com/vfile-location/-/vfile-location-5.0.3.tgz",
26908
+ "integrity": "sha512-5yXvWDEgqeiYiBe1lbxYF7UMAIm/IcopxMHrMQDq3nvKcjPKIhZklUKL+AE7J7uApI4kwe2snsK+eI6UTj9EHg==",
26909
+ "dependencies": {
26910
+ "@types/unist": "^3.0.0",
26911
+ "vfile": "^6.0.0"
26912
+ },
26913
+ "funding": {
26914
+ "type": "opencollective",
26915
+ "url": "https://opencollective.com/unified"
26916
+ }
26917
+ },
26918
  "node_modules/vfile-message": {
26919
  "version": "4.0.2",
26920
  "resolved": "https://registry.npmmirror.com/vfile-message/-/vfile-message-4.0.2.tgz",
 
27435
  "minimalistic-assert": "^1.0.0"
27436
  }
27437
  },
27438
+ "node_modules/web-namespaces": {
27439
+ "version": "2.0.1",
27440
+ "resolved": "https://registry.npmmirror.com/web-namespaces/-/web-namespaces-2.0.1.tgz",
27441
+ "integrity": "sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==",
27442
+ "funding": {
27443
+ "type": "github",
27444
+ "url": "https://github.com/sponsors/wooorm"
27445
+ }
27446
+ },
27447
  "node_modules/web-streams-polyfill": {
27448
  "version": "3.3.2",
27449
  "resolved": "https://registry.npmmirror.com/web-streams-polyfill/-/web-streams-polyfill-3.3.2.tgz",
web/package.json CHANGED
@@ -50,6 +50,7 @@
50
  "react18-json-view": "^0.2.8",
51
  "reactflow": "^11.11.2",
52
  "recharts": "^2.12.4",
 
53
  "remark-gfm": "^4.0.0",
54
  "umi": "^4.0.90",
55
  "umi-request": "^1.4.0",
 
50
  "react18-json-view": "^0.2.8",
51
  "reactflow": "^11.11.2",
52
  "recharts": "^2.12.4",
53
+ "rehype-raw": "^7.0.0",
54
  "remark-gfm": "^4.0.0",
55
  "umi": "^4.0.90",
56
  "umi-request": "^1.4.0",
web/src/assets/svg/prompt.svg ADDED
web/src/components/highlight-markdown/index.less ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .text {
2
+ .chunkText;
3
+ }
web/src/components/highlight-markdown/index.tsx CHANGED
@@ -1,7 +1,10 @@
1
  import Markdown from 'react-markdown';
2
  import SyntaxHighlighter from 'react-syntax-highlighter';
 
3
  import remarkGfm from 'remark-gfm';
4
 
 
 
5
  const HightLightMarkdown = ({
6
  children,
7
  }: {
@@ -10,6 +13,8 @@ const HightLightMarkdown = ({
10
  return (
11
  <Markdown
12
  remarkPlugins={[remarkGfm]}
 
 
13
  components={
14
  {
15
  code(props: any) {
 
1
  import Markdown from 'react-markdown';
2
  import SyntaxHighlighter from 'react-syntax-highlighter';
3
+ import rehypeRaw from 'rehype-raw';
4
  import remarkGfm from 'remark-gfm';
5
 
6
+ import styles from './index.less';
7
+
8
  const HightLightMarkdown = ({
9
  children,
10
  }: {
 
13
  return (
14
  <Markdown
15
  remarkPlugins={[remarkGfm]}
16
+ rehypePlugins={[rehypeRaw]}
17
+ className={styles.text}
18
  components={
19
  {
20
  code(props: any) {
web/src/components/message-item/group-button.tsx CHANGED
@@ -1,4 +1,5 @@
1
  import CopyToClipboard from '@/components/copy-to-clipboard';
 
2
  import {
3
  DeleteOutlined,
4
  DislikeOutlined,
@@ -8,17 +9,29 @@ import {
8
  } from '@ant-design/icons';
9
  import { Radio } from 'antd';
10
  import { useCallback } from 'react';
 
11
  import FeedbackModal from './feedback-modal';
12
  import { useSendFeedback } from './hooks';
 
13
 
14
  interface IProps {
15
  messageId: string;
16
  content: string;
 
17
  }
18
 
19
- export const AssistantGroupButton = ({ messageId, content }: IProps) => {
 
 
 
 
20
  const { visible, hideModal, showModal, onFeedbackOk, loading } =
21
  useSendFeedback(messageId);
 
 
 
 
 
22
 
23
  const handleLike = useCallback(() => {
24
  onFeedbackOk({ thumbup: true });
@@ -39,6 +52,11 @@ export const AssistantGroupButton = ({ messageId, content }: IProps) => {
39
  <Radio.Button value="d" onClick={showModal}>
40
  <DislikeOutlined />
41
  </Radio.Button>
 
 
 
 
 
42
  </Radio.Group>
43
  {visible && (
44
  <FeedbackModal
@@ -48,6 +66,13 @@ export const AssistantGroupButton = ({ messageId, content }: IProps) => {
48
  loading={loading}
49
  ></FeedbackModal>
50
  )}
 
 
 
 
 
 
 
51
  </>
52
  );
53
  };
 
1
  import CopyToClipboard from '@/components/copy-to-clipboard';
2
+ import { useSetModalState } from '@/hooks/common-hooks';
3
  import {
4
  DeleteOutlined,
5
  DislikeOutlined,
 
9
  } from '@ant-design/icons';
10
  import { Radio } from 'antd';
11
  import { useCallback } from 'react';
12
+ import SvgIcon from '../svg-icon';
13
  import FeedbackModal from './feedback-modal';
14
  import { useSendFeedback } from './hooks';
15
+ import PromptModal from './prompt-modal';
16
 
17
  interface IProps {
18
  messageId: string;
19
  content: string;
20
+ prompt?: string;
21
  }
22
 
23
+ export const AssistantGroupButton = ({
24
+ messageId,
25
+ content,
26
+ prompt,
27
+ }: IProps) => {
28
  const { visible, hideModal, showModal, onFeedbackOk, loading } =
29
  useSendFeedback(messageId);
30
+ const {
31
+ visible: promptVisible,
32
+ hideModal: hidePromptModal,
33
+ showModal: showPromptModal,
34
+ } = useSetModalState();
35
 
36
  const handleLike = useCallback(() => {
37
  onFeedbackOk({ thumbup: true });
 
52
  <Radio.Button value="d" onClick={showModal}>
53
  <DislikeOutlined />
54
  </Radio.Button>
55
+ {prompt && (
56
+ <Radio.Button value="e" onClick={showPromptModal}>
57
+ <SvgIcon name={`prompt`} width={16}></SvgIcon>
58
+ </Radio.Button>
59
+ )}
60
  </Radio.Group>
61
  {visible && (
62
  <FeedbackModal
 
66
  loading={loading}
67
  ></FeedbackModal>
68
  )}
69
+ {promptVisible && (
70
+ <PromptModal
71
+ visible={promptVisible}
72
+ hideModal={hidePromptModal}
73
+ prompt={prompt}
74
+ ></PromptModal>
75
+ )}
76
  </>
77
  );
78
  };
web/src/components/message-item/index.tsx CHANGED
@@ -115,6 +115,7 @@ const MessageItem = ({
115
  <AssistantGroupButton
116
  messageId={item.id}
117
  content={item.content}
 
118
  ></AssistantGroupButton>
119
  ) : (
120
  <UserGroupButton></UserGroupButton>
 
115
  <AssistantGroupButton
116
  messageId={item.id}
117
  content={item.content}
118
+ prompt={item.prompt}
119
  ></AssistantGroupButton>
120
  ) : (
121
  <UserGroupButton></UserGroupButton>
web/src/components/message-item/prompt-modal.tsx ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { IModalProps } from '@/interfaces/common';
2
+ import { IFeedbackRequestBody } from '@/interfaces/request/chat';
3
+ import { Modal, Space } from 'antd';
4
+ import HightLightMarkdown from '../highlight-markdown';
5
+ import SvgIcon from '../svg-icon';
6
+
7
+ const PromptModal = ({
8
+ visible,
9
+ hideModal,
10
+ prompt,
11
+ }: IModalProps<IFeedbackRequestBody> & { prompt?: string }) => {
12
+ return (
13
+ <Modal
14
+ title={
15
+ <Space>
16
+ <SvgIcon name={`prompt`} width={18}></SvgIcon>
17
+ Prompt
18
+ </Space>
19
+ }
20
+ width={'80%'}
21
+ open={visible}
22
+ onCancel={hideModal}
23
+ footer={null}
24
+ >
25
+ <HightLightMarkdown>{prompt}</HightLightMarkdown>
26
+ </Modal>
27
+ );
28
+ };
29
+
30
+ export default PromptModal;
web/src/interfaces/database/chat.ts CHANGED
@@ -68,6 +68,8 @@ export interface Message {
68
  content: string;
69
  role: MessageType;
70
  doc_ids?: string[];
 
 
71
  }
72
 
73
  export interface IReference {
@@ -80,6 +82,8 @@ export interface IAnswer {
80
  answer: string;
81
  reference: IReference;
82
  conversationId?: string;
 
 
83
  }
84
 
85
  export interface Docagg {
 
68
  content: string;
69
  role: MessageType;
70
  doc_ids?: string[];
71
+ prompt?: string;
72
+ id?: string;
73
  }
74
 
75
  export interface IReference {
 
82
  answer: string;
83
  reference: IReference;
84
  conversationId?: string;
85
+ prompt?: string;
86
+ id?: string;
87
  }
88
 
89
  export interface Docagg {