Skip to main content

AI Output Token Optimizer - Reduce OpenAI API costs by up to 88%

Project description

🚀 WoosAI Library

Reduce your OpenAI API costs by up to 88%!

WoosAI Library is a powerful Python library that optimizes OpenAI API calls through intelligent input compression, output optimization, advanced caching, and real-time statistics tracking.

PyPI version Python 3.7+ License: MIT


✨ Features

🎯 Core Features

  • Input Optimization - Compress user inputs without losing meaning
  • Output Optimization - Get concise, relevant responses
  • Advanced Caching - LRU cache with pattern-based deletion
  • Usage Statistics - Track costs, tokens, and savings in real-time
  • Auto License - Free license auto-generated on first use

💰 Cost Savings

  • Up to 88% cost reduction on OpenAI API calls
  • Real-time tracking of cost savings
  • Cache system eliminates repeated API calls

📊 Statistics & Monitoring

  • Daily, monthly, and total usage statistics
  • Token usage tracking
  • Cost comparison (with/without WoosAI)
  • Cache hit rate monitoring

💾 Advanced Caching

  • LRU Eviction - Automatic removal of least-used entries
  • TTL Support - Auto-expire old cache entries
  • Pattern Deletion - Remove cache by regex pattern
  • Auto Cleanup - Periodic automatic maintenance

🚀 Quick Start

Installation

pip install woosailibrary

Basic Usage

import os
from woosailibrary import WoosAI

# Set your OpenAI API key
os.environ['OPENAI_API_KEY'] = 'your-openai-api-key'

# Initialize WoosAI (auto-generates free license on first use)
client = WoosAI()

# Make optimized API call
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Explain AI in simple terms"}]
)

print(response.choices[0].message.content)

With Caching

# Enable caching for repeated queries
client = WoosAI(
    cache=True,              # Enable caching
    cache_ttl=24,            # Cache expires after 24 hours
    max_cache_size=1000,     # Store up to 1000 entries
    auto_cleanup_interval=100 # Auto cleanup every 100 operations
)

# First call - hits OpenAI API
response1 = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "What is AI?"}]
)

# Second call - returns from cache (FREE!)
response2 = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "What is AI?"}]
)

📊 Statistics & Monitoring

View Statistics

# Display all statistics
client.display_stats()

# Get specific stats
today = client.get_today_stats()
monthly = client.get_monthly_stats()
total = client.get_total_stats()

print(f"Today's savings: {today['cost_saved']}")
print(f"Monthly savings: {monthly['cost_saved']}")
print(f"Total savings: {total['cost']['saved']}")

Example Output:

============================================================
📊 WoosAI Usage Statistics
============================================================

📅 Today (2025-10-23):
  Requests: 15
  Cost Saved: $2.50
  Tokens Saved: 3,500

📆 This Month (2025-10):
  Requests: 450
  Cost Saved: $75.00
  Projected Monthly: $225.00

🎯 Total (All Time):
  Requests: 1,200
  Cost Saved: $210.00
  Savings: 88.0%

============================================================

💾 Cache Management

View Cache Statistics

# Display cache statistics
client.display_cache_stats()

# Get cache info
cache_info = client.get_cache_info()
print(f"Cache size: {cache_info['size_usage']}")

Example Output:

============================================================
💾 Advanced Cache Statistics
============================================================

📊 Performance:
  Cache Hits: 450
  Cache Misses: 150
  Hit Rate: 75.0%
  LRU Evictions: 50

💰 Savings:
  Cost Saved (from cache): $22.50

📦 Storage:
  Cached Entries: 850/1000 (85.0%)
  Active: 800
  Expired: 50

============================================================

Cache Management

# Clear expired cache entries
client.clear_expired_cache()

# Clear cache by pattern (e.g., weather-related queries)
client.clear_cache_by_pattern("weather|날씨")

# Clear cache older than 7 days
client.clear_old_cache(days=7)

# Clear all cache
client.clear_cache()

🎯 Use Cases

1. FAQ Chatbot

client = WoosAI(cache=True, cache_ttl=168)  # 1 week cache

# Same questions = FREE responses!
for question in faq_questions:
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": question}]
    )

2. Customer Support Bot

client = WoosAI(cache=True, max_cache_size=5000)

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "How do I reset my password?"}]
)

📖 API Reference

WoosAI Client

client = WoosAI(
    api_key=None,              # OpenAI API key
    license_key=None,          # WoosAI license
    cache=False,               # Enable caching
    cache_ttl=24,              # Cache TTL in hours
    max_cache_size=1000,       # Maximum cache entries
    auto_cleanup_interval=100  # Auto cleanup frequency
)

Statistics Methods

client.get_today_stats()      # Get today's statistics
client.get_monthly_stats()    # Get monthly statistics
client.get_total_stats()      # Get total statistics
client.display_stats()        # Display statistics

Cache Methods

client.get_cache_info()              # Get cache info
client.display_cache_stats()         # Display cache stats
client.clear_cache()                 # Clear all cache
client.clear_cache_by_pattern(regex) # Clear by pattern
client.clear_expired_cache()         # Clear expired
client.clear_old_cache(days=7)       # Clear old entries

🔧 Configuration

Configuration Files

WoosAI stores data in:

  • Windows: C:\Users\<username>\.woosai\
  • Linux/Mac: ~/.woosai/

Files:

  • config.json - License information
  • stats.json - Usage statistics
  • cache/responses.json - Cached responses

🔗 Links


📄 License

MIT License


Made with ❤️ by WoosAI Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

woosailibrary-1.1.0.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

woosailibrary-1.1.0-py3-none-any.whl (42.9 kB view details)

Uploaded Python 3

File details

Details for the file woosailibrary-1.1.0.tar.gz.

File metadata

  • Download URL: woosailibrary-1.1.0.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for woosailibrary-1.1.0.tar.gz
Algorithm Hash digest
SHA256 336b6323b42bd4eb6bdee3ec6b685416d69ccb84f2c241a2832e357e05b02377
MD5 26c5b260b7ae6916b2a900a499ee5cb4
BLAKE2b-256 f6942ed75cb4f087abb52b89df7b9508f30defe08010e2ea2794ba0a0dbb9e07

See more details on using hashes here.

File details

Details for the file woosailibrary-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: woosailibrary-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 42.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for woosailibrary-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d3a991e6ebdeef5cd80859019d8f151049e9fd7fa3230992ff607e6a50e4c8b
MD5 553c6256b1ec5a50ba6894c190d2f8b8
BLAKE2b-256 7f7bde8a76cae3004b4a42c2838151a60ab45d03b7b9cf442441882aefaacadc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page