diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..66afe81 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +SHELL := /bin/bash +CONDA := /home/paul/anaconda3/bin/conda + +run_server: + source $$(/home/paul/miniconda/bin/conda info --base)/etc/profile.d/conda.sh ; \ + conda activate appenv ; \ + python backend/manage.py makemigrations ; \ + python backend/manage.py migrate ; \ + python backend/manage.py runserver diff --git a/backend/backend/__init__.py b/backend/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/backend/__pycache__/__init__.cpython-311.pyc b/backend/backend/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..684bc45 Binary files /dev/null and b/backend/backend/__pycache__/__init__.cpython-311.pyc differ diff --git a/backend/backend/__pycache__/settings.cpython-311.pyc b/backend/backend/__pycache__/settings.cpython-311.pyc new file mode 100644 index 0000000..69b07b5 Binary files /dev/null and b/backend/backend/__pycache__/settings.cpython-311.pyc differ diff --git a/backend/backend/__pycache__/urls.cpython-311.pyc b/backend/backend/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..71de28b Binary files /dev/null and b/backend/backend/__pycache__/urls.cpython-311.pyc differ diff --git a/backend/backend/__pycache__/wsgi.cpython-311.pyc b/backend/backend/__pycache__/wsgi.cpython-311.pyc new file mode 100644 index 0000000..87b18c3 Binary files /dev/null and b/backend/backend/__pycache__/wsgi.cpython-311.pyc differ diff --git a/backend/backend/asgi.py b/backend/backend/asgi.py new file mode 100644 index 0000000..15b2aa4 --- /dev/null +++ b/backend/backend/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for backend project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') + +application = get_asgi_application() diff --git a/backend/backend/settings.py b/backend/backend/settings.py new file mode 100644 index 0000000..479d8c0 --- /dev/null +++ b/backend/backend/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for backend project. + +Generated by 'django-admin startproject' using Django 4.2.4. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-c6k@o#a!)p0=l1q%_zc!=tw624-*4a6u*c651oon7r_k+0&mrs' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True +ALLOWED_HOSTS = ["*"] +CORS_ORIGIN_ALLOW_ALL = True +CORS_ALLOWED_ORIGINS = [] + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'rest_framework', + 'drag', + 'corsheaders', +] + +MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'backend.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'backend.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/backend/backend/urls.py b/backend/backend/urls.py new file mode 100644 index 0000000..234b500 --- /dev/null +++ b/backend/backend/urls.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('drag.urls')), +] diff --git a/backend/backend/wsgi.py b/backend/backend/wsgi.py new file mode 100644 index 0000000..ac58012 --- /dev/null +++ b/backend/backend/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for backend project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') + +application = get_wsgi_application() diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 new file mode 100644 index 0000000..7bffb97 Binary files /dev/null and b/backend/db.sqlite3 differ diff --git a/backend/drag/__init__.py b/backend/drag/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/drag/__pycache__/__init__.cpython-311.pyc b/backend/drag/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..3f1f452 Binary files /dev/null and b/backend/drag/__pycache__/__init__.cpython-311.pyc differ diff --git a/backend/drag/__pycache__/admin.cpython-311.pyc b/backend/drag/__pycache__/admin.cpython-311.pyc new file mode 100644 index 0000000..af26cfd Binary files /dev/null and b/backend/drag/__pycache__/admin.cpython-311.pyc differ diff --git a/backend/drag/__pycache__/apps.cpython-311.pyc b/backend/drag/__pycache__/apps.cpython-311.pyc new file mode 100644 index 0000000..05cd70f Binary files /dev/null and b/backend/drag/__pycache__/apps.cpython-311.pyc differ diff --git a/backend/drag/__pycache__/models.cpython-311.pyc b/backend/drag/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..7a5c77e Binary files /dev/null and b/backend/drag/__pycache__/models.cpython-311.pyc differ diff --git a/backend/drag/__pycache__/serializers.cpython-311.pyc b/backend/drag/__pycache__/serializers.cpython-311.pyc new file mode 100644 index 0000000..05af6da Binary files /dev/null and b/backend/drag/__pycache__/serializers.cpython-311.pyc differ diff --git a/backend/drag/__pycache__/urls.cpython-311.pyc b/backend/drag/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..e83e149 Binary files /dev/null and b/backend/drag/__pycache__/urls.cpython-311.pyc differ diff --git a/backend/drag/__pycache__/views.cpython-311.pyc b/backend/drag/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..244cbf6 Binary files /dev/null and b/backend/drag/__pycache__/views.cpython-311.pyc differ diff --git a/backend/drag/admin.py b/backend/drag/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/backend/drag/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/backend/drag/apps.py b/backend/drag/apps.py new file mode 100644 index 0000000..608ba09 --- /dev/null +++ b/backend/drag/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class DragConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'drag' diff --git a/backend/drag/migrations/__init__.py b/backend/drag/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/drag/migrations/__pycache__/__init__.cpython-311.pyc b/backend/drag/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..8b7684e Binary files /dev/null and b/backend/drag/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/backend/drag/models.py b/backend/drag/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/backend/drag/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/backend/drag/serializers.py b/backend/drag/serializers.py new file mode 100644 index 0000000..2bcbdf0 --- /dev/null +++ b/backend/drag/serializers.py @@ -0,0 +1,11 @@ +from rest_framework import serializers + +class QuestionSerializer(serializers.Serializer): + question = serializers.CharField() + userId = serializers.CharField() + +class FeedbackSerializer(serializers.Serializer): + previousQuestion = serializers.CharField() + previousResults = serializers.JSONField() + feedback = serializers.ChoiceField(choices=['OKAY', 'BAD_GPT', 'BAD_DOCUMENTS']) + userId = serializers.CharField() diff --git a/backend/drag/tests.py b/backend/drag/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/backend/drag/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/drag/urls.py b/backend/drag/urls.py new file mode 100644 index 0000000..7707637 --- /dev/null +++ b/backend/drag/urls.py @@ -0,0 +1,11 @@ +from django.urls import path, include +from rest_framework.routers import DefaultRouter +from .views import AskQuestionViewSet, SendFeedbackViewSet + +router = DefaultRouter() +router.register(r'askQuestion', AskQuestionViewSet, basename='ask-question') +router.register(r'sendFeedback', SendFeedbackViewSet, basename='send-feedback') + +urlpatterns = [ + path('', include(router.urls)), +] diff --git a/backend/drag/views.py b/backend/drag/views.py new file mode 100644 index 0000000..eb6c8f8 --- /dev/null +++ b/backend/drag/views.py @@ -0,0 +1,41 @@ +from rest_framework import viewsets, status +from rest_framework.response import Response +from .serializers import QuestionSerializer, FeedbackSerializer + +def query_model(question): + # Replace this with the actual implementation + return { + "result": [ + {'url': 'http://example.com' + , 'description': 'Example' + , 'sysId': 'ahsoashoa' + , 'type': 'PDF' + , 'language': 'English' + } + ] + } + + +def handle_feedback(feedback, previousQuestion, previousResults): + # Replace this with the actual implementation + return [{'status': 'received'}] + +class AskQuestionViewSet(viewsets.ViewSet): + def create(self, request): + serializer = QuestionSerializer(data=request.data) + if serializer.is_valid(): + data = serializer.validated_data + response_data = query_model(data['question']) + return Response(response_data, status=status.HTTP_200_OK) + else: + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +class SendFeedbackViewSet(viewsets.ViewSet): + def create(self, request): + serializer = FeedbackSerializer(data=request.data) + if serializer.is_valid(): + data = serializer.validated_data + response_data = handle_feedback(data['feedback'], data['previousQuestion'], data['previousResults']) + return Response(response_data, status=status.HTTP_200_OK) + else: + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) diff --git a/backend/manage.py b/backend/manage.py new file mode 100755 index 0000000..eb6431e --- /dev/null +++ b/backend/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main()