diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Houshyar/__pycache__/settings.cpython-312.pyc b/Houshyar/__pycache__/settings.cpython-312.pyc index bd87013..c614041 100644 Binary files a/Houshyar/__pycache__/settings.cpython-312.pyc and b/Houshyar/__pycache__/settings.cpython-312.pyc differ diff --git a/Houshyar/__pycache__/urls.cpython-312.pyc b/Houshyar/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..be500ee Binary files /dev/null and b/Houshyar/__pycache__/urls.cpython-312.pyc differ diff --git a/Houshyar/__pycache__/wsgi.cpython-312.pyc b/Houshyar/__pycache__/wsgi.cpython-312.pyc new file mode 100644 index 0000000..e0899c2 Binary files /dev/null and b/Houshyar/__pycache__/wsgi.cpython-312.pyc differ diff --git a/chat/__pycache__/__init__.cpython-312.pyc b/chat/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..5532a38 Binary files /dev/null and b/chat/__pycache__/__init__.cpython-312.pyc differ diff --git a/chat/__pycache__/admin.cpython-312.pyc b/chat/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..e4b346f Binary files /dev/null and b/chat/__pycache__/admin.cpython-312.pyc differ diff --git a/chat/__pycache__/apps.cpython-312.pyc b/chat/__pycache__/apps.cpython-312.pyc new file mode 100644 index 0000000..4101c8e Binary files /dev/null and b/chat/__pycache__/apps.cpython-312.pyc differ diff --git a/chat/__pycache__/models.cpython-312.pyc b/chat/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..860bf0e Binary files /dev/null and b/chat/__pycache__/models.cpython-312.pyc differ diff --git a/chat/__pycache__/schema.cpython-312.pyc b/chat/__pycache__/schema.cpython-312.pyc new file mode 100644 index 0000000..75675a7 Binary files /dev/null and b/chat/__pycache__/schema.cpython-312.pyc differ diff --git a/chat/__pycache__/urls.cpython-312.pyc b/chat/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..d7e0683 Binary files /dev/null and b/chat/__pycache__/urls.cpython-312.pyc differ diff --git a/chat/__pycache__/views.cpython-312.pyc b/chat/__pycache__/views.cpython-312.pyc new file mode 100644 index 0000000..51e6958 Binary files /dev/null and b/chat/__pycache__/views.cpython-312.pyc differ diff --git a/chat/migrations/__pycache__/__init__.cpython-312.pyc b/chat/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..2371675 Binary files /dev/null and b/chat/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/chat/schema.py b/chat/schema.py index 357511f..168adc5 100644 --- a/chat/schema.py +++ b/chat/schema.py @@ -148,84 +148,8 @@ MODELS_SCHEMA = { } } -from datetime import datetime, timedelta -from django.utils import timezone -def apply_date_filter(queryset, date_filter): - if not date_filter: - return queryset - - field = date_filter.get("field", "Date") - filter_type = date_filter.get("type") - value = date_filter.get("value") - - now = timezone.now() - - # امروز - if filter_type == "today": - start = now.replace(hour=0, minute=0, second=0, microsecond=0) - end = start + timedelta(days=1) - return queryset.filter( - **{f"{field}__gte": start, f"{field}__lt": end} - ) - - # دیروز - if filter_type == "yesterday": - start = (now - timedelta(days=1)).replace( - hour=0, minute=0, second=0, microsecond=0 - ) - end = start + timedelta(days=1) - return queryset.filter( - **{f"{field}__gte": start, f"{field}__lt": end} - ) - - # n روز گذشته - if filter_type == "last_n_days" and value: - start = now - timedelta(days=int(value)) - return queryset.filter(**{f"{field}__gte": start}) - - # این هفته - if filter_type == "this_week": - start = now - timedelta(days=now.weekday()) - start = start.replace(hour=0, minute=0, second=0, microsecond=0) - return queryset.filter(**{f"{field}__gte": start}) - - # این ماه - if filter_type == "this_month": - start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0) - return queryset.filter(**{f"{field}__gte": start}) - - # n ماه گذشته - if filter_type == "last_n_month" and value: - start = now - for _ in range(int(value)): - start = (start.replace(day=1) - timedelta(days=1)).replace(day=1) - start = start.replace(hour=0, minute=0, second=0, microsecond=0) - return queryset.filter(**{f"{field}__gte": start}) - - # این سال - if filter_type == "this_year": - start = now.replace( - month=1, day=1, hour=0, minute=0, second=0, microsecond=0 - ) - return queryset.filter(**{f"{field}__gte": start}) - - # n سال گذشته - if filter_type == "last_n_year" and value: - start = now.replace( - year=now.year - int(value), - month=1, - day=1, - hour=0, - minute=0, - second=0, - microsecond=0 - ) - return queryset.filter(**{f"{field}__gte": start}) - - return queryset - def clean_gpt_json(text): """ diff --git a/chat/urls.py b/chat/urls.py index 381660d..eb17f0b 100644 --- a/chat/urls.py +++ b/chat/urls.py @@ -3,5 +3,5 @@ from django.urls import path from chat.views import get_ai_response urlpatterns = [ - path("get_ai_response/", get_ai_response), + path("ask/", get_ai_response), ] \ No newline at end of file diff --git a/chat/views.py b/chat/views.py index a354ac8..0164101 100644 --- a/chat/views.py +++ b/chat/views.py @@ -1,5 +1,4 @@ import requests -from django.db.models import Sum from django.views.decorators.csrf import csrf_exempt from rest_framework import status from rest_framework.decorators import api_view, permission_classes @@ -7,7 +6,7 @@ from rest_framework.permissions import AllowAny from rest_framework.response import Response from openai import OpenAI -from schema import get_filters_from_question, apply_date_filter +from chat.schema import get_filters_from_question API_KEY = "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" # ⚠️ جایگزین با کلیدت کن RSI_URL='https://rsibackend.rasadyar.com/app/get_ai_response/' @@ -37,6 +36,7 @@ def get_ai_response(request): verify=False ) + result_data = result_data.json() # تولید پاسخ نهایی با GPT prompt = f""" diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..e69de29