Skip to content

Commit 3061a1d

Browse files
add copy button (#206)
1 parent 7f5974e commit 3061a1d

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

ui/src/pages/RagChatTab/ChatOutput/ChatMessages/ChatMessageBody.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import Markdown from "react-markdown";
4646
import Remark from "remark-gfm";
4747
import { Evaluations } from "pages/RagChatTab/ChatOutput/ChatMessages/Evaluations.tsx";
4848
import RatingFeedbackWrapper from "pages/RagChatTab/ChatOutput/ChatMessages/RatingFeedbackWrapper.tsx";
49+
import CopyButton from "pages/RagChatTab/ChatOutput/ChatMessages/CopyButton.tsx";
4950

5051
export const ChatMessageBody = ({ data }: { data: ChatMessageType }) => {
5152
return (
@@ -96,6 +97,7 @@ export const ChatMessageBody = ({ data }: { data: ChatMessageType }) => {
9697
</Markdown>
9798
</Typography.Text>
9899
<Flex gap={16} align="center">
100+
<CopyButton message={data} />
99101
<Evaluations evaluations={data.evaluations} />
100102
<RatingFeedbackWrapper responseId={data.id} />
101103
</Flex>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* CLOUDERA APPLIED MACHINE LEARNING PROTOTYPE (AMP)
3+
* (C) Cloudera, Inc. 2025
4+
* All rights reserved.
5+
*
6+
* Applicable Open Source License: Apache 2.0
7+
*
8+
* NOTE: Cloudera open source products are modular software products
9+
* made up of hundreds of individual components, each of which was
10+
* individually copyrighted. Each Cloudera open source product is a
11+
* collective work under U.S. Copyright Law. Your license to use the
12+
* collective work is as provided in your written agreement with
13+
* Cloudera. Used apart from the collective work, this file is
14+
* licensed for your use pursuant to the open source license
15+
* identified above.
16+
*
17+
* This code is provided to you pursuant a written agreement with
18+
* (i) Cloudera, Inc. or (ii) a third-party authorized to distribute
19+
* this code. If you do not have a written agreement with Cloudera nor
20+
* with an authorized and properly licensed third party, you do not
21+
* have any rights to access nor to use this code.
22+
*
23+
* Absent a written agreement with Cloudera, Inc. ("Cloudera") to the
24+
* contrary, A) CLOUDERA PROVIDES THIS CODE TO YOU WITHOUT WARRANTIES OF ANY
25+
* KIND; (B) CLOUDERA DISCLAIMS ANY AND ALL EXPRESS AND IMPLIED
26+
* WARRANTIES WITH RESPECT TO THIS CODE, INCLUDING BUT NOT LIMITED TO
27+
* IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND
28+
* FITNESS FOR A PARTICULAR PURPOSE; (C) CLOUDERA IS NOT LIABLE TO YOU,
29+
* AND WILL NOT DEFEND, INDEMNIFY, NOR HOLD YOU HARMLESS FOR ANY CLAIMS
30+
* ARISING FROM OR RELATED TO THE CODE; AND (D)WITH RESPECT TO YOUR EXERCISE
31+
* OF ANY RIGHTS GRANTED TO YOU FOR THE CODE, CLOUDERA IS NOT LIABLE FOR ANY
32+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR
33+
* CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, DAMAGES
34+
* RELATED TO LOST REVENUE, LOST PROFITS, LOSS OF INCOME, LOSS OF
35+
* BUSINESS ADVANTAGE OR UNAVAILABILITY, OR LOSS OR CORRUPTION OF
36+
* DATA.
37+
*/
38+
39+
import { ChatMessageType } from "src/api/chatApi.ts";
40+
import messageQueue from "src/utils/messageQueue.ts";
41+
import { Button, Tooltip } from "antd";
42+
import { CopyOutlined } from "@ant-design/icons";
43+
44+
const CopyButton = ({ message }: { message: ChatMessageType }) => {
45+
return (
46+
<Tooltip title="Copy the assistant's response">
47+
<Button
48+
onClick={() => {
49+
navigator.clipboard
50+
.writeText(message.rag_message.assistant)
51+
.catch(() => {
52+
messageQueue.error("Failed to copy to clipboard");
53+
});
54+
}}
55+
type="text"
56+
icon={<CopyOutlined />}
57+
/>
58+
</Tooltip>
59+
);
60+
};
61+
export default CopyButton;

0 commit comments

Comments
 (0)