django-gpt


Namedjango-gpt JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/markolofsen/django-gpt
SummaryIntegrate powerful text generators like GPT-3 and GPT-4 into your Django application for automated text generation based on instructions.
upload_time2023-09-10 11:55:13
maintainer
docs_urlNone
authorMark
requires_python>=3.6
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
Django GPT
==========

Django GPT is a library for integrating powerful text generators like GPT-3 and GPT-4 into your Django application. It allows you to automatically generate text based on instructions, which can be useful for creating property descriptions or other textual data.

Installation
------------

You can install Django GPT using pip:

.. code-block:: bash

   pip install django-ckeditor-5
   pip install django-gpt

Usage Example
-------------

.. code-block:: python

   from django.db import models
   from django_gpt.models import DjangoGptField

   class PropertyModel(models.Model):
       id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
       title = models.CharField(max_length=255)

       # GPT
       gpt_instruction = models.TextField(
           default='', blank=True, help_text='GPT instruction')

       description_html = DjangoGptField(
           type="html",
           field_instruction_name="gpt_instruction",
           gpt_role="You're a real estate agent and you're writing a description for a property.",
           gpt_content_length=300,  # Default maximum generated text length.
           allowed_tags=['p', 'br', 'b', 'strong', 'i', 'em', 'u',
                         'ul', 'ol', 'li', 'a', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
           default="",
           blank=True,
       )

       description_text = DjangoGptField(
           type="textarea",
           field_instruction_name="gpt_instruction",
           gpt_role="You're a real estate agent and you're writing a description for a property.",
           gpt_content_length=300,  # Default maximum generated text length.
           default="",
           blank=True,
       )

How It Works
------------

The Django GPT library allows you to create Django model fields that automatically generate text based on instructions. In the example above, we have two fields: ``description_html`` and ``description_text``\ , which use GPT to generate property description text.


#. 
   ``gpt_instruction``\ : This field is intended for instructions that you provide to GPT to specify what to generate.

#. 
   ``description_html`` and ``description_text``\ : These fields will be automatically filled with generated text based on the instructions provided in the ``gpt_instruction`` field.

#. 
   ``field_instruction_name``\ : This field determines where to take the instruction for text generation. If you change the ``field_instruction_name`` value, automatic regeneration of text will occur for fields that reference this instruction. GPT also takes into account the previous value that was in fields of type ``DjangoGptField``. If you clear the value and change the instruction, text generation will be based solely on the new instruction. If there are no changes in the instruction, text regeneration will not occur. This allows you to preserve previous versions of generated text if needed for comparison.

#. 
   ``gpt_content_length``\ : This parameter defines the maximum length of generated text. In this example, the maximum length of the text is set to 300 characters. You can customize this parameter according to your needs.

Configuration
-------------

To configure the Django GPT library, you can use the following parameters in your Django application's ``settings.py`` file:

.. code-block::

   # Version of GPT to use (3 or 4).
   DJANGO_GPT_VERSION = 3

   # ISO language code (e.g., "en"). If not specified, it uses the value from LANGUAGE_CODE, and if that's not set, it defaults to "en".
   DJANGO_GPT_LANGUAGE = "en"

   # API key for GPT.
   CHATGPT_API_KEY = "your-api-key-here"
   # Please make sure to replace `"your-api-key-here"` with your actual GPT API key in the settings before using the library.

To use the rich text editor for HTML fields like ``description_html``\ , consider integrating a package like `django-ckeditor-5 <https://pypi.org/project/django-ckeditor-5/>`_. Here's an example of how to configure the editor in your Django settings:

.. code-block:: python

   INSTALLED_APPS = [
       ...
       "django_ckeditor_5",
       ...
   ]

   CKEDITOR_5_CONFIGS = {
       'default': {
           'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',
                       'code', 'subscript', 'superscript', 'highlight', '|', 'codeBlock', 'sourceEditing', 'insertImage',
                       'bulletedList', 'numberedList', 'todoList', '|', 'blockQuote', 'imageUpload', '|',
                       'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat',
                       'insertTable',],
           'image': {
               'toolbar': ['imageTextAlternative', '|', 'imageStyle:alignLeft',
                           'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side', '|'],
               'styles': [
                   'full',
                   'side',
                   'alignLeft',
                   'alignRight',
                   'alignCenter',
               ]

           },
           'heading': {
               'options': [
                   {'model': 'paragraph', 'title': 'Paragraph',
                       'class': 'ck-heading_paragraph'},
                   {'model': 'heading1', 'view': 'h1', 'title': 'Heading 1',
                       'class': 'ck-heading_heading1'},
                   {'model': 'heading2', 'view': 'h2', 'title': 'Heading 2',
                       'class': 'ck-heading_heading2'},
                   {'model': 'heading3', 'view': 'h3',
                       'title': 'Heading 3', 'class': 'ck-heading_heading3'},
                    ...
               ]
           }
       },
   }

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/markolofsen/django-gpt",
    "name": "django-gpt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Mark",
    "author_email": "markolofsen@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/22/b7/6c69d7893444c904b3377bf2e16b292e36c47c0e1c70c680ba4e3047be46/django-gpt-1.0.1.tar.gz",
    "platform": null,
    "description": "\nDjango GPT\n==========\n\nDjango GPT is a library for integrating powerful text generators like GPT-3 and GPT-4 into your Django application. It allows you to automatically generate text based on instructions, which can be useful for creating property descriptions or other textual data.\n\nInstallation\n------------\n\nYou can install Django GPT using pip:\n\n.. code-block:: bash\n\n   pip install django-ckeditor-5\n   pip install django-gpt\n\nUsage Example\n-------------\n\n.. code-block:: python\n\n   from django.db import models\n   from django_gpt.models import DjangoGptField\n\n   class PropertyModel(models.Model):\n       id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\n       title = models.CharField(max_length=255)\n\n       # GPT\n       gpt_instruction = models.TextField(\n           default='', blank=True, help_text='GPT instruction')\n\n       description_html = DjangoGptField(\n           type=\"html\",\n           field_instruction_name=\"gpt_instruction\",\n           gpt_role=\"You're a real estate agent and you're writing a description for a property.\",\n           gpt_content_length=300,  # Default maximum generated text length.\n           allowed_tags=['p', 'br', 'b', 'strong', 'i', 'em', 'u',\n                         'ul', 'ol', 'li', 'a', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],\n           default=\"\",\n           blank=True,\n       )\n\n       description_text = DjangoGptField(\n           type=\"textarea\",\n           field_instruction_name=\"gpt_instruction\",\n           gpt_role=\"You're a real estate agent and you're writing a description for a property.\",\n           gpt_content_length=300,  # Default maximum generated text length.\n           default=\"\",\n           blank=True,\n       )\n\nHow It Works\n------------\n\nThe Django GPT library allows you to create Django model fields that automatically generate text based on instructions. In the example above, we have two fields: ``description_html`` and ``description_text``\\ , which use GPT to generate property description text.\n\n\n#. \n   ``gpt_instruction``\\ : This field is intended for instructions that you provide to GPT to specify what to generate.\n\n#. \n   ``description_html`` and ``description_text``\\ : These fields will be automatically filled with generated text based on the instructions provided in the ``gpt_instruction`` field.\n\n#. \n   ``field_instruction_name``\\ : This field determines where to take the instruction for text generation. If you change the ``field_instruction_name`` value, automatic regeneration of text will occur for fields that reference this instruction. GPT also takes into account the previous value that was in fields of type ``DjangoGptField``. If you clear the value and change the instruction, text generation will be based solely on the new instruction. If there are no changes in the instruction, text regeneration will not occur. This allows you to preserve previous versions of generated text if needed for comparison.\n\n#. \n   ``gpt_content_length``\\ : This parameter defines the maximum length of generated text. In this example, the maximum length of the text is set to 300 characters. You can customize this parameter according to your needs.\n\nConfiguration\n-------------\n\nTo configure the Django GPT library, you can use the following parameters in your Django application's ``settings.py`` file:\n\n.. code-block::\n\n   # Version of GPT to use (3 or 4).\n   DJANGO_GPT_VERSION = 3\n\n   # ISO language code (e.g., \"en\"). If not specified, it uses the value from LANGUAGE_CODE, and if that's not set, it defaults to \"en\".\n   DJANGO_GPT_LANGUAGE = \"en\"\n\n   # API key for GPT.\n   CHATGPT_API_KEY = \"your-api-key-here\"\n   # Please make sure to replace `\"your-api-key-here\"` with your actual GPT API key in the settings before using the library.\n\nTo use the rich text editor for HTML fields like ``description_html``\\ , consider integrating a package like `django-ckeditor-5 <https://pypi.org/project/django-ckeditor-5/>`_. Here's an example of how to configure the editor in your Django settings:\n\n.. code-block:: python\n\n   INSTALLED_APPS = [\n       ...\n       \"django_ckeditor_5\",\n       ...\n   ]\n\n   CKEDITOR_5_CONFIGS = {\n       'default': {\n           'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',\n                       'code', 'subscript', 'superscript', 'highlight', '|', 'codeBlock', 'sourceEditing', 'insertImage',\n                       'bulletedList', 'numberedList', 'todoList', '|', 'blockQuote', 'imageUpload', '|',\n                       'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat',\n                       'insertTable',],\n           'image': {\n               'toolbar': ['imageTextAlternative', '|', 'imageStyle:alignLeft',\n                           'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side', '|'],\n               'styles': [\n                   'full',\n                   'side',\n                   'alignLeft',\n                   'alignRight',\n                   'alignCenter',\n               ]\n\n           },\n           'heading': {\n               'options': [\n                   {'model': 'paragraph', 'title': 'Paragraph',\n                       'class': 'ck-heading_paragraph'},\n                   {'model': 'heading1', 'view': 'h1', 'title': 'Heading 1',\n                       'class': 'ck-heading_heading1'},\n                   {'model': 'heading2', 'view': 'h2', 'title': 'Heading 2',\n                       'class': 'ck-heading_heading2'},\n                   {'model': 'heading3', 'view': 'h3',\n                       'title': 'Heading 3', 'class': 'ck-heading_heading3'},\n                    ...\n               ]\n           }\n       },\n   }\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Integrate powerful text generators like GPT-3 and GPT-4 into your Django application for automated text generation based on instructions.",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/markolofsen/django-gpt"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "873f916b979cb27775e37ebc4ff77c77e16e93236e79b74b4129f780e93f5058",
                "md5": "b53e811feeb532b46d8aa6820349b0d1",
                "sha256": "190775fb0651109b0fe400ba3996a61b0dccff571b615438815a2afde8a83d6b"
            },
            "downloads": -1,
            "filename": "django_gpt-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b53e811feeb532b46d8aa6820349b0d1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6506,
            "upload_time": "2023-09-10T11:55:11",
            "upload_time_iso_8601": "2023-09-10T11:55:11.570215Z",
            "url": "https://files.pythonhosted.org/packages/87/3f/916b979cb27775e37ebc4ff77c77e16e93236e79b74b4129f780e93f5058/django_gpt-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22b76c69d7893444c904b3377bf2e16b292e36c47c0e1c70c680ba4e3047be46",
                "md5": "8707f534b74f2c0db73c3005b88e590a",
                "sha256": "77379c77c79cf80d638640578eda0a89dd16a8da42a122d7647eb7f64ad8f32d"
            },
            "downloads": -1,
            "filename": "django-gpt-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8707f534b74f2c0db73c3005b88e590a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6077,
            "upload_time": "2023-09-10T11:55:13",
            "upload_time_iso_8601": "2023-09-10T11:55:13.834070Z",
            "url": "https://files.pythonhosted.org/packages/22/b7/6c69d7893444c904b3377bf2e16b292e36c47c0e1c70c680ba4e3047be46/django-gpt-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-10 11:55:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "markolofsen",
    "github_project": "django-gpt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-gpt"
}
        
Elapsed time: 0.11690s