From c61facef13ed0c1cce3265d96c0e81d33bad6efb Mon Sep 17 00:00:00 2001 From: ItzCrazyKns Date: Sat, 18 May 2024 13:11:15 +0530 Subject: [PATCH] feat(message-box): display suggestions --- ui/components/MessageBox.tsx | 52 +++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/ui/components/MessageBox.tsx b/ui/components/MessageBox.tsx index 9712a23..8084d5f 100644 --- a/ui/components/MessageBox.tsx +++ b/ui/components/MessageBox.tsx @@ -4,7 +4,15 @@ import React, { MutableRefObject, useEffect, useState } from 'react'; import { Message } from './ChatWindow'; import { cn } from '@/lib/utils'; -import { BookCopy, Disc3, Share, Volume2, StopCircle } from 'lucide-react'; +import { + BookCopy, + Disc3, + Share, + Volume2, + StopCircle, + Layers3, + Plus, +} from 'lucide-react'; import Markdown from 'markdown-to-jsx'; import Copy from './MessageActions/Copy'; import Rewrite from './MessageActions/Rewrite'; @@ -21,6 +29,7 @@ const MessageBox = ({ dividerRef, isLast, rewrite, + sendMessage, }: { message: Message; messageIndex: number; @@ -29,6 +38,7 @@ const MessageBox = ({ dividerRef?: MutableRefObject; isLast: boolean; rewrite: (messageId: string) => void; + sendMessage: (message: string) => void; }) => { const [parsedMessage, setParsedMessage] = useState(message.content); const [speechMessage, setSpeechMessage] = useState(message.content); @@ -98,9 +108,9 @@ const MessageBox = ({ {loading && isLast ? null : (
- + */}
@@ -124,6 +134,42 @@ const MessageBox = ({
)} + {isLast && + message.suggestions && + message.suggestions.length > 0 && + message.role === 'assistant' && + !loading && ( + <> +
+
+
+ +

Related

+
+
+ {message.suggestions.map((suggestion, i) => ( +
+
+
{ + sendMessage(suggestion); + }} + className="cursor-pointer flex flex-row justify-between font-medium space-x-2 items-center" + > +

+ {suggestion} +

+ +
+
+ ))} +
+
+ + )}