Skip to main content

AI support for your django app.

Project description

django-ai-support

This library is powered by langchain and langgraph to make easy AI support for your online shop or any website you want to create with Django.

This is used Agent workflow

Get started

settings

Settings should be something like this

AI_SUPPORT_SETTINGS = {
    "TOOLS": [],
    "SYSTEM_PROMPT": "You are the supporter of a bookstore website.",
    "LLM_MODEL": model,
}

TOOLS: tools are for your AI model.

SYSTEM_PROMPT: This is important for your AI support, but the default prompt is: You are the supporter of a bookstore website. As you see.

LLM_MODEL: your chat model. like this:

model = init_chat_model("gemini-2.5-flash", model_provider="google_genai")

see more

Be careful: LLM_MODEL can not be None.

config

Additionally, you can integrate your tools within your apps and add them to TOOLS.

For example, I have an app with the name of book. and this is inside of my tools.py file:

from langchain_core.tools import tool

from .models import Book

@tool(description="this is to get list of book with a price")
def get_books_with_price(price:int) -> str:
    """
    get book with input price

    Args:
        price (int): price. in dollars

    Returns:
        str: list of books.
    """
    text = ""

    for book in Book.objects.filter(price=price).select_related("author"):
        book_detail = f"book name: {book.name}, book price: {book.price}, Author: {book.author.first_name} {book.author.last_name}"
        text += book_detail + "\n"

    return text

After that, I can add this tool easily. This is inside my apps.py file:

from django.apps import AppConfig


class BookConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'book'

    def ready(self):
        from .tools import get_books_with_price as  my_tool
        from django_ai_support.conf import append_tools

        append_tools([my_tool])

read more about tool calling in langchain

API

Now, you can use the chat API to talk with your AI support:

from django.urls import path

from django_ai_support.views import ChatAiSupportApi

urlpatterns = [
    path("ai/", ChatAiSupportApi.as_view())
]

swagger

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_ai_support-0.1.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

django_ai_support-0.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file django_ai_support-0.1.tar.gz.

File metadata

  • Download URL: django_ai_support-0.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for django_ai_support-0.1.tar.gz
Algorithm Hash digest
SHA256 aaea38ef8c66ae77761cfc43e6bfabbf5c40a0eca94b9ced7e7bec904c817946
MD5 7e222404f99fa2e6acf07769abea4a28
BLAKE2b-256 aa6e911277eb8f2743315eb49052d7af7602d36e7c0acb2adefe26e8414dfa0e

See more details on using hashes here.

File details

Details for the file django_ai_support-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_ai_support-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 14312a09ffe930f10300a338fad58486873c7afd8539c6dc0b6075b5f6a5f3d0
MD5 0591881eea1f1ac575cc8a39d2e9aa3b
BLAKE2b-256 f3614a00b5ead28bf71385b414bfd0843bcf2dce639ce47932f0ef149cef6ca9

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