Metadata-Version: 2.4
Name: django-ai-support
Version: 0.1.8
Summary: AI support for your django app.
Author-email: EmadDeve20 <emaddeve20@gmail.com>
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/EmadDeve20/django-ai-support
Project-URL: Issues, https://github.com/EmadDeve20/django-ai-support/issues
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.0
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=4.0
Requires-Dist: djangorestframework>=3.13.1
Requires-Dist: langchain>=0.3.27
Requires-Dist: langchain>=0.3.27
Requires-Dist: langgraph>=0.6.10
Requires-Dist: drf-spectacular>=0.24.2
Dynamic: license-file

# 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](https://langchain-ai.github.io/langgraph/tutorials/workflows/#agent)

## Get started

### settings

Settings should be something like this 

```python
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:

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

[see more](https://python.langchain.com/docs/integrations/chat/)

*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:

```python
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:

```python
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](https://langchain-ai.github.io/langgraph/how-tos/tool-calling/#dynamically-select-tools)


### API

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

```python
from django.urls import path

from django_ai_support.views import ChatAiSupportApi

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

![swagger](./images/swagger-example.png)

