1
1
"use client" ;
2
2
import { useEffect , useRef , useState } from 'react' ;
3
3
import Bubble from '../components/Bubble'
4
- import { useChat } from 'ai/react' ;
4
+ import { useChat , Message } from 'ai/react' ;
5
5
import Footer from '../components/Footer' ;
6
6
import Configure from '../components/Configure' ;
7
+ import PromptSuggestionRow from '../components/PromptSuggestions/PromptSuggestionsRow' ;
7
8
import ThemeButton from '../components/ThemeButton' ;
8
9
import useConfiguration from './hooks/useConfiguration' ;
9
10
11
+
10
12
export default function Home ( ) {
11
- const { messages, input, handleInputChange, handleSubmit } = useChat ( ) ;
13
+ const { append , messages, input, handleInputChange, handleSubmit } = useChat ( ) ;
12
14
const { useRag, llm, similarityMetric, setConfiguration } = useConfiguration ( ) ;
13
15
14
16
const messagesEndRef = useRef ( null ) ;
@@ -26,6 +28,11 @@ export default function Home() {
26
28
handleSubmit ( e , { options : { body : { useRag, llm, similarityMetric} } } ) ;
27
29
}
28
30
31
+ const handlePrompt = ( promptText ) => {
32
+ const msg : Message = { id : crypto . randomUUID ( ) , content : promptText , role : 'user' } ;
33
+ append ( msg , { options : { body : { useRag, llm, similarityMetric} } } ) ;
34
+ } ;
35
+
29
36
return (
30
37
< >
31
38
< main className = "flex h-screen flex-col items-center justify-center" >
@@ -54,6 +61,9 @@ export default function Home() {
54
61
{ messages . map ( ( message , index ) => < Bubble ref = { messagesEndRef } key = { `message-${ index } ` } content = { message } /> ) }
55
62
</ div >
56
63
</ div >
64
+ { ! messages || messages . length === 0 && (
65
+ < PromptSuggestionRow onPromptClick = { handlePrompt } />
66
+ ) }
57
67
< form className = 'flex h-[40px] gap-2' onSubmit = { handleSend } >
58
68
< input onChange = { handleInputChange } value = { input } className = 'chatbot-input flex-1 text-sm md:text-base outline-none bg-transparent rounded-md p-2' placeholder = 'Send a message...' />
59
69
< button type = "submit" className = 'chatbot-send-button flex rounded-md items-center justify-center px-2.5 origin:px-3' >
0 commit comments