Skip to main content

Django smart models & fields with AI built-in

Project description

Django smart models

Make your Django models & fields smarter with built-in support for OpenAI & Stability AI APIs

Quick start

  1. Install django-smart-models
pip install django-smart-models
  1. Add "smart_models" to your INSTALLED_APPS setting like this:
   INSTALLED_APPS = [
   ...
   'smart_models',
   ]
  1. Run migrations to create smart_models models
python manage.py makemigrations smart_models
python manage.py migrate
# Initialize API configurations
python manage.py init_smart_models
  1. Get OpenAI and Stability AI API keys
  2. Add API keys to environment variables OPENAI_API_KEY and STABILITYAI_API_KEY
  3. Copy & paste below code snippet to settings.py
AI_API_SETTINGS = {
    "openai": {
        "key": os.getenv("OPENAI_API_KEY"),
    },
    "stability_ai": {
        "key": os.getenv("STABILITYAI_API_KEY"),
        "host": "grpc.stability.ai:443",
    },
}

Usage

Refer demo for sample usage example

Fields

  • SmartTextField Supports auto spell correction, translation, generating summary, generating emojis along with title generation tasks.
    • Base class: models.TextField
    • Parameters:
      • data_fields: list[str]
      • spell_correct: bool
      • translate: bool
      • target_lan: str
      • generate_title: bool
      • max_title_length: int
      • summarize: bool
      • emojify: bool
      • api_provider: models.APIProviders
  • SmartImageField Supports thumbnail generation for a given article/text
    • Base class: models.ImageField
    • Parameters:
      • data_fields: list[str]
      • thumbnail: bool
      • image_height: int
      • image_width: int
      • image_extension: str
      • api_provider: models.APIProviders
  • AudioToTextField Supports tasks of transcribing an audio or generating translation of an audio (text)
    • Base class: models.TextField
    • Parameters:
      • data_fields: list[str]
      • transcribe: bool
      • translate: bool
      • api_provider: models.APIProviders
  • APIProviders
    • Base class: models.TextChoices
    • Choices:
      • OPENAI
      • STABILITYAI
      • GCP # API support yet to be added
      • AZURE # API support yet to be added
      • AWS # API support yet to be added

Models

  • TextAIModel
  • ImageAIModel
  • AudioAIModel

TODO:

There is room for lots of improvements and will be taken up in future.

  • [] async and celery based task execution
  • [] Exception handling for OpenAI max_tokens
  • [] Integrate all OpenAI APIs
  • [] Stability AI API integration
  • [] Hugging Face AI API integration
  • [] GCP, Azure, AWS AI API integration

As this is more of a hobby project, updates would be pushed at very slow speed. But pull requests are welcome!

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

django-smart-models-0.2.tar.gz (10.7 kB view details)

Uploaded Source

File details

Details for the file django-smart-models-0.2.tar.gz.

File metadata

  • Download URL: django-smart-models-0.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for django-smart-models-0.2.tar.gz
Algorithm Hash digest
SHA256 3a9436f96518833def9470e722f7115e24e41965a0e543c830f5983755024fef
MD5 08a510234bc4404698dd8ce6e9e874a1
BLAKE2b-256 a179558e94b510838bcce17ed771e608569064227aba1d2f7d1e3d31889cd4fc

See more details on using hashes here.

Provenance

Supported by

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