From 33f4ab7b42aa4040587e395b9cfe3575c2d8a2f2 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Fri, 10 Nov 2023 17:12:57 +0800 Subject: [PATCH] fix copy render msg --- src/chatgpt.ts | 8 ++++ src/global.css | 2 +- src/message.tsx | 120 ++++++++++++++++++++++++++++++------------------ 3 files changed, 85 insertions(+), 45 deletions(-) diff --git a/src/chatgpt.ts b/src/chatgpt.ts index 6704c46..748476a 100644 --- a/src/chatgpt.ts +++ b/src/chatgpt.ts @@ -47,6 +47,14 @@ export interface StreamingResponseChunk { } export const getMessageText = (message: Message): string => { if (typeof message.content === "string") { + // function call message + if (message.tool_calls) { + return message.tool_calls + .map((tc) => { + return `Tool Call ID: ${tc.id}\nType: ${tc.type}\nFunction: ${tc.function.name}\nArguments: ${tc.function.arguments}}`; + }) + .join("\n"); + } return message.content; } return message.content diff --git a/src/global.css b/src/global.css index f67213a..c951762 100644 --- a/src/global.css +++ b/src/global.css @@ -28,6 +28,6 @@ body::-webkit-scrollbar { display: none; } -p.message-content { +.message-content { white-space: pre-wrap; } diff --git a/src/message.tsx b/src/message.tsx index b7f8f1e..94c2a4b 100644 --- a/src/message.tsx +++ b/src/message.tsx @@ -245,14 +245,18 @@ export default function Message(props: Props) { ); - const CopyIcon = () => { + const copyToClipboard = (text: string) => { + navigator.clipboard.writeText(text); + setShowCopiedHint(true); + setTimeout(() => setShowCopiedHint(false), 1000); + }; + + const CopyIcon = ({ textToCopy }: { textToCopy: string }) => { return ( <>