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

Task 3 updates [New components from chat interface, Discovery Library UI changes from figma update] #135

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d78a5be
hasOwnProperty
Mezwer Jun 29, 2024
71895da
es1.2 and es1.3 done, merged backend functionality with frontend
Mezwer Jun 29, 2024
0352e77
es1.2 and es1.3 done, merged backend functionality with frontend
Mezwer Jun 29, 2024
8b75023
bug fixes with loading sessions
Mezwer Jul 2, 2024
0bfc042
minor style changes
Mezwer Jul 3, 2024
4dab15c
Default prompts frontend es 3.1 updates
prasanthmanda Jul 10, 2024
23b49a6
merged ES3.1 and ES3.2 functionalities
Mezwer Jul 17, 2024
e081df9
required for generating prompts
Mezwer Jul 17, 2024
a3e1060
added prompt displaying
lingyundai Jul 22, 2024
2e166dc
default prompts only on chat start
Mezwer Jul 29, 2024
012f653
changed ui format & styling
Mezwer Aug 5, 2024
29aa4cb
merged all changes:
Mezwer Aug 5, 2024
6592d41
Merge branch 'Task-3-Updates' of https://github.com/Mezwer/kai-platfo…
mickey4653 Aug 6, 2024
c91fb1d
minor style changes:
Mezwer Aug 6, 2024
52a3929
Made Some Changes:
mickey4653 Aug 12, 2024
e17406b
Merge branch 'Task-3-Updates' of https://github.com/Mezwer/kai-platfo…
mickey4653 Aug 12, 2024
3df956f
Made Some Changes:
mickey4653 Aug 12, 2024
1efea8d
Made Some Changes:
mickey4653 Aug 19, 2024
ad9e549
- Renamed text in chat button to new chat button
mickey4653 Aug 19, 2024
72a3b16
Merge branch 'Task-3-Updates'
mickey4653 Aug 28, 2024
78b9f49
Made some Changes: PR review changes
mickey4653 Sep 10, 2024
029f091
Fix:
mickey4653 Sep 10, 2024
c594998
Made Some Changes:
mickey4653 Sep 18, 2024
2f16982
Merge branch 'main' of https://github.com/Mezwer/kai-platform
mickey4653 Sep 18, 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
8 changes: 6 additions & 2 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"projects": {
"default": "kai-ai-f63c8"
"default": "kai-ai-f63c8",
"kai-app": "kai-platform-b53aa",
"kai-app1": "kai-platform-b53aa"
},
"targets": {
"kai-ai-f63c8": {
"kai-ai-f63c8": {
"hosting": {
"next": [
"kai-ai-f63c8"
"kai-ai-f63c8"
]
}
}
},
"etags": {}
}
}
21 changes: 21 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on PR
on: pull_request
permissions:
checks: write
contents: read
pull-requests: write
jobs:
build_and_preview:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: next build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KAI_AI_F63C8 }}
projectId: kai-40de1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ dist

# Ignore back-end build output
**/node_modules/
**/build/
**/build/
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.
9 changes: 9 additions & 0 deletions frontend/assets/svg/UnionPurple.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.
25 changes: 25 additions & 0 deletions frontend/constants/prompts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const categorizePrompts = [
{
title: 'Math Tutor',
description:
'From now on, I want you to act as a math tutor. I will be asking you questions related to various mathematical concepts, including algebra, geometry, calculus, and statistics. Please provide detailed explanations, step-by-step solutions, and relevant examples for each topic we discuss.',
},
{
title: 'Biology Tutor',
description:
'Please act as my biology tutor. I will ask you about topics such as cell biology, genetics, evolution, ecology, and human anatomy. Provide comprehensive explanations, diagrams, and examples to help me understand these biological concepts.',
},
{
title: 'Programming Tutor',
description:
'I want you to be my programming tutor. I will ask you about various programming languages, coding concepts, algorithms, and debugging techniques. Provide clear explanations, code examples, and step-by-step guidance for writing and understanding code.',
},
{
title: 'Music Tutor',
description:
'Act as a music tutor for our conversation. I will ask you about music theory, instruments, composition, and performance techniques. Provide detailed explanations, sheet music examples, and exercises to help me understand and improve my musical abilities.',
},
// Add more prompts as needed
];

export default categorizePrompts;
2 changes: 1 addition & 1 deletion frontend/layouts/MainAppLayout/SideMenu/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const styles = {
mainGridProps: {
container: true,
item: true,
width: '360px',
width: '300px',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
Expand Down
17 changes: 17 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions frontend/services/ChatHistory/chatHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
collection,
getDocs,
getFirestore,
query,
where,
} from 'firebase/firestore';
import moment from 'moment';

const db = getFirestore();

/**
* Takes in a Date object and returns the "timeframe" of the date (whether it's today, yesterday, this week, etc.).
* Returns the year of the date if it's >1 year in the past.
* @param {Date} date - date to be processed
* @returns {number | string}
*/
const processDate = (date) => {
const now = moment(); // Current date/time
const inputDate = moment(date); // Convert the input date

if (now.isSame(inputDate, 'day')) {
return 'Today';
}
if (now.subtract(1, 'days').isSame(inputDate, 'day')) {
return 'Yesterday';
}
if (now.isSame(inputDate, 'week')) {
return 'This Week';
}
if (now.isSame(inputDate, 'month')) {
return 'This Month';
}
if (now.isSame(inputDate, 'year')) {
return 'This Year';
}
return inputDate.format('YYYY'); // Return year if it's older than this year
};

const fetchChatHistory = async (userData) => {
// get chat history data
const q = query(
collection(db, 'chatSessions'),
where('user', '==', userData)
);
const querySnapshot = await getDocs(q);
const history = [];
querySnapshot.forEach((document) => {
history.push({
...document.data(),
});
});

const sortedHistory = {};
history.sort((a, b) => {
return b.updatedAt.toDate() - a.updatedAt.toDate();
});

history.forEach((data) => {
const timeframe = processDate(data.updatedAt.toDate());
const msgItem = {
id: data.id,
timestamp: data.updatedAt,
message: data.messages[0].payload.text,
};

if (Object.prototype.hasOwnProperty.call(sortedHistory, timeframe))
sortedHistory[timeframe].push(msgItem);
else sortedHistory[timeframe] = [msgItem];
});

return sortedHistory;
};

export { fetchChatHistory };
16 changes: 16 additions & 0 deletions frontend/services/chatbot/generatePrompts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { httpsCallable } from 'firebase/functions';

import { functions } from '@/redux/store';

const generatePrompts = async (payload) => {
try {
const genPrompts = httpsCallable(functions, 'generatePrompts');
const response = await genPrompts(payload);

return response.data;
} catch (error) {
throw new Error('Error could not generate prompts');
}
};

export default generatePrompts;
75 changes: 75 additions & 0 deletions frontend/services/chathistory/chatHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
collection,
getDocs,
getFirestore,
query,
where,
} from 'firebase/firestore';
import moment from 'moment';

const db = getFirestore();

/**
* Takes in a Date object and returns the "timeframe" of the date (whether it's today, yesterday, this week, etc.).
* Returns the year of the date if it's >1 year in the past.
* @param {Date} date - date to be processed
* @returns {number | string}
*/
const processDate = (date) => {
const now = moment(); // Current date/time
const inputDate = moment(date); // Convert the input date

if (now.isSame(inputDate, 'day')) {
return 'Today';
}
if (now.subtract(1, 'days').isSame(inputDate, 'day')) {
return 'Yesterday';
}
if (now.isSame(inputDate, 'week')) {
return 'This Week';
}
if (now.isSame(inputDate, 'month')) {
return 'This Month';
}
if (now.isSame(inputDate, 'year')) {
return 'This Year';
}
return inputDate.format('YYYY'); // Return year if it's older than this year
};

const fetchChatHistory = async (userData) => {
// get chat history data
const q = query(
collection(db, 'chatSessions'),
where('user', '==', userData)
);
const querySnapshot = await getDocs(q);
const history = [];
querySnapshot.forEach((document) => {
history.push({
...document.data(),
});
});

const sortedHistory = {};
history.sort((a, b) => {
return b.updatedAt.toDate() - a.updatedAt.toDate();
});

history.forEach((data) => {
const timeframe = processDate(data.updatedAt.toDate());
const msgItem = {
id: data.id,
timestamp: data.updatedAt,
message: data.messages[0].payload.text,
};

if (Object.prototype.hasOwnProperty.call(sortedHistory, timeframe))
sortedHistory[timeframe].push(msgItem);
else sortedHistory[timeframe] = [msgItem];
});

return sortedHistory;
};

export { fetchChatHistory };
Loading