AdvoCat is an advanced, AI-powered legal assistant built with FastAPI. The application leverages OpenAI's GPT-3 model to provide users with instant legal advice and information. It combines natural language processing (NLP) techniques, powered by spaCy and NLTK, to classify and respond to various legal queries, such as contract laws, general legal terms, and case procedures.
Additionally, the system logs all user queries and responses to a database for analysis and continuous improvement. The app also provides suggested actions and related links to help users better understand their legal concerns.
- AI-Powered Legal Assistance: Instant responses generated by OpenAI GPT-3.
- Predefined Legal Chatbot: Custom NLP patterns to handle common legal queries.
- Query Classification: Categorizes queries and provides suggested actions and related links.
- Query Logging: Logs user queries and AI-generated responses in a database (SQLite).
- Search History: A
/queries
endpoint to retrieve past user queries and responses. - FastAPI Backend: High-performance API built using FastAPI.
- FastAPI: A modern, fast web framework for building APIs with Python.
- OpenAI GPT-3: AI model for generating legal advice and answering legal questions.
- spaCy: Advanced NLP library used for classifying and extracting entities from legal queries.
- NLTK: Provides a simple chatbot structure for predefined legal patterns.
- SQLAlchemy: ORM used for query logging and database interactions.
- SQLite: Lightweight relational database for storing user queries and responses.
- Uvicorn: ASGI server to run the FastAPI application.
- Clone the repository:
git clone https://github.com/shamuraanim7/AdvoCat.git
cd AdvoCat
- Install required dependencies:
pip install -r requirements.txt
- Install spaCy and download the English model:
python -m spacy download en_core_web_sm
- Set OpenAI API Key:
Replace
'your_openai_api_key_here'
in the code with your OpenAI API key.
To run the server locally, use the following command:
uvicorn main:app --reload
This will start the FastAPI application at http://localhost:8000
.
The main endpoint for asking legal questions.
Request Body:
{
"query": "What is contract law?"
}
Response:
{
"response": "Contract law is the body of law that governs legally binding agreements between parties.",
"suggested_actions": ["Review the contract terms thoroughly."],
"related_links": ["https://www.law.com/contract-terms/"]
}
Fetch all previously logged queries and responses.
Parameters:
skip
: Number of queries to skip (default is 0).limit
: Number of queries to return (default is 10).
Example:
GET /queries?skip=0&limit=10
Response:
[
{
"id": 1,
"query": "What is contract law?",
"response": "Contract law is the body of law that governs legally binding agreements between parties."
}
]
The application uses SQLite to store logs of user queries and responses. This helps track previous interactions, analyze trends, and improve the AI's responses.
If you'd like to contribute to this project, please fork the repository and submit a pull request with your changes.
- Fork the repository
- Create your feature branch (
git checkout -b feature-branch
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to your branch (
git push origin feature-branch
) - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI GPT-3 for its powerful language model.
- spaCy and NLTK for simplifying natural language processing tasks.
- FastAPI for providing a fast and efficient framework for building APIs.