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

Feature/f 146 integrate chatbot reports chatting #117

Merged
merged 16 commits into from
Dec 15, 2024

Conversation

ahmtslmngcl
Copy link
Collaborator

@ahmtslmngcl ahmtslmngcl commented Dec 8, 2024

Implement Report Chat Functionality and According Chatbot Accessibility

Changes Introduced:

Chat with Reports in DownloadPortal

  • Added functionality to chat with report contents when the button in the DownloadPortal is clicked.
  • Implemented PDF text extraction to retrieve information from reports, which is sent to the backend (BE) for further processing.
  • Updated the BE system prompt to ensure the chatbot understands it's interacting with report data (refer to corresponding BE Repo PR for details).

Global Chatbot Access

  • Integrated the chatbot into the top bar, making it accessible across all pages of the application.
  • Implemented local data storage of the chats for 1 week which also ensures conversation consistency when navigating between sites.

I also explored alternative methods for extracting additional PDF information, including OCR and OpenAI Assistant, text extraction approach seems to be effective and sufficient for our case

Edit: Chatbot was removed from the Topbar component itself and was placed into the layout files of the pages. The visual positioning still is the same. This allows easier usage of the Topbar without the Chatbot for example in the error page later on.

Copy link

netlify bot commented Dec 8, 2024

Deploy Preview for wfp-hungermap ready!

Name Link
🔨 Latest commit 5823e9b
🔍 Latest deploy log https://app.netlify.com/sites/wfp-hungermap/deploys/675f14b659cee6000833b8cb
😎 Deploy Preview https://deploy-preview-117--wfp-hungermap.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ahmtslmngcl ahmtslmngcl marked this pull request as ready for review December 13, 2024 13:58
Copy link
Collaborator

@marinovl7 marinovl7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall valuable improvements, thanks for thinking about the context and local storage! Also one more thing I noticed, on mobile the chatbot icon in the Topbar is displayed over the theme toggle, I think it would be nice to actually put the theme toggle in the mobile bar for smaller screens. Could you do that as well?

Comment on lines 309 to 314
)}
style={{
wordWrap: 'break-word',
overflowWrap: 'break-word',
whiteSpace: 'normal',
}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use className from tailwind, we do not use the style prop

@@ -33,6 +34,7 @@ export default function CountryReports({ countryCodesData }: CountryReportsProps
data={DownloadPortalOperations.formatTableData(
filteredData,
setSelectedCountry,
useChatbot().chatWithReport,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this into const

const chatBot = useChatbot()
const { chatWithReport } = chatbot

setCurrentChatIndex: React.Dispatch<React.SetStateAction<number>>;
openChat: (chatIndex: number) => void;
startNewChat: (newChat?: IChat) => void;
chatWithReport: (countryName: string, report: string) => Promise<void>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chatWithReport is a little bit weird naming. Can it be more precise? At least I don't understand what it is about

Comment on lines 53 to 61
return [
{
id: 1,
title: 'Chat 1',
messages: [],
isTyping: false,
timestamp: Date.now(),
},
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code duplication with the thing above

Comment on lines +64 to +72
return [
{
id: 1,
title: 'Chat 1',
messages: [],
isTyping: false,
timestamp: Date.now(),
},
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code duplication with the thing above

Comment on lines 76 to 84
if (typeof window !== 'undefined') {
const chatsWithTimestamp = chats.map((chat) => ({
...chat,
timestamp: chat.timestamp || Date.now(),
}));

localStorage.setItem('chatbotChatsWithTimestamp', JSON.stringify(chatsWithTimestamp));
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add error handling if window is undefined with the Snackbar

Comment on lines 41 to 43
} catch (error) {
throw new Error(`Error extracting text from PDF: ${error}`);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better Error Handling with the Snackbar is required

@marinovl7 marinovl7 mentioned this pull request Dec 15, 2024
5 tasks
@marinovl7 marinovl7 merged commit c26db7f into main Dec 15, 2024
5 checks passed
@marinovl7 marinovl7 deleted the feature/f-146-integrate-chatbot-reports-chatting branch December 15, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants