update permissions, add logging
Browse files- api/views.py +6 -1
- backend/settings.py +25 -0
api/views.py
CHANGED
|
@@ -1,19 +1,23 @@
|
|
| 1 |
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
|
|
| 2 |
from rest_framework.response import Response
|
| 3 |
-
from rest_framework.decorators import api_view
|
| 4 |
from rest_framework import status
|
| 5 |
from agent_manager import get_or_create_agent, end_session, get_message_list
|
| 6 |
import logging
|
| 7 |
|
| 8 |
@csrf_exempt
|
|
|
|
| 9 |
@api_view(['GET'])
|
| 10 |
def hello(request):
|
| 11 |
return Response({"message": "Hello from Grammo!"})
|
| 12 |
|
| 13 |
@csrf_exempt
|
|
|
|
| 14 |
@api_view(['POST'])
|
| 15 |
def chat(request):
|
| 16 |
"""Start or continue an existing chat session."""
|
|
|
|
| 17 |
chat_session = request.data.get("chatSession")
|
| 18 |
message = request.data.get("message")
|
| 19 |
logging.getLogger(__name__).info(f"Received message: {message}")
|
|
@@ -49,6 +53,7 @@ def chat(request):
|
|
| 49 |
}, status=status.HTTP_200_OK)
|
| 50 |
|
| 51 |
@csrf_exempt
|
|
|
|
| 52 |
@api_view(['POST'])
|
| 53 |
def end(request):
|
| 54 |
"""End and delete the chat session."""
|
|
|
|
| 1 |
from django.views.decorators.csrf import csrf_exempt
|
| 2 |
+
from rest_framework.decorators import api_view, permission_classes
|
| 3 |
+
from rest_framework.permissions import AllowAny
|
| 4 |
from rest_framework.response import Response
|
|
|
|
| 5 |
from rest_framework import status
|
| 6 |
from agent_manager import get_or_create_agent, end_session, get_message_list
|
| 7 |
import logging
|
| 8 |
|
| 9 |
@csrf_exempt
|
| 10 |
+
@permission_classes([AllowAny])
|
| 11 |
@api_view(['GET'])
|
| 12 |
def hello(request):
|
| 13 |
return Response({"message": "Hello from Grammo!"})
|
| 14 |
|
| 15 |
@csrf_exempt
|
| 16 |
+
@permission_classes([AllowAny])
|
| 17 |
@api_view(['POST'])
|
| 18 |
def chat(request):
|
| 19 |
"""Start or continue an existing chat session."""
|
| 20 |
+
logging.getLogger(__name__).info(f"Received a chat request.")
|
| 21 |
chat_session = request.data.get("chatSession")
|
| 22 |
message = request.data.get("message")
|
| 23 |
logging.getLogger(__name__).info(f"Received message: {message}")
|
|
|
|
| 53 |
}, status=status.HTTP_200_OK)
|
| 54 |
|
| 55 |
@csrf_exempt
|
| 56 |
+
@permission_classes([AllowAny])
|
| 57 |
@api_view(['POST'])
|
| 58 |
def end(request):
|
| 59 |
"""End and delete the chat session."""
|
backend/settings.py
CHANGED
|
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
|
|
| 11 |
"""
|
| 12 |
|
| 13 |
import os
|
|
|
|
| 14 |
from pathlib import Path
|
| 15 |
from dotenv import load_dotenv
|
| 16 |
|
|
@@ -181,3 +182,27 @@ STATIC_URL = 'static/'
|
|
| 181 |
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
| 182 |
|
| 183 |
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
"""
|
| 12 |
|
| 13 |
import os
|
| 14 |
+
import sys
|
| 15 |
from pathlib import Path
|
| 16 |
from dotenv import load_dotenv
|
| 17 |
|
|
|
|
| 182 |
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
| 183 |
|
| 184 |
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
| 185 |
+
|
| 186 |
+
# LOGGING
|
| 187 |
+
|
| 188 |
+
LOGGING = {
|
| 189 |
+
'version': 1,
|
| 190 |
+
'disable_existing_loggers': False,
|
| 191 |
+
'handlers': {
|
| 192 |
+
'console': {
|
| 193 |
+
'class': 'logging.StreamHandler',
|
| 194 |
+
'stream': sys.stdout,
|
| 195 |
+
},
|
| 196 |
+
},
|
| 197 |
+
'root': {
|
| 198 |
+
'handlers': ['console'],
|
| 199 |
+
'level': 'INFO',
|
| 200 |
+
},
|
| 201 |
+
'loggers': {
|
| 202 |
+
'django': {
|
| 203 |
+
'handlers': ['console'],
|
| 204 |
+
'level': 'INFO',
|
| 205 |
+
'propagate': True,
|
| 206 |
+
},
|
| 207 |
+
},
|
| 208 |
+
}
|