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.
.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.
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r req.txt
-
Set up environment variables:
Run the chatbot by executing the following command:
python 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.
- 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.
- 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.
-
PARAMETER_MAPPING: A dictionary mapping parameter names to their descriptions.
-
PROMPT_TEMPLATE: A template for generating prompts to extract filters from user queries.
This project is licensed under the MIT License.