1
1
import { useEffect , useState , useRef } from "react" ;
2
2
import { Button } from "@/components/ui/button" ;
3
3
import { Card , CardHeader , CardContent , CardFooter } from "@/components/ui/card" ;
4
- import { Avatar , AvatarImage , AvatarFallback } from "@/components/ui/avatar" ;
4
+ import { Avatar , AvatarFallback } from "@/components/ui/avatar" ;
5
5
import { Input } from "@/components/ui/input" ;
6
6
7
7
import { v4 as uuidv4 } from "uuid" ;
@@ -13,12 +13,13 @@ import { useToast } from "@/components/ui/use-toast";
13
13
export default function Chatbot ( ) {
14
14
const [ isOpen , setIsOpen ] = useState ( false ) ;
15
15
const [ input , setInput ] = useState ( "" ) ;
16
+ const [ aiModelName , setAiModelName ] = useState ( "" ) ;
16
17
const startArray : object [ ] = [ ] ;
17
18
const [ messages , setMessages ] = useState ( startArray ) ;
18
19
const [ isLoading , setIsLoading ] = useState ( false ) ;
19
20
const client = useLDClient ( ) ;
20
21
const { toast } = useToast ( ) ;
21
- const flags = useFlags ( ) ;
22
+ const aiChatbotFlag = useFlags ( ) [ "ai-chatbot" ] ;
22
23
23
24
const handleInputChange = ( e : any ) => {
24
25
setInput ( e . target . value ) ;
@@ -83,8 +84,14 @@ export default function Chatbot() {
83
84
}
84
85
85
86
useEffect ( ( ) => {
86
- console . log ( "aiChatBot" , flags [ "ai-chatbot" ] ) ;
87
- } , [ messages ] ) ;
87
+ if ( aiChatbotFlag . modelId . includes ( "cohere" ) ) {
88
+ setAiModelName ( "Cohere Coral" ) ;
89
+ } else if ( aiChatbotFlag . modelId . includes ( "meta" ) ) {
90
+ setAiModelName ( "Meta Llama" ) ;
91
+ } else if ( aiChatbotFlag . modelId . includes ( "anthropic" ) ) {
92
+ setAiModelName ( "Anthropic Claude" ) ;
93
+ }
94
+ } , [ aiChatbotFlag ] ) ;
88
95
89
96
const surveyResponseNotification = ( surveyResponse : string ) => {
90
97
client ?. track ( surveyResponse , client . getContext ( ) ) ;
@@ -103,7 +110,6 @@ export default function Chatbot() {
103
110
}
104
111
} , [ messages ] ) ;
105
112
106
- //powered by
107
113
return (
108
114
< >
109
115
< div className = "fixed bottom-4 right-4 z-50" >
@@ -117,7 +123,7 @@ export default function Chatbot() {
117
123
< span className = "sr-only" > Open Chatbot</ span >
118
124
</ Button >
119
125
</ div >
120
- { /* "fixed top-[calc(50%-150px)] left-[calc(90%-100px)] transform -translate-x-1/2 z-50" */ }
126
+
121
127
{ isOpen && (
122
128
< div className = "fixed inset-0 z-50 flex items-end justify-end p-4 sm:p-6 bottom-[50px]" >
123
129
< Card className = "w-full max-w-md border-2 border-grey-400" >
@@ -129,7 +135,9 @@ export default function Chatbot() {
129
135
</ Avatar >
130
136
< div >
131
137
< p className = "text-sm font-medium leading-none" > Chatbot Assistant</ p >
132
- < p className = "text-sm text-gray-500 dark:text-gray-400" > Here to help!</ p >
138
+ < p className = "text-sm text-gray-500 dark:text-gray-400" >
139
+ Powered by { aiModelName }
140
+ </ p >
133
141
</ div >
134
142
</ div >
135
143
< div className = "ml-auto flex items-center space-x-2" >
0 commit comments