Make your Django models & fields smarter with built-in support for OpenAI & Stability AI APIs
- Install
django-smart-models
pip install django-smart-models- Add "smart_models" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
...
'smart_models',
]- 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- Get OpenAI and Stability AI API keys
- Add API keys to environment variables
OPENAI_API_KEYandSTABILITYAI_API_KEY - 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",
},
}Refer demo for sample usage example
SmartTextFieldSupports auto spell correction, translation, generating summary, generating emojis along with title generation tasks.- Base class:
models.TextField - Parameters:
data_fields:list[str]spell_correct:booltranslate:booltarget_lan:strgenerate_title:boolmax_title_length:intsummarize:boolemojify:boolapi_provider:models.APIProviders
- Base class:
SmartImageFieldSupports thumbnail generation for a given article/text- Base class:
models.ImageField - Parameters:
data_fields:list[str]thumbnail:boolimage_height:intimage_width:intimage_extension:strapi_provider:models.APIProviders
- Base class:
AudioToTextFieldSupports tasks of transcribing an audio or generating translation of an audio (text)- Base class:
models.TextField - Parameters:
data_fields:list[str]transcribe:booltranslate:boolapi_provider:models.APIProviders
- Base class:
APIProviders- Base class:
models.TextChoices - Choices:
OPENAISTABILITYAIGCP# API support yet to be addedAZURE# API support yet to be addedAWS# API support yet to be added
- Base class:
TextAIModelImageAIModelAudioAIModel
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!