Skip to content

Clecotech/SafeLLM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SafeLLM API 🚀

This is a Flask-based API that processes user queries, ensuring they are non-toxic and appropriate. It uses pre-trained NLP models for query classification, toxicity detection, and query rewriting.

Features ✨

  • 🛡️ Detects and blocks toxic or inappropriate content.
  • 🧠 Classifies query intents and restricts certain types of queries.
  • ✍️ Rewrites queries for better clarity.
  • 🤖 Generates responses to rewritten queries.

Tech Stack 🛠️

  • Flask: Backend framework for the API.
  • Transformers Library: For text classification and query rewriting.
  • Detoxify: For toxicity detection in text.

Endpoints 🔗

/query (Method: POST)

Processes user queries by:

  1. Checking for toxicity.
  2. Classifying intent.
  3. Rewriting queries for clarity.
  4. Generating a response.

Request Body (JSON): 📤

{
  "query": "Your input query here"
}

Response: 📥

🚫 If query contains toxicity:

{
  "query": "Query contains inappropriate content."
}

Status Code: 403

Response:

☣️ If query is restricted:

{
  "query": "Restricted query detected."
}

Status Code: 403

Response:

✅ If query is valid:

{
  "query": "LLM Response to: Your clarified query"
}

Status Code: 200

Installation 🛠️

Prerequisites

  • Python 3.8 or later
  • pip package manager

Setup ⚡

  1. Clone the repository:
   git clone git@github.com:Clecotech/SafeLLM.git
   cd SafeLLM
  1. Install dependencies:
  pip install -r requirements.txt
  1. Run the application:
    python app.py
    
  2. The app will run on http://localhost:5001 🌐

Environment Configuration 🌱

You can set up a virtual environment for this project:

python -m venv venv  
source venv/bin/activate  # On Windows: venv\Scripts\activate  
pip install -r requirements.txt  

Example Request 📡

cURL:

curl -X POST http://localhost:5001/query \
-H "Content-Type: application/json" \
-d '{"query": "Explain the process of natural language processing."}'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors