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

Added Chatbot #537

Open
wants to merge 117 commits into
base: main
Choose a base branch
from
Open

Added Chatbot #537

wants to merge 117 commits into from

Conversation

sreevidya-16
Copy link

@sreevidya-16 sreevidya-16 commented Jul 23, 2024

Description

Adding a chatbot to Paws will significantly enhance user engagement and support by providing instant assistance and guidance on reporting injured animals.

The chatbot will facilitate seamless communication between users, NGOs, and animal hospitals, ensuring that reports are efficiently directed to the appropriate parties.

This feature will streamline the process of helping stray injured animals, making the platform more responsive and effective in addressing animal welfare concerns

Related Issue

Resolves #534 Issue

Screenshots / GIFs (if applicable)

[Attach any relevant screenshots or GIFs demonstrating the changes]

Checklist:

  • I have performed a self-review of my code
  • I have added/updated relevant documentation (if needed)
  • I have tested the changes locally and they function as expected
  • I have ensured my code follows the project's coding standards

Additional Notes

[Add any additional notes or context about the changes made]

@itsekta, could you please approve this pull request

Summary by CodeRabbit

  • New Features

    • Introduced a new AI chatbot named "Snapitizer" capable of engaging in conversations based on user input.
    • Added an intents document to define structured conversational intents to enhance user interaction regarding animal welfare services.
    • Implemented natural language processing utilities for better text handling and understanding.
    • Established a training pipeline for the chatbot model to improve its responsiveness and accuracy.
  • Documentation

    • Added comprehensive documentation for the AI chatbot, outlining its purpose, features, and customization options for users.

suhanipaliwal and others added 30 commits May 11, 2024 20:27
removed unnecessary commented part.
…ModuleFile

[FIX] - Module.css files removed and Tailwind CSS applied.
Added Nearest NGO Info in Success Page
taneeshaa15 and others added 27 commits July 2, 2024 20:46
* R

* now

* G

* FINALLLLL

---------

Co-authored-by: Arnab Mondal <[email protected]>
	modified:   src/pages/user/UserRegistration.jsx
* added a happy recovery story page

* updated

* original Navbar.jsx
	modified:   src/pages/user/ReportIncidentPages/FeedbackForm/Feedback.jsx
	modified:   src/App.jsx
* Updated Error Page.

* new
Copy link

coderabbitai bot commented Jul 23, 2024

Walkthrough

The recent changes introduce a chatbot named "Snapitizer" to the Paws platform, enhancing user engagement through natural language processing capabilities. The chatbot leverages a neural network model for intent recognition and utilizes a structured set of intents for dynamic interactions. Additionally, the implementation includes necessary documentation and utilities for easy customization and training, significantly improving the platform's responsiveness to user inquiries about animal welfare.

Changes

Files Change Summary
AI_CHATBOT/README.md Introduces documentation for the chatbot, outlining its purpose and customization options.
AI_CHATBOT_PAWS/chat.py Implements the chatbot's conversation loop, processing user inputs and responding based on intent recognition with a neural network model.
AI_CHATBOT_PAWS/intents.json Defines conversational intents with tags, patterns, and responses to enhance user interaction focused on animal welfare services.
AI_CHATBOT_PAWS/model.py Introduces the NeuralNet class for the chatbot’s neural network architecture, defining layers and the forward pass for intent classification.
AI_CHATBOT_PAWS/nltk_utils.py Contains utility functions for tokenization, stemming, and creating a bag-of-words representation for natural language processing.
AI_CHATBOT_PAWS/train.py Provides a training pipeline for the chatbot model, including data preparation, model training, and saving the trained model.

Assessment against linked issues

Objective Addressed Explanation
Facilitate seamless communication regarding animal welfare (Issue #534)
Enhance user engagement through instant assistance (Issue #534)
Provide guidance on reporting injured animals (Issue #534)

Poem

Hop, hop, hooray, my friend!
A chatbot's here to lend a hand.
With words and thoughts, it will assist,
In caring for critters, it can't be missed!
So ask away, don't be shy,
For Snapitizer's ready to reply! 🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aeec142 and 8ac0255.

Files selected for processing (6)
  • AI_CHATBOT_PAWS/README.md (1 hunks)
  • AI_CHATBOT_PAWS/chat.py (1 hunks)
  • AI_CHATBOT_PAWS/intents.json (1 hunks)
  • AI_CHATBOT_PAWS/model.py (1 hunks)
  • AI_CHATBOT_PAWS/nltk_utils.py (1 hunks)
  • AI_CHATBOT_PAWS/train.py (1 hunks)
Additional context used
LanguageTool
AI_CHATBOT_PAWS/README.md

[uncategorized] ~3-~3: Possible missing comma found.
Context: ...it NLTK, pytorch
I have developed this bot
Feel free to update the intents.json ...

(AI_HYDRA_LEO_MISSING_COMMA)

Ruff
AI_CHATBOT_PAWS/model.py

1-1: torch imported but unused

Remove unused import: torch

(F401)

AI_CHATBOT_PAWS/train.py

2-2: random imported but unused

Remove unused import: random

(F401)

Additional comments not posted (21)
AI_CHATBOT_PAWS/nltk_utils.py (3)

1-5: LGTM!

The imports and initialization are appropriate.


7-8: LGTM!

The tokenize function correctly uses NLTK's word_tokenize function.


11-12: LGTM!

The stem function correctly uses the PorterStemmer.

AI_CHATBOT_PAWS/model.py (2)

5-11: LGTM!

The NeuralNet class and __init__ method are implemented correctly.


13-19: LGTM!

The forward method is implemented correctly.

AI_CHATBOT_PAWS/chat.py (2)

24-26: LGTM!

The model loading and evaluation setup is correct.


48-53: LGTM!

The response generation logic is correct and handles cases where the model is not confident.

AI_CHATBOT_PAWS/train.py (4)

18-29: LGTM!

The data preprocessing logic is correct and efficient.


54-70: LGTM!

The dataset and dataloader setup is correct.


79-91: LGTM!

The model training loop is correct and efficient.


96-108: LGTM!

The model saving logic is correct.

AI_CHATBOT_PAWS/intents.json (10)

3-17: LGTM!

The patterns and responses for the greeting intent are appropriate and cover common greeting phrases.


18-26: LGTM!

The patterns and responses for the goodbye intent are appropriate and cover common goodbye phrases.


27-35: LGTM!

The patterns and responses for the thanks intent are appropriate and cover common phrases for expressing gratitude.


36-47: LGTM!

The patterns and responses for the mission intent are appropriate and provide clear information about the platform's mission.


48-57: LGTM!

The patterns and responses for the hackathon intent are appropriate and provide clear information about the hackathon.


60-69: LGTM!

The patterns and responses for the features intent are appropriate and provide clear information about the platform's features.


71-80: LGTM!

The patterns and responses for the report_animal intent are appropriate and provide clear information about reporting an injured animal.


82-90: LGTM!

The patterns and responses for the volunteer intent are appropriate and provide clear information about volunteering.


93-101: LGTM!

The patterns and responses for the donate intent are appropriate and provide clear information about donations.


104-123: LGTM!

The patterns and responses for the awareness and contact intents are appropriate and provide clear information about awareness campaigns and contact information.

Comment on lines +1 to +4
# AI_CHATBOT
It is an Ai chatbot developed using natural language toolkit NLTK, pytorch
I have developed this bot
Feel free to update the intents.json to make the domain of the chatbot wider.
Copy link

Choose a reason for hiding this comment

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

Improve documentation clarity and fix grammatical issue.

The documentation can be enhanced for better readability. Additionally, there is a missing comma after "pytorch".

- It is an Ai chatbot developed using natural language toolkit NLTK, pytorch
- I have developed this bot
+ It is an AI chatbot developed using the Natural Language Toolkit (NLTK) and PyTorch.
+ This bot has been developed to assist users.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# AI_CHATBOT
It is an Ai chatbot developed using natural language toolkit NLTK, pytorch
I have developed this bot
Feel free to update the intents.json to make the domain of the chatbot wider.
# AI_CHATBOT
It is an AI chatbot developed using the Natural Language Toolkit (NLTK) and PyTorch.
This bot has been developed to assist users.
Feel free to update the intents.json to make the domain of the chatbot wider.
Tools
LanguageTool

[uncategorized] ~3-~3: Possible missing comma found.
Context: ...it NLTK, pytorch
I have developed this bot
Feel free to update the intents.json ...

(AI_HYDRA_LEO_MISSING_COMMA)

Comment on lines +15 to +23
def bag_of_words(tokenized_sentence, words):

sentence_words = [stem(word) for word in tokenized_sentence]
bag = np.zeros(len(words), dtype=np.float32)
for idx, w in enumerate(words):
if w in sentence_words:
bag[idx] = 1

return bag
Copy link

Choose a reason for hiding this comment

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

Enhance readability and clarity.

Add a docstring for clarity and remove unnecessary blank lines.

+ def bag_of_words(tokenized_sentence, words):
+     """
+     Create a bag of words representation.
+ 
+     Args:
+         tokenized_sentence (list): Tokenized sentence.
+         words (list): List of words.
+ 
+     Returns:
+         numpy.ndarray: Bag of words representation.
+     """
      sentence_words = [stem(word) for word in tokenized_sentence]
      bag = np.zeros(len(words), dtype=np.float32)
      for idx, w in enumerate(words):
          if w in sentence_words: 
              bag[idx] = 1
      return bag
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def bag_of_words(tokenized_sentence, words):
sentence_words = [stem(word) for word in tokenized_sentence]
bag = np.zeros(len(words), dtype=np.float32)
for idx, w in enumerate(words):
if w in sentence_words:
bag[idx] = 1
return bag
def bag_of_words(tokenized_sentence, words):
"""
Create a bag of words representation.
Args:
tokenized_sentence (list): Tokenized sentence.
words (list): List of words.
Returns:
numpy.ndarray: Bag of words representation.
"""
sentence_words = [stem(word) for word in tokenized_sentence]
bag = np.zeros(len(words), dtype=np.float32)
for idx, w in enumerate(words):
if w in sentence_words:
bag[idx] = 1
return bag

Comment on lines +1 to +3
import torch
import torch.nn as nn

Copy link

Choose a reason for hiding this comment

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

Remove unused import.

The torch import is unused and should be removed.

- import torch
  import torch.nn as nn
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import torch
import torch.nn as nn
import torch.nn as nn
Tools
Ruff

1-1: torch imported but unused

Remove unused import: torch

(F401)

Comment on lines +30 to +34
while True:
# sentence = "do you use credit cards?"
sentence = input("You: ")
if sentence == "quit":
break
Copy link

Choose a reason for hiding this comment

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

Handle case-insensitive 'quit' command.

Currently, the 'quit' command is case-sensitive. Consider making it case-insensitive for better user experience.

- if sentence == "quit":
+ if sentence.lower() == "quit":
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
while True:
# sentence = "do you use credit cards?"
sentence = input("You: ")
if sentence == "quit":
break
while True:
# sentence = "do you use credit cards?"
sentence = input("You: ")
if sentence.lower() == "quit":
break

Comment on lines +1 to +2
import random
import json
Copy link

Choose a reason for hiding this comment

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

Remove unused import: random.

The random module is imported but not used in the code.

- import random
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import random
import json
import json

@@ -0,0 +1,108 @@
import numpy as np
import random
Copy link

Choose a reason for hiding this comment

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

Remove unused import: random.

The random module is imported but not used in the code.

- import random
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import random
Tools
Ruff

2-2: random imported but unused

Remove unused import: random

(F401)

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.

Add ChatBot