From 3afa826fb96e969279a2036401ef9a7e9767bd7f Mon Sep 17 00:00:00 2001 From: litongjava Date: Tue, 4 Feb 2025 19:15:54 -1000 Subject: [PATCH] feat: add sources of user --- ui/components/ChatWindow.tsx | 2 +- ui/components/MessageBox.tsx | 69 +++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index 4808f49..54c4b49 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -352,7 +352,7 @@ const loadMessages = async ( const messages = data.messages.map((msg: any) => { return { ...msg, - ...JSON.parse(msg.metadata), + // ...JSON.parse(msg.metadata), }; }) as Message[]; diff --git a/ui/components/MessageBox.tsx b/ui/components/MessageBox.tsx index f23127c..64cbe2a 100644 --- a/ui/components/MessageBox.tsx +++ b/ui/components/MessageBox.tsx @@ -1,9 +1,9 @@ 'use client'; /* eslint-disable @next/next/no-img-element */ -import React, { MutableRefObject, useEffect, useState } from 'react'; -import { Message } from './ChatWindow'; -import { cn } from '@/lib/utils'; +import React, {MutableRefObject, useEffect, useState} from 'react'; +import {Message} from './ChatWindow'; +import {cn} from '@/lib/utils'; import { BookCopy, Disc3, @@ -18,18 +18,18 @@ import Rewrite from './MessageActions/Rewrite'; import MessageSources from './MessageSources'; import SearchImages from './SearchImages'; import SearchVideos from './SearchVideos'; -import { useSpeech } from 'react-text-to-speech'; +import {useSpeech} from 'react-text-to-speech'; const MessageBox = ({ - message, - messageIndex, - history, - loading, - dividerRef, - isLast, - rewrite, - sendMessage, -}: { + message, + messageIndex, + history, + loading, + dividerRef, + isLast, + rewrite, + sendMessage, + }: { message: Message; messageIndex: number; history: Message[]; @@ -63,7 +63,7 @@ const MessageBox = ({ setParsedMessage(message.content); }, [message.content, message.sources, message.role]); - const { speechStatus, start, stop } = useSpeech({ text: speechMessage }); + const {speechStatus, start, stop} = useSpeech({text: speechMessage}); return (
@@ -72,6 +72,23 @@ const MessageBox = ({

{message.content}

+
+ + {message.sources && message.sources.length > 0 && ( +
+
+ +

+ Sources +

+
+ +
+ )} +
)} @@ -84,12 +101,12 @@ const MessageBox = ({ {message.sources && message.sources.length > 0 && (
- +

Sources

- +
)}
@@ -114,15 +131,16 @@ const MessageBox = ({ {parsedMessage} {loading && isLast ? null : ( -
+
{/* */} - +
- +
@@ -148,10 +166,10 @@ const MessageBox = ({ message.role === 'assistant' && !loading && ( <> -
+
- +

Related

@@ -160,7 +178,7 @@ const MessageBox = ({ className="flex flex-col space-y-3 text-sm" key={i} > -
+
{ sendMessage(suggestion); @@ -183,7 +201,8 @@ const MessageBox = ({ )}
-
+