Use the power of OpenAI on your Django database
Project description
This app enables you to use OpenAI requests over the Django database.
Installation
You can install the package using pip:
#pip install django-open-ai
Quick start
Please include your OpenAI API key in the settings.py file as follows. Please also include your target database (generally “default” but could be different if you have more databases)::
OPENAI_API_TYPE = "standard" OPENAI_API_KEY = "<YOUR_API_KEY>" OPENAI_TARGET_DATABASE = "default"
Also make sure that the package is in the installed apps list in the settings.py file::
INSTALLED_APPS = [ 'django_open_ai', ... ]
Now, make sure that your database is not sqlite3, as this is not supported. Similarly, the each database in the DATABASES list in the settings.py file must include the following keys: HOST, NAME, USER, PASSWORD, ENGINE, PORT. The current version only allows for when the host is the server.
Simple example
Suppose that the Django app has an app called polls.py (as per the example https://docs.djangoproject.com/en/4.2/intro/tutorial01/). Then in the polls/views.py simply make:
from django_open_ai import views class make_view(views.DjangoOpenAI): template = "YOUR OWN TEMPLATE.html"
Please make sure that your template includes a form as follows:
<form method="post"> {% csrf_token %} {{ form.as_p }} <input type="submit" value="Submit"> </form>
Now set up your urls.py file inside polls:
from django.urls import path from . import views urlpatterns = [ path('', views.make_view.as_view()), ... ]
and in your site urls.py:
from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path("ai/", include("polls.urls")), ... ]
That’s it! Run your server:
python manage.py runserver
The page http://127.0.0.1:8000/ai/ shows the form. Ask away about your data! For example “What is the most popular choice for question 1?”. This will return a JsonResponse with the result.
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
Built Distribution
Hashes for django_open_ai-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a896bbf24386bf045a50a9e1d6471fb13758d672f8dd477699875ff35a8f6df |
|
MD5 | 551633bcc8788347d210f137acc9920b |
|
BLAKE2b-256 | a817c0eaf8ad14c941914acdad4448e86953663b16daf1283e369c72b786b898 |