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.8.tar.gz (16.9 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.8-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_ai_support-0.1.8.tar.gz
  • Upload date:
  • Size: 16.9 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.8.tar.gz
Algorithm Hash digest
SHA256 8f26c3876721e5600dbc6836276d7123f3c7a58e1b842c49036e6512842e7880
MD5 bd358ca7189f3d00bd449a24d9ebe1df
BLAKE2b-256 faa5b90a8e86b76f1b07081f9516ecd05ef3724bcf82d1ce79dabfd0e0dfd4cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_ai_support-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1e5fbb2194d9f89af8340207a29a022f90c68fcd615948aa550ed77e1ad5c890
MD5 0fb2b89f2928a3ebd1fcc934202d58af
BLAKE2b-256 e51bb48d3c0da3f094991632a5ddb89af8cdafe8c7615e676cedc130cb95fb54

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