From fd7017e48a96629f370137c7df573136460bedd1 Mon Sep 17 00:00:00 2001 From: Salmen Hichri Date: Wed, 15 May 2024 04:04:06 +0100 Subject: [PATCH] Updated custom comp in samples --- .../react/core/src/exports/messageOptions.tsx | 2 +- .../logic/MessageRenderer/MessageRenderer.tsx | 2 +- samples/aiChat/react/src/App.tsx | 25 +++++++++++++++++-- .../react/src/comp/AiChatReactExpo.tsx | 4 ++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/react/core/src/exports/messageOptions.tsx b/packages/react/core/src/exports/messageOptions.tsx index bb95fde7..269cd86e 100644 --- a/packages/react/core/src/exports/messageOptions.tsx +++ b/packages/react/core/src/exports/messageOptions.tsx @@ -5,7 +5,7 @@ export type ResponseComponentProps = { uid: string; status: 'streaming' | 'complete'; response?: AiMsg; - containerRef: RefObject; + containerRef: RefObject; }; export type ResponseComponent = FunctionComponent>; diff --git a/packages/react/core/src/logic/MessageRenderer/MessageRenderer.tsx b/packages/react/core/src/logic/MessageRenderer/MessageRenderer.tsx index c449c5f7..5a1d89d0 100644 --- a/packages/react/core/src/logic/MessageRenderer/MessageRenderer.tsx +++ b/packages/react/core/src/logic/MessageRenderer/MessageRenderer.tsx @@ -35,7 +35,7 @@ export const createMessageRenderer: ( status, // We only pass the response to custom renderer when the status is 'complete'. response: status === 'complete' ? message as AiMsg : undefined, - containerRef: containerRefToUse, + containerRef: containerRefToUse as RefObject, }); } diff --git a/samples/aiChat/react/src/App.tsx b/samples/aiChat/react/src/App.tsx index 64d7fc66..bf89ed62 100644 --- a/samples/aiChat/react/src/App.tsx +++ b/samples/aiChat/react/src/App.tsx @@ -81,10 +81,31 @@ function App() { syntaxHighlighter: highlighter, // showCodeBlockCopyButton: false, // streamingAnimationSpeed: 100, - responseComponent: ({response}) => { + promptComponent: ({prompt}) => { return (
-
{response}
+
{prompt}
+
Custom Prompt Component +
+
+ ); + }, + responseComponent: ({ + response, + status, + containerRef, + }) => { + console.log(status); + return ( +
+ {response ?
{response}
:
}
> = ( +const CustomMessageComponent: FunctionComponent< + ResponseComponentProps +> = ( {response}, ) => { const color = useMemo(() => possibleColors[Math.floor(Math.random() * possibleColors.length)], []);