Skip to content

The Profanity Detection API is a web service designed to detect and flag profane language in text messages. Built using the Hono framework and deployed on a serverless environment such as Cloudflare Workers, this API leverages vector search technologies to accurately identify offensive language.

Notifications You must be signed in to change notification settings

sarvagyakrcs/apshabd.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Profanity Detection API

Overview

The Profanity Detection API is designed to detect and flag profane language in text messages. It processes the input message, checks for profanity, and returns the result along with the detected offensive text if any.

Endpoint

Base URL

bash
/gaali

HTTP Method

POST

Request

Headers

  • Content-Type: application/json

Body

The request body must be a JSON object with the following structure:

json
{ "message": "Your message here" }
  • message (string): The text message to be analyzed. Must be no longer than 500 characters.

Example Request

json
{ "message": "tu ##### hai" }

Response

The response will be a JSON object with the following structure:

Profanity Detected

json
{ "isProfanity": true, "score": 0.95, "flaggedFor": "#####" }
  • isProfanity (boolean): Indicates if the message contains profanity.
  • score (number): The similarity score of the detected profane content.
  • flaggedFor (string): The text that was flagged as profane.

No Profanity Detected

json
{ "isProfanity": false, "score": 0.45 }
  • isProfanity (boolean): Indicates if the message contains profanity.
  • score (number): The highest similarity score observed.

Error Responses

  • Content-Type not JSON:

    json
    { "error": "JSON Body Expected." }

    Status Code: 406

  • Message Argument Missing:

    json
    { "error": "Message Argument is Required." }

    Status Code: 400

  • Message Too Long:

    json
    { "error": "Message can only be at most 500 characters." }

    Status Code: 413

  • Internal Server Error:

    json
    { "error": "Something Went Wrong" }

    Status Code: 500

Usage Example

cURL

sh
curl -X POST https://abshabd.apshabd.workers.dev/gaali \ -H "Content-Type: application/json" \ -d '{"message": "tu ##### hai"}'

JavaScript (Fetch API)

javascript
fetch('https://abshabd.apshabd.workers.dev/gaali', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: "tu ##### hai" }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error));

Python (Requests)

python
import requests

url = 'https://abshabd.apshabd.workers.dev/gaali' headers = { 'Content-Type': 'application/json', } data = { 'message': 'tu ##### hai' }

response = requests.post(url, headers=headers, json=data) print(response.json())

Environment Variables

Make sure to set the following environment variables for the API to function correctly:

  • VECTOR_URL: URL of the vector database.
  • VECTOR_TOKEN: Token for authenticating requests to the vector database.

Setup and Deployment

  1. Clone the repository.
  2. Install dependencies using npm install.
  3. Deploy to your serverless environment (e.g., Cloudflare Workers).
  4. Set the required environment variables (VECTOR_URL and VECTOR_TOKEN).
  5. Access the API at the /gaali endpoint.

About

The Profanity Detection API is a web service designed to detect and flag profane language in text messages. Built using the Hono framework and deployed on a serverless environment such as Cloudflare Workers, this API leverages vector search technologies to accurately identify offensive language.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published