Skip to content

A chatbot application to search for vulnerability using the NIST database

License

Notifications You must be signed in to change notification settings

shivam096/Vulnerability-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NVD Vulnerability Chatbot

This project is designed to create a chatbot that interacts with the National Vulnerability Database (NVD) to provide information about Common Vulnerabilities and Exposures (CVEs). The chatbot uses OpenAI's GPT-4 model to understand user queries and extract relevant filters to query the NVD API.

Project Structure

Files and Directories

  • .env: Contains environment variables, including API keys for OpenAI and the NVD API.
  • chatbot.py: Defines the main chatbot functionality, initializes the language model, and handles user interaction.
  • constants.py: Defines constant mappings and a prompt template used for extracting filters from user queries.
  • req.txt: Lists the dependencies required for the project.
  • tool.py: Defines the tool for querying the NVD database and extracting filters from user queries.
  • util/utilities.py: Contains utility functions for constructing API queries and filtering API responses.

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-directory>
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install the dependencies:

    pip install -r req.txt
  4. Set up environment variables:

    • Create a .env file in the root directory of the project.
    • Add your OpenAI API key and NVD API key to the .env file:
      OPENAI_API_KEY="your_openai_api_key"
      API_URL="https://services.nvd.nist.gov/rest/json/cves/2.0"
      API_KEY="your_nvd_api_key"
      

Usage

Run the chatbot by executing the following command:

python chatbot.py

Key Components

chatbot.py

  • Initializes the language model using OpenAI's GPT-4.
  • Creates an agent with a custom tool for querying the NVD database.
  • Defines the chatbot() function, which handles user interaction and processes queries using the agent.

tool.py

  • Imports necessary libraries and loads environment variables.
  • Defines the language model and prompt template for query extraction.
  • Implements the extract_filters(user_query: str) -> Dict function to extract filters from user queries using the language model.
  • Implements the query_online_database(query: str) -> Dict function to query the NVD database with extracted filters and return filtered API responses.

utilities.py

  • construct_api_query(filters: Dict) -> str: Builds an API query string from extracted filters.
  • filter_response(data: Dict) -> List[Dict]: Filters the API response to include only relevant fields.

constants.py

  • PARAMETER_MAPPING: A dictionary mapping parameter names to their descriptions.

  • PROMPT_TEMPLATE: A template for generating prompts to extract filters from user queries.

License

This project is licensed under the MIT License.

About

A chatbot application to search for vulnerability using the NIST database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages