Skip to content

json_views

django_spire.ai.chat.views.json_views

delete_chat_view

Source code in django_spire/ai/chat/views/json_views.py
def delete_chat_view(request: WSGIRequest, pk: int) -> JsonResponse:
    try:
        chat = Chat.objects.get(pk=pk)
    except Chat.DoesNotExist:
        return JsonResponse(
            {
                'type': 'error',
                'message': 'Chat does not exist. Refresh and try again.'
            }
        )

    chat.set_deleted()

    return JsonResponse({'type': 'success', 'message': 'Chat deleted.'})

rename_chat_view

Source code in django_spire/ai/chat/views/json_views.py
def rename_chat_view(request: WSGIRequest, pk: int) -> JsonResponse:
    try:
        chat = Chat.objects.get(pk=pk)
    except Chat.DoesNotExist:
        return JsonResponse(
            {
                'type': 'error',
                'message': 'Chat does not exist. Refresh and try again.'
            }
        )

    new_chat_name = json.loads(request.body.decode("utf-8")).get('new_name', '')

    if new_chat_name == '' or len(new_chat_name) > 128:
        return JsonResponse({'type': 'error', 'message': 'Chat name was not updated.'})

    chat.name = new_chat_name
    chat.save()

    return JsonResponse({'type': 'success'})

chat_workflow_process_view

Source code in django_spire/ai/chat/views/json_views.py
def chat_workflow_process_view(request: WSGIRequest) -> JsonResponse:
    body = json.loads(request.body.decode('utf-8'))
    return JsonResponse({'response': chat_workflow_process(request, body)})