18 lines
691 B
Python
18 lines
691 B
Python
from django.http import JsonResponse
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.contrib.auth.decorators import login_required
|
|
import json
|
|
|
|
@csrf_exempt
|
|
@login_required
|
|
def ai_chat(request, pk):
|
|
if request.method == 'POST':
|
|
data = json.loads(request.body)
|
|
user_message = data.get('message')
|
|
|
|
# In a real app, this would call your AI service (e.g., GPT, Gemini)
|
|
# Here we mock the AI response
|
|
ai_response = f"AI thinking about: {user_message}. Based on my analysis, you should consider..."
|
|
|
|
return JsonResponse({'response': ai_response})
|
|
return JsonResponse({'error': 'Invalid request'}, status=400) |