Skip to main content

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

  1. 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"
  2. 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

django-open-ai-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

django_open_ai-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file django-open-ai-0.1.0.tar.gz.

File metadata

  • Download URL: django-open-ai-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for django-open-ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4abdb6fff6207a53c954b0cdfdfd828e04babbcb1eeb65aaac2b93b28a6e734a
MD5 04f9b5e72243550f19b45aca65187736
BLAKE2b-256 d08832bac9fbec190d2adda16afe0c888742567128d18dcf4101039e78536446

See more details on using hashes here.

File details

Details for the file django_open_ai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_open_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for django_open_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a896bbf24386bf045a50a9e1d6471fb13758d672f8dd477699875ff35a8f6df
MD5 551633bcc8788347d210f137acc9920b
BLAKE2b-256 a817c0eaf8ad14c941914acdad4448e86953663b16daf1283e369c72b786b898

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