Skip to content

SatyamDevv/langchain-api-hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Langchain API Hub

A comprehensive Django-based AI services platform with user authentication, API key management, and 8 powerful AI-powered text processing APIs.

๐ŸŒŸ Features

Authentication System

  • User Registration & Login: Secure signup and login system
  • API Key Management: Automatic API key generation for each user
  • Dashboard: User dashboard with API key management and usage statistics
  • Middleware Authentication: Secure API endpoints with API key validation

AI Services (8 APIs)

  1. ๐Ÿ“ Text Summarization - Extract key points from long texts
  2. ๐Ÿ˜Š Sentiment Analysis - Analyze emotional tone of text
  3. ๐Ÿ”‘ Keyword Extraction - Extract important keywords and phrases
  4. ๐Ÿท๏ธ Text Classification - Categorize text into different topics
  5. ๐ŸŒ Language Detection - Identify the language of input text
  6. ๐Ÿ”„ Text Translation - Translate text between multiple languages
  7. โ“ Question Answering - Get answers to questions with optional context
  8. โœจ Content Generation - Generate various types of content

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8+
  • Django 5.2+
  • Google Gemini API key

Installation

  1. Clone the repository

    git clone <repository-url>
    cd service_hub
  2. Install dependencies

    pip install django djangorestframework python-dotenv langchain-google-genai
  3. Set up environment variables Create a .env file in the project root:

    GOOGLE_API_KEY=your_gemini_api_key_here
  4. Run migrations

    python manage.py migrate
  5. Create superuser (optional)

    python manage.py createsuperuser
  6. Start the server

    python manage.py runserver
  7. Access the application Open http://127.0.0.1:8000 in your browser

๐Ÿ” Authentication Flow

User Registration

  1. Visit /signup/ to create a new account
  2. Fill in username, email, and password
  3. Upon successful registration, an API key is automatically generated
  4. User is redirected to the home page

User Login

  1. Visit /login/ to sign in
  2. Enter username and password
  3. Access dashboard at /dashboard/ to view API key and statistics

API Key Usage

  • Header Method: Include X-API-Key: your_api_key in request headers
  • Body Method: Include "api_key": "your_api_key" in request body

๐Ÿ“ก API Endpoints

Authentication Endpoints

  • GET / - Home page with API testing interface
  • GET /login/ - Login page
  • POST /login/ - Process login
  • GET /signup/ - Registration page
  • POST /signup/ - Process registration
  • GET /dashboard/ - User dashboard
  • POST /logout/ - Logout user
  • POST /regenerate-api-key/ - Generate new API key

AI Service Endpoints

All endpoints require API key authentication:

Endpoint Method Description
/summarize/ POST Text summarization
/sentiment/ POST Sentiment analysis
/keywords/ POST Keyword extraction
/classify/ POST Text classification
/detect-language/ POST Language detection
/translate/ POST Text translation
/answer/ POST Question answering
/generate/ POST Content generation

๐Ÿ”ง API Usage Examples

Text Summarization

fetch("/summarize/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "your_api_key_here",
  },
  body: JSON.stringify({
    text: "Your long text here...",
    method: "stuff", // 'stuff', 'map_reduce', or 'refine'
  }),
});

Sentiment Analysis

fetch("/sentiment/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "your_api_key_here",
  },
  body: JSON.stringify({
    text: "I love this product!",
  }),
});

Text Translation

fetch("/translate/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "your_api_key_here",
  },
  body: JSON.stringify({
    text: "Hello, how are you?",
    target_language: "Spanish",
  }),
});

Content Generation

fetch("/generate/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "your_api_key_here",
  },
  body: JSON.stringify({
    prompt_text: "Write a professional email",
    content_type: "email",
    max_length: 500,
  }),
});

๐Ÿ—๏ธ Project Structure

service_hub/
โ”œโ”€โ”€ ai_services/                 # Main Django app
โ”‚   โ”œโ”€โ”€ logic/                  # AI service logic
โ”‚   โ”‚   โ”œโ”€โ”€ summarizer.py       # Text summarization
โ”‚   โ”‚   โ”œโ”€โ”€ sentiment_analyzer.py # Sentiment analysis
โ”‚   โ”‚   โ”œโ”€โ”€ keyword_extractor.py # Keyword extraction
โ”‚   โ”‚   โ”œโ”€โ”€ text_classifier.py  # Text classification
โ”‚   โ”‚   โ”œโ”€โ”€ language_detector.py # Language detection
โ”‚   โ”‚   โ”œโ”€โ”€ text_translator.py  # Text translation
โ”‚   โ”‚   โ”œโ”€โ”€ question_answerer.py # Question answering
โ”‚   โ”‚   โ”œโ”€โ”€ content_generator.py # Content generation
โ”‚   โ”‚   โ””โ”€โ”€ gemini_setup.py     # Gemini API setup
โ”‚   โ”œโ”€โ”€ templates/              # HTML templates
โ”‚   โ”‚   โ””โ”€โ”€ ai_services/
โ”‚   โ”‚       โ”œโ”€โ”€ home.html       # Main interface
โ”‚   โ”‚       โ”œโ”€โ”€ login.html      # Login page
โ”‚   โ”‚       โ”œโ”€โ”€ signup.html     # Registration page
โ”‚   โ”‚       โ””โ”€โ”€ dashboard.html  # User dashboard
โ”‚   โ”œโ”€โ”€ models.py              # Database models
โ”‚   โ”œโ”€โ”€ views.py               # API views
โ”‚   โ”œโ”€โ”€ auth_views.py          # Authentication views
โ”‚   โ”œโ”€โ”€ serializers.py         # API serializers
โ”‚   โ”œโ”€โ”€ middleware.py          # API key middleware
โ”‚   โ””โ”€โ”€ urls.py                # URL patterns
โ”œโ”€โ”€ service_hub/               # Django project settings
โ”‚   โ”œโ”€โ”€ settings.py           # Project settings
โ”‚   โ””โ”€โ”€ urls.py               # Main URL configuration
โ””โ”€โ”€ manage.py                 # Django management script

๐ŸŽจ Frontend Features

Responsive Design

  • Modern gradient-based UI design
  • Mobile-responsive layout
  • Interactive service cards
  • Real-time API testing interface

User Experience

  • Sample data pre-loaded for testing
  • Loading spinners and progress indicators
  • Success/error message handling
  • Copy-to-clipboard functionality for API keys

๐Ÿ”’ Security Features

  • CSRF Protection: All forms protected against CSRF attacks
  • API Key Authentication: Secure API access with unique keys
  • Password Validation: Strong password requirements
  • Session Management: Secure user session handling
  • Middleware Protection: All API endpoints protected by authentication middleware

๐Ÿ“Š Admin Interface

Access Django admin at /admin/ to:

  • View and manage user accounts
  • Monitor API key usage
  • View API usage statistics
  • Manage user permissions

๐Ÿงช Testing

Run the included test script:

python test_auth.py

This tests:

  • User registration
  • User login
  • API key authentication
  • API endpoint functionality

๐Ÿš€ Deployment

Vercel Deployment

This project is configured for easy deployment on Vercel:

  1. Install Vercel CLI

    npm install -g vercel
  2. Set Environment Variables Configure these in your Vercel dashboard:

    SECRET_KEY=your-secret-django-key
    DEBUG=False
    SUPABASE_DB_NAME=your_db_name
    SUPABASE_DB_USER=your_db_user
    SUPABASE_DB_PASSWORD=your_db_password
    SUPABASE_DB_HOST=your_db_host
    SUPABASE_DB_PORT=5432
    GOOGLE_API_KEY=your-google-api-key
    
  3. Deploy

    vercel --prod
  4. Test Production Settings Locally

    python test_production.py

For detailed deployment instructions, see DEPLOYMENT.md.

๐Ÿš€ Deployment Considerations

Production Settings

  • Set DEBUG = False
  • Configure secure database (PostgreSQL recommended)
  • Set up proper static file serving
  • Configure HTTPS
  • Set secure session cookies
  • Use environment variables for all secrets

Environment Variables

SECRET_KEY=your_django_secret_key
DEBUG=False
ALLOWED_HOSTS=your-domain.com
DATABASE_URL=your_database_url
GOOGLE_API_KEY=your_gemini_api_key

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add your changes
  4. Write tests for new functionality
  5. Submit a pull request

๐Ÿ“ License

This project is licensed under the MIT License.

๐Ÿ†˜ Support

For issues and questions:

  1. Check the documentation
  2. Run the test script to verify setup
  3. Check Django logs for errors
  4. Ensure all environment variables are set

๐Ÿ”ฎ Future Enhancements

  • Rate limiting for API calls
  • Usage analytics and billing
  • Additional AI models integration
  • Bulk processing capabilities
  • API versioning
  • Webhook support
  • Team collaboration features

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published