Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es1 4 final steps #198

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f505ebb
Setting Up environment
mickey4653 Jun 26, 2024
fdd1bd7
Made some Changes:
mickey4653 Jul 1, 2024
06b8bc0
Made some Changes:
mickey4653 Jul 4, 2024
a707c9e
Made Some Changes and Fix:
mickey4653 Jul 5, 2024
6e309f7
Fix:
mickey4653 Jul 5, 2024
6c7097a
Made some Changes:
mickey4653 Jul 8, 2024
f55318d
Modified Quick Action Buttons:
mickey4653 Jul 10, 2024
c459bfb
Fix:
mickey4653 Jul 10, 2024
f604021
Made Some Changes:
mickey4653 Jul 12, 2024
a769eab
Fix:
mickey4653 Jul 12, 2024
7d07d4e
created new Branch:
mickey4653 Jul 12, 2024
4da7bb0
Fix:
mickey4653 Jul 12, 2024
5e52f6a
Made Some Changes:
mickey4653 Jul 22, 2024
6f666d1
Fix:
mickey4653 Jul 22, 2024
227bed0
Made Some Changes:
mickey4653 Jul 23, 2024
19e072d
Made Some Changes:
mickey4653 Jul 26, 2024
d3953af
Made changes:
mickey4653 Jul 26, 2024
3cd0016
discovery button added
surbhi498 Jul 30, 2024
ae379f5
Made Some Changes:
mickey4653 Jul 30, 2024
479c401
Made Some Changes:
mickey4653 Jul 31, 2024
d5f816e
button alignment:
mickey4653 Aug 5, 2024
cb89a7a
Made Some Changes:
mickey4653 Aug 14, 2024
332cfea
Fix:
mickey4653 Aug 14, 2024
c4c606d
Made Some Changes:
mickey4653 Aug 30, 2024
3a165b1
Fixes:
mickey4653 Aug 30, 2024
df2f596
Made Some Changes:
mickey4653 Sep 3, 2024
876c19c
Made Some Changes & Fixes:
mickey4653 Sep 5, 2024
e29c394
FinalStep page
MisakaZentai Dec 9, 2024
5d419ea
Resolve issues.
MisakaZentai Dec 11, 2024
929af76
Update package-lock.json
MisakaZentai Dec 11, 2024
3698613
resolve issues
MisakaZentai Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"projects": {
"default": "kai-ai-f63c8"
"default": "marvel-onboarding"
},
"targets": {
"kai-ai-f63c8": {
"marvel-onboarding": {
"hosting": {
"next": [
"kai-ai-f63c8"
"marvel-onboarding"
]
}
}
},
"etags": {}
}
"etags": {},
"dataconnectEmulatorConfig": {}
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"eslint.workingDirectories": [
{ "pattern": "./functions/*" },
{ "pattern": "./frontend/*" }
]
],
"Codegeex.Chat.LanguagePreference": "English"
}
8 changes: 4 additions & 4 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2023, 6, 16);
match /chatSessions/{id} {
allow read, write: if request.auth != null && resource.data.user.id == request.auth.uid;
}
}
}
}

Binary file added frontend/assets/images/imageCover1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/assets/images/imagecover2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/assets/images/imagecover3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/assets/images/imagecover4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions frontend/assets/svg/ImageCover1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions frontend/assets/svg/ImageCover2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions frontend/assets/svg/ImageCover3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions frontend/assets/svg/ImageCover4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/assets/svg/ReadyPlayerMeAvatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions frontend/assets/svg/StarGroupIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/assets/svg/Union.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/assets/svg/add-block2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/assets/svg/add-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/assets/svg/arrow-forward-simple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions frontend/constants/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const ROUTES = {
PASSWORD_RESET: '/password-reset',
REDIRECT: '/redirect',
CHAT: '/chat',
DISCOVERY: '/discovery',
HISTORY: '/history',
PROFILE: '/profile',
};

export default ROUTES;
197 changes: 197 additions & 0 deletions frontend/hooks/useChat.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { useEffect, useRef } from 'react';

import { collection, onSnapshot, query, where } from 'firebase/firestore';
import { useDispatch, useSelector } from 'react-redux';

import { MESSAGE_ROLE, MESSAGE_TYPES } from '@/constants/bots';

import {
resetChat,
setChatSession,
setError,
setFullyScrolled,
setInput,
setMessages,
setMore,
setSessionLoaded,
setStreaming,
setStreamingDone,
setTyping,
} from '@/redux/slices/chatSlice';
import { firestore } from '@/redux/store';
import createChatSession from '@/services/chatbot/createChatSession';
import sendMessage from '@/services/chatbot/sendMessage';

const useChat = () => {
const messagesContainerRef = useRef();
const dispatch = useDispatch();
const {
more,
input,
typing,
chat,
sessionLoaded,
openSettingsChat,
infoChatOpened,
fullyScrolled,
streamingDone,
streaming,
error,
} = useSelector((state) => state.chat);
const { data: userData } = useSelector((state) => state.user);
const sessionId = localStorage.getItem('sessionId');
const currentSession = chat;
const chatMessages = currentSession?.messages;
const showNewMessageIndicator = !fullyScrolled && streamingDone;

const startConversation = async (message) => {
dispatch(setMessages({ role: MESSAGE_ROLE.AI }));
dispatch(setTyping(true));

const chatPayload = {
user: {
id: userData?.id,
fullName: userData?.fullName,
email: userData?.email,
},
type: 'chat',
message,
};
const { status, data } = await createChatSession(chatPayload, dispatch);

dispatch(setTyping(false));
if (status === 'created') dispatch(setStreaming(true));
dispatch(setChatSession(data));
dispatch(setSessionLoaded(true));
};

useEffect(() => {
return () => {
localStorage.removeItem('sessionId');
dispatch(resetChat());
};
}, []);

useEffect(() => {
let unsubscribe;

if (sessionLoaded || currentSession) {
messagesContainerRef.current?.scrollTo(
0,
messagesContainerRef.current?.scrollHeight,
{ behavior: 'smooth' }
);

const sessionRef = query(
collection(firestore, 'chatSessions'),
where('id', '==', sessionId)
);
unsubscribe = onSnapshot(sessionRef, async (snapshot) => {
snapshot.docChanges().forEach((change) => {
if (change.type === 'modified') {
const updatedData = change.doc.data();
const updatedMessages = updatedData.messages;
const lastMessage = updatedMessages[updatedMessages.length - 1];
if (lastMessage?.role === MESSAGE_ROLE.AI) {
dispatch(
setMessages({ role: MESSAGE_ROLE.AI, response: lastMessage })
);
dispatch(setTyping(false));
}
}
});
});
}

return () => {
if (sessionLoaded || currentSession) unsubscribe();
};
}, [currentSession, sessionLoaded]);

const handleOnScroll = () => {
const scrolled =
Math.abs(
messagesContainerRef.current.scrollHeight -
messagesContainerRef.current.clientHeight -
messagesContainerRef.current.scrollTop
) <= 1;
if (fullyScrolled !== scrolled) dispatch(setFullyScrolled(scrolled));
};

const handleScrollToBottom = () => {
messagesContainerRef.current?.scrollTo(
0,
messagesContainerRef.current?.scrollHeight,
{ behavior: 'smooth' }
);
dispatch(setStreamingDone(false));
};

const handleSendMessage = async (messages = null) => {
const currentInput = messages || input;
// console.log('Input before sending message:', currentInput);
dispatch(setStreaming(true));
if (!currentInput) {
dispatch(setError('Please enter a message'));
setTimeout(() => dispatch(setError(null)), 3000);
return;
}

const message = {
role: MESSAGE_ROLE.HUMAN,
type: MESSAGE_TYPES.TEXT,
payload: { text: currentInput },
};
if (!chatMessages) {
await startConversation(message);
return;
}

dispatch(setMessages({ role: MESSAGE_ROLE.HUMAN }));
dispatch(setTyping(true));
await sendMessage({ message, id: sessionId }, dispatch);
dispatch(setInput('')); // Clear input after sending message
};

const handleQuickReply = async (option) => {
dispatch(setInput(option));
dispatch(setStreaming(true));
handleSendMessage();
const message = {
role: MESSAGE_ROLE.HUMAN,
type: MESSAGE_TYPES.QUICK_REPLY,
payload: { text: option },
};
dispatch(setMessages({ role: MESSAGE_ROLE.HUMAN }));
dispatch(setTyping(true));
await sendMessage({ message, id: currentSession?.id }, dispatch);
};

const keyDownHandler = async (e) => {
if (typing || !input || streaming) return;
if (e.keyCode === 13) handleSendMessage();
};

return {
messagesContainerRef,
dispatch,
input,
setInput,
setMore,
typing,
streaming,
chatMessages,
showNewMessageIndicator,
error,
openSettingsChat,
infoChatOpened,
handleOnScroll,
handleScrollToBottom,
handleSendMessage,
handleQuickReply,
keyDownHandler,
fullyScrolled,
};
};

export default useChat;
Loading