From 4a27d09cce2a19dc809f8dcc947fb0b717728935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Mon, 21 Oct 2024 11:26:09 +0100 Subject: [PATCH 01/11] Adds django and settings table. --- asgi_app.py | 28 ++++ {labs/config => config}/__init__.py | 0 config/admin.py | 7 + config/asgi.py | 16 +++ .../configuration_variables.py | 0 {labs/config => config}/litellm.yaml | 0 config/migrations/0001_initial.py | 42 ++++++ config/migrations/__init__.py | 0 config/models.py | 18 +++ config/settings.py | 132 ++++++++++++++++++ config/urls.py | 22 +++ config/wsgi.py | 16 +++ labs/celery.py | 4 +- labs/llm.py | 16 ++- labs/repo.py | 50 +++++-- labs/run.py | 22 ++- manage.py | 22 +++ poetry.lock | 57 +++++++- pyproject.toml | 2 + 19 files changed, 433 insertions(+), 21 deletions(-) create mode 100644 asgi_app.py rename {labs/config => config}/__init__.py (100%) create mode 100644 config/admin.py create mode 100644 config/asgi.py rename labs/config/settings.py => config/configuration_variables.py (100%) rename {labs/config => config}/litellm.yaml (100%) create mode 100644 config/migrations/0001_initial.py create mode 100644 config/migrations/__init__.py create mode 100644 config/models.py create mode 100644 config/settings.py create mode 100644 config/urls.py create mode 100644 config/wsgi.py create mode 100755 manage.py diff --git a/asgi_app.py b/asgi_app.py new file mode 100644 index 0000000..4e49b02 --- /dev/null +++ b/asgi_app.py @@ -0,0 +1,28 @@ +import os +import django +from fastapi import FastAPI +from django.core.asgi import get_asgi_application + +# Set the DJANGO_SETTINGS_MODULE environment variable to point to your Django project's settings +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +# Initialize Django settings +django.setup() + +# Load Django ASGI application +django_app = get_asgi_application() + +# Create FastAPI app +fastapi_app = FastAPI() + +# Sample FastAPI route +@fastapi_app.get("/fastapi") +async def fastapi_root(): + return {"message": "Hello from FastAPI"} + +# ASGI application to route to Django or FastAPI +async def app(scope, receive, send): + if scope["type"] == "http" and scope["path"].startswith("/d"): + await django_app(scope, receive, send) + else: + await fastapi_app(scope, receive, send) diff --git a/labs/config/__init__.py b/config/__init__.py similarity index 100% rename from labs/config/__init__.py rename to config/__init__.py diff --git a/config/admin.py b/config/admin.py new file mode 100644 index 0000000..90a9055 --- /dev/null +++ b/config/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from .models import Config + +@admin.register(Config) +class ConfigAdmin(admin.ModelAdmin): + list_display = ('llm_model', 'config_key', 'config_value', 'config_type', 'created_at', 'updated_at') + search_fields = (['config_key', 'llm_model']) diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 0000000..19b90e3 --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config 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/5.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +application = get_asgi_application() diff --git a/labs/config/settings.py b/config/configuration_variables.py similarity index 100% rename from labs/config/settings.py rename to config/configuration_variables.py diff --git a/labs/config/litellm.yaml b/config/litellm.yaml similarity index 100% rename from labs/config/litellm.yaml rename to config/litellm.yaml diff --git a/config/migrations/0001_initial.py b/config/migrations/0001_initial.py new file mode 100644 index 0000000..415801f --- /dev/null +++ b/config/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# Generated by Django 5.1.2 on 2024-10-18 14:13 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Config", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("llm_model", models.TextField(blank=True, null=True)), + ("config_key", models.TextField(unique=True)), + ("config_value", models.TextField(blank=True, null=True)), + ("config_type", models.TextField(blank=True, null=True)), + ("created_at", models.DateTimeField(default=django.utils.timezone.now)), + ("updated_at", models.DateTimeField(auto_now=True)), + ], + options={ + "indexes": [ + models.Index( + fields=["config_key", "llm_model"], + name="config_conf_config__4d9363_idx", + ) + ], + }, + ), + ] diff --git a/config/migrations/__init__.py b/config/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/models.py b/config/models.py new file mode 100644 index 0000000..be952ce --- /dev/null +++ b/config/models.py @@ -0,0 +1,18 @@ +from django.db import models +from django.utils import timezone + +class Config(models.Model): + llm_model = models.TextField(blank=True, null=True) + config_key = models.TextField(unique=True) + config_value = models.TextField(blank=True, null=True) + config_type = models.TextField(blank=True, null=True) + created_at = models.DateTimeField(default=timezone.now) + updated_at = models.DateTimeField(auto_now=True) + + def __str__(self): + return f"{self.config_key}: {self.config_value}" + + class Meta: + indexes = [ + models.Index(fields=['config_key', 'llm_model']) + ] diff --git a/config/settings.py b/config/settings.py new file mode 100644 index 0000000..f574918 --- /dev/null +++ b/config/settings.py @@ -0,0 +1,132 @@ +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 5.1.2. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.1/ref/settings/ +""" +import os +from pathlib import Path +from dotenv import load_dotenv + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + +# Explicitly load the .env.local file from the project root +dotenv_path = os.path.join(BASE_DIR, '.env.local') +load_dotenv(dotenv_path) + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-hxak7+phh51^p%vuxxk5%28b4tz^%e1m=6@q*tmf1eq-0$32_3" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "config", + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", +] + +MIDDLEWARE = [ + "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 = "config.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 = "config.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/5.1/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": os.environ.get("DATABASE_NAME"), + "USER": os.environ.get("DATABASE_USER"), + "PASSWORD": os.environ.get("DATABASE_PASS"), + "HOST": os.environ.get("DATABASE_HOST"), + "PORT": os.environ.get("DATABASE_PORT"), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.1/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/5.1/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/5.1/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..62fa85f --- /dev/null +++ b/config/urls.py @@ -0,0 +1,22 @@ +""" +URL configuration for config project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path("django/admin/", admin.site.urls), +] diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 0000000..b2bb19f --- /dev/null +++ b/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config 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/5.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +application = get_wsgi_application() diff --git a/labs/celery.py b/labs/celery.py index 6eb3acc..fe02801 100644 --- a/labs/celery.py +++ b/labs/celery.py @@ -14,7 +14,9 @@ LOW_PRIORITY_QUEUE_NAME = f"{CELERY_QUEUE_PREFIX}-low" HIGH_PRIORITY_QUEUE_NAME = f"{CELERY_QUEUE_PREFIX}-high" -redis_client = redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0, decode_responses=True) +redis_client = redis.StrictRedis( + host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0, decode_responses=True +) app = Celery( diff --git a/labs/llm.py b/labs/llm.py index da12165..8aa333c 100644 --- a/labs/llm.py +++ b/labs/llm.py @@ -47,7 +47,9 @@ def prepare_context(context, prompt): def check_length_issue(llm_response): - finish_reason = getattr(llm_response["choices"][0]["message"], "finish_reason", None) + finish_reason = getattr( + llm_response["choices"][0]["message"], "finish_reason", None + ) if finish_reason == "length": return ( True, @@ -57,7 +59,9 @@ def check_length_issue(llm_response): def check_content_filter(llm_response): - finish_reason = getattr(llm_response["choices"][0]["message"], "finish_reason", None) + finish_reason = getattr( + llm_response["choices"][0]["message"], "finish_reason", None + ) if finish_reason == "content_filter": return ( True, @@ -110,7 +114,9 @@ def get_llm_response(prepared_context): while redo and retries < max_retries: try: - llm_response = litellm_requests.completion_without_proxy(prepared_context, model=settings.LLM_MODEL_NAME) + llm_response = litellm_requests.completion_without_proxy( + prepared_context, model=settings.LLM_MODEL_NAME + ) logger.debug(f"LLM Response: {llm_response}") redo, redo_reason = validate_llm_response(llm_response) except Exception: @@ -140,6 +146,8 @@ def call_llm_with_context(repo_destination, issue_summary): prompt = get_prompt(issue_summary) prepared_context = prepare_context(context, prompt) - logger.debug(f"Issue Summary: {issue_summary} - LLM Model: {settings.LLM_MODEL_NAME}") + logger.debug( + f"Issue Summary: {issue_summary} - LLM Model: {settings.LLM_MODEL_NAME}" + ) return get_llm_response(prepared_context) diff --git a/labs/repo.py b/labs/repo.py index 98d14b0..b8e71f3 100644 --- a/labs/repo.py +++ b/labs/repo.py @@ -16,15 +16,35 @@ def clone_repository(repo_url, local_path): @time_and_log_function def get_issue(token, repo_owner, repo_name, username, issue_number): - github_request = GithubRequests(github_token=token, repo_owner=repo_owner, repo_name=repo_name, username=username) + github_request = GithubRequests( + github_token=token, + repo_owner=repo_owner, + repo_name=repo_name, + username=username, + ) return github_request.get_issue(issue_number) @time_and_log_function -def create_branch(token, repo_owner, repo_name, username, issue_number, issue_title, original_branch="main"): - github_request = GithubRequests(github_token=token, repo_owner=repo_owner, repo_name=repo_name, username=username) +def create_branch( + token, + repo_owner, + repo_name, + username, + issue_number, + issue_title, + original_branch="main", +): + github_request = GithubRequests( + github_token=token, + repo_owner=repo_owner, + repo_name=repo_name, + username=username, + ) branch_name = f"{issue_number}-{issue_title}" - github_request.create_branch(branch_name=branch_name, original_branch=original_branch) + github_request.create_branch( + branch_name=branch_name, original_branch=original_branch + ) return branch_name @@ -35,13 +55,27 @@ def change_issue_to_in_progress(): @time_and_log_function def commit_changes(token, repo_owner, repo_name, username, branch_name, file_list): - github_request = GithubRequests(github_token=token, repo_owner=repo_owner, repo_name=repo_name, username=username) - return github_request.commit_changes("fix", branch_name=branch_name, files=file_list) + github_request = GithubRequests( + github_token=token, + repo_owner=repo_owner, + repo_name=repo_name, + username=username, + ) + return github_request.commit_changes( + "fix", branch_name=branch_name, files=file_list + ) @time_and_log_function -def create_pull_request(token, repo_owner, repo_name, username, original_branch, branch_name): - github_request = GithubRequests(github_token=token, repo_owner=repo_owner, repo_name=repo_name, username=username) +def create_pull_request( + token, repo_owner, repo_name, username, original_branch, branch_name +): + github_request = GithubRequests( + github_token=token, + repo_owner=repo_owner, + repo_name=repo_name, + username=username, + ) return github_request.create_pull_request(branch_name, base=original_branch) diff --git a/labs/run.py b/labs/run.py index 2a424f9..1a3dd02 100644 --- a/labs/run.py +++ b/labs/run.py @@ -17,12 +17,22 @@ @time_and_log_function -def run_on_repo(token, repo_owner, repo_name, username, issue_number, original_branch="main"): +def run_on_repo( + token, repo_owner, repo_name, username, issue_number, original_branch="main" +): issue = get_issue(token, repo_owner, repo_name, username, issue_number) issue_title = issue["title"].replace(" ", "-") issue_summary = issue["body"] - branch_name = create_branch(token, repo_owner, repo_name, username, issue_number, issue_title, original_branch) + branch_name = create_branch( + token, + repo_owner, + repo_name, + username, + issue_number, + issue_title, + original_branch, + ) repo_url = f"https://github.com/{repo_owner}/{repo_name}" logger.debug(f"Cloning repo from {repo_url}") @@ -35,7 +45,9 @@ def run_on_repo(token, repo_owner, repo_name, username, issue_number, original_b logger.error("Failed to get a response from LLM, aborting run.") return - response_output = call_agent_to_apply_code_changes(llm_response[1].choices[0].message.content) + response_output = call_agent_to_apply_code_changes( + llm_response[1].choices[0].message.content + ) commit_changes(token, repo_owner, repo_name, username, branch_name, response_output) create_pull_request(token, repo_owner, repo_name, username, branch_name) @@ -48,5 +60,7 @@ def run_on_local_repo(repo_path, issue_text): logger.error("Failed to get a response from LLM, aborting run.") return - response_output = call_agent_to_apply_code_changes(llm_response[1].choices[0].message.content) + response_output = call_agent_to_apply_code_changes( + llm_response[1].choices[0].message.content + ) return True, response_output diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..d28672e --- /dev/null +++ b/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", "config.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() diff --git a/poetry.lock b/poetry.lock index cfe11ad..01f1356 100644 --- a/poetry.lock +++ b/poetry.lock @@ -268,6 +268,20 @@ types-python-dateutil = ">=2.8.10" doc = ["doc8", "sphinx (>=7.0.0)", "sphinx-autobuild", "sphinx-autodoc-typehints", "sphinx_rtd_theme (>=1.3.0)"] test = ["dateparser (==1.*)", "pre-commit", "pytest", "pytest-cov", "pytest-mock", "pytz (==2021.1)", "simplejson (==3.*)"] +[[package]] +name = "asgiref" +version = "3.8.1" +description = "ASGI specs, helper code, and adapters" +optional = false +python-versions = ">=3.8" +files = [ + {file = "asgiref-3.8.1-py3-none-any.whl", hash = "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47"}, + {file = "asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590"}, +] + +[package.extras] +tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] + [[package]] name = "asttokens" version = "2.4.1" @@ -833,6 +847,26 @@ files = [ {file = "distro-1.9.0.tar.gz", hash = "sha256:2fa77c6fd8940f116ee1d6b94a2f90b13b5ea8d019b98bc8bafdcabcdd9bdbed"}, ] +[[package]] +name = "django" +version = "5.1.2" +description = "A high-level Python web framework that encourages rapid development and clean, pragmatic design." +optional = false +python-versions = ">=3.10" +files = [ + {file = "Django-5.1.2-py3-none-any.whl", hash = "sha256:f11aa87ad8d5617171e3f77e1d5d16f004b79a2cf5d2e1d2b97a6a1f8e9ba5ed"}, + {file = "Django-5.1.2.tar.gz", hash = "sha256:bd7376f90c99f96b643722eee676498706c9fd7dc759f55ebfaf2c08ebcdf4f0"}, +] + +[package.dependencies] +asgiref = ">=3.8.1,<4" +sqlparse = ">=0.3.1" +tzdata = {version = "*", markers = "sys_platform == \"win32\""} + +[package.extras] +argon2 = ["argon2-cffi (>=19.1.0)"] +bcrypt = ["bcrypt"] + [[package]] name = "dnspython" version = "2.6.1" @@ -4245,6 +4279,21 @@ postgresql-psycopgbinary = ["psycopg[binary] (>=3.0.7)"] pymysql = ["pymysql"] sqlcipher = ["sqlcipher3_binary"] +[[package]] +name = "sqlparse" +version = "0.5.1" +description = "A non-validating SQL parser." +optional = false +python-versions = ">=3.8" +files = [ + {file = "sqlparse-0.5.1-py3-none-any.whl", hash = "sha256:773dcbf9a5ab44a090f3441e2180efe2560220203dc2f8c0b0fa141e18b505e4"}, + {file = "sqlparse-0.5.1.tar.gz", hash = "sha256:bb6b4df465655ef332548e24f08e205afc81b9ab86cb1c45657a7ff173a3a00e"}, +] + +[package.extras] +dev = ["build", "hatch"] +doc = ["sphinx"] + [[package]] name = "stack-data" version = "0.6.3" @@ -4724,13 +4773,13 @@ socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [[package]] name = "uvicorn" -version = "0.30.6" +version = "0.32.0" description = "The lightning-fast ASGI server." optional = false python-versions = ">=3.8" files = [ - {file = "uvicorn-0.30.6-py3-none-any.whl", hash = "sha256:65fd46fe3fda5bdc1b03b94eb634923ff18cd35b2f084813ea79d1f103f711b5"}, - {file = "uvicorn-0.30.6.tar.gz", hash = "sha256:4b15decdda1e72be08209e860a1e10e92439ad5b97cf44cc945fcbee66fc5788"}, + {file = "uvicorn-0.32.0-py3-none-any.whl", hash = "sha256:60b8f3a5ac027dcd31448f411ced12b5ef452c646f76f02f8cc3f25d8d26fd82"}, + {file = "uvicorn-0.32.0.tar.gz", hash = "sha256:f78b36b143c16f54ccdb8190d0a26b5f1901fe5a3c777e1ab29f26391af8551e"}, ] [package.dependencies] @@ -5291,4 +5340,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.11.7" -content-hash = "0c7dca69dbe2d4a39a38ed18189de0f9daf7b18ddbf5e08690471a142b86f9fe" +content-hash = "de61b0371b4520bc42ad9788e2701d4cca6fada57b68e4d5ce07230e11d8b271" diff --git a/pyproject.toml b/pyproject.toml index 1b2743e..3c7aff8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,8 @@ langchain-community = "^0.3.0" celery = "^5.4.0" celery-redbeat = "^2.2.0" redis = "^5.1.0" +uvicorn = "^0.32.0" +django = "^5.1.2" [tool.poetry.group.dev.dependencies] pre-commit = "^3.8.0" From 0ed1921d9e75abc8d01f48ce49311be1d9a664b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Mon, 21 Oct 2024 15:37:23 +0100 Subject: [PATCH 02/11] Fixes issue with settings and .env import --- Makefile | 3 +++ asgi_app.py | 10 +++++----- config/settings.py | 4 ---- labs/celery.py | 2 +- labs/database/connect.py | 2 +- labs/database/vectorize.py | 2 +- labs/github/github.py | 2 +- labs/litellm_service/request.py | 2 +- labs/llm.py | 2 +- labs/run.py | 2 +- labs/tasks/llm.py | 2 +- labs/tasks/repo.py | 2 +- labs/tasks/run.py | 2 +- 13 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 16d426b..356d3f0 100644 --- a/Makefile +++ b/Makefile @@ -74,3 +74,6 @@ help: api: fastapi dev labs/api/main.py + +asgi_api: + poetry run uvicorn asgi_app:app --reload --port 8000 diff --git a/asgi_app.py b/asgi_app.py index 4e49b02..0dbd4fb 100644 --- a/asgi_app.py +++ b/asgi_app.py @@ -2,6 +2,7 @@ import django from fastapi import FastAPI from django.core.asgi import get_asgi_application +from labs.api import codemonkey_endpoints, github_endpoints # Set the DJANGO_SETTINGS_MODULE environment variable to point to your Django project's settings os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") @@ -15,14 +16,13 @@ # Create FastAPI app fastapi_app = FastAPI() -# Sample FastAPI route -@fastapi_app.get("/fastapi") -async def fastapi_root(): - return {"message": "Hello from FastAPI"} +# include codemonkey and github into fastapi +fastapi_app.include_router(codemonkey_endpoints.router) +fastapi_app.include_router(github_endpoints.router) # ASGI application to route to Django or FastAPI async def app(scope, receive, send): - if scope["type"] == "http" and scope["path"].startswith("/d"): + if scope["type"] == "http" and scope["path"].startswith("/django"): await django_app(scope, receive, send) else: await fastapi_app(scope, receive, send) diff --git a/config/settings.py b/config/settings.py index f574918..bcbeef8 100644 --- a/config/settings.py +++ b/config/settings.py @@ -16,10 +16,6 @@ # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent -# Explicitly load the .env.local file from the project root -dotenv_path = os.path.join(BASE_DIR, '.env.local') -load_dotenv(dotenv_path) - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ diff --git a/labs/celery.py b/labs/celery.py index fe02801..e1f6799 100644 --- a/labs/celery.py +++ b/labs/celery.py @@ -3,7 +3,7 @@ from kombu import Queue from redbeat import RedBeatSchedulerEntry, schedulers import redis -from labs.config import settings +from config import configuration_variables as settings import logging diff --git a/labs/database/connect.py b/labs/database/connect.py index ddfdca3..e805c7c 100644 --- a/labs/database/connect.py +++ b/labs/database/connect.py @@ -1,4 +1,4 @@ -from labs.config import settings +from config import configuration_variables as settings from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, declarative_base import logging diff --git a/labs/database/vectorize.py b/labs/database/vectorize.py index 2751e51..e3c4e85 100644 --- a/labs/database/vectorize.py +++ b/labs/database/vectorize.py @@ -8,7 +8,7 @@ import logging -from labs.config import settings +from config import configuration_variables as settings from labs.database.embeddings import reembed_code diff --git a/labs/github/github.py b/labs/github/github.py index c82ace0..ffb91e1 100644 --- a/labs/github/github.py +++ b/labs/github/github.py @@ -1,7 +1,7 @@ import base64 import requests from dataclasses import dataclass -from labs.config import settings +from config import configuration_variables as settings import git import os import logging diff --git a/labs/litellm_service/request.py b/labs/litellm_service/request.py index b12c040..0b5c9ef 100644 --- a/labs/litellm_service/request.py +++ b/labs/litellm_service/request.py @@ -1,7 +1,7 @@ from litellm import completion import requests from pydantic import BaseModel -from labs.config import settings +from config import configuration_variables as settings class Step(BaseModel): diff --git a/labs/llm.py b/labs/llm.py index 8aa333c..87bc7ac 100644 --- a/labs/llm.py +++ b/labs/llm.py @@ -1,6 +1,6 @@ from labs.decorators import time_and_log_function import logging -from labs.config import settings +from config import configuration_variables as settings from labs.litellm_service.request import RequestLiteLLM from labs.database.embeddings import find_similar_embeddings from labs.database.vectorize import vectorize_to_database diff --git a/labs/run.py b/labs/run.py index 1a3dd02..fb70d28 100644 --- a/labs/run.py +++ b/labs/run.py @@ -2,7 +2,7 @@ from labs.decorators import time_and_log_function from labs.llm import call_llm_with_context -from labs.config import settings +from config import configuration_variables as settings from labs.repo import ( commit_changes, create_branch, diff --git a/labs/tasks/llm.py b/labs/tasks/llm.py index 59994d0..ca6dcfe 100644 --- a/labs/tasks/llm.py +++ b/labs/tasks/llm.py @@ -1,5 +1,5 @@ import redis -from labs.config import settings +from config import configuration_variables as settings import logging import json diff --git a/labs/tasks/repo.py b/labs/tasks/repo.py index 5961ee8..4a7d825 100644 --- a/labs/tasks/repo.py +++ b/labs/tasks/repo.py @@ -1,5 +1,5 @@ import redis -from labs.config import settings +from config import configuration_variables as settings import logging import json from labs.celery import app diff --git a/labs/tasks/run.py b/labs/tasks/run.py index 2335967..661ea5b 100644 --- a/labs/tasks/run.py +++ b/labs/tasks/run.py @@ -12,7 +12,7 @@ prepare_prompt_and_context_task, vectorize_repo_to_database_task, ) -from labs.config import settings +from config import configuration_variables as settings import logging from labs.celery import app From 4e4370af9c683be46df4c2be3dc79323fdaa271e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Mon, 21 Oct 2024 17:49:46 +0100 Subject: [PATCH 03/11] Updates django admin paths --- asgi_app.py | 2 +- config/urls.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/asgi_app.py b/asgi_app.py index 0dbd4fb..37ebeda 100644 --- a/asgi_app.py +++ b/asgi_app.py @@ -22,7 +22,7 @@ # ASGI application to route to Django or FastAPI async def app(scope, receive, send): - if scope["type"] == "http" and scope["path"].startswith("/django"): + if scope["type"] == "http" and scope["path"].startswith("/admin"): await django_app(scope, receive, send) else: await fastapi_app(scope, receive, send) diff --git a/config/urls.py b/config/urls.py index 62fa85f..0db52d5 100644 --- a/config/urls.py +++ b/config/urls.py @@ -18,5 +18,5 @@ from django.urls import path urlpatterns = [ - path("django/admin/", admin.site.urls), + path("admin/", admin.site.urls), ] From 9f809708efd42e37cc3a9274b6e91e9ba5140ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Tue, 22 Oct 2024 12:36:49 +0100 Subject: [PATCH 04/11] Extracts config to file and adds fixtures --- config/fixtures/config.json | 38 ++++++++++++++++++++++++++ config/models/__init__.py | 1 + config/{models.py => models/config.py} | 0 3 files changed, 39 insertions(+) create mode 100644 config/fixtures/config.json create mode 100644 config/models/__init__.py rename config/{models.py => models/config.py} (100%) diff --git a/config/fixtures/config.json b/config/fixtures/config.json new file mode 100644 index 0000000..723e545 --- /dev/null +++ b/config/fixtures/config.json @@ -0,0 +1,38 @@ +[ + { + "model": "config.config", + "pk": 1, + "fields": { + "llm_model": "gpt-3.5-turbo", + "config_key": "default_model", + "config_value": "true", + "config_type": "boolean", + "created_at": "2024-10-20T12:00:00Z", + "updated_at": "2024-10-20T12:00:00Z" + } + }, + { + "model": "config.config", + "pk": 2, + "fields": { + "llm_model": "gpt-4", + "config_key": "api_key", + "config_value": "your_api_key_here", + "config_type": "string", + "created_at": "2024-10-20T12:05:00Z", + "updated_at": "2024-10-20T12:05:00Z" + } + }, + { + "model": "config.config", + "pk": 3, + "fields": { + "llm_model": null, + "config_key": "max_tokens", + "config_value": "150", + "config_type": "integer", + "created_at": "2024-10-20T12:10:00Z", + "updated_at": "2024-10-20T12:10:00Z" + } + } +] diff --git a/config/models/__init__.py b/config/models/__init__.py new file mode 100644 index 0000000..cca5d9b --- /dev/null +++ b/config/models/__init__.py @@ -0,0 +1 @@ +from .config import Config diff --git a/config/models.py b/config/models/config.py similarity index 100% rename from config/models.py rename to config/models/config.py From c7398bb9abc8b3261267f28d5f92d175847a749d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Tue, 22 Oct 2024 16:20:13 +0100 Subject: [PATCH 05/11] Adds makefile commands, fixtures and fixes extra space --- Makefile | 8 ++++- config/fixtures/config.json | 58 ++++++++++++++++++++------------- labs/celery.py | 2 +- labs/database/vectorize.py | 2 +- labs/github/github.py | 2 +- labs/litellm_service/request.py | 2 +- labs/llm.py | 2 +- labs/run.py | 2 +- labs/tasks/llm.py | 2 +- labs/tasks/repo.py | 2 +- labs/tasks/run.py | 2 +- 11 files changed, 51 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 356d3f0..cd78901 100644 --- a/Makefile +++ b/Makefile @@ -73,7 +73,13 @@ help: @python -c "${PRINT_HELP_PYSCRIPT}" < $(MAKEFILE_LIST) api: - fastapi dev labs/api/main.py + fastapi dev labs/api/main.py + +runserver: + poetry run python manage.py runserver asgi_api: poetry run uvicorn asgi_app:app --reload --port 8000 + +load_config: + python manage.py loaddata config.json diff --git a/config/fixtures/config.json b/config/fixtures/config.json index 723e545..0306254 100644 --- a/config/fixtures/config.json +++ b/config/fixtures/config.json @@ -4,35 +4,47 @@ "pk": 1, "fields": { "llm_model": "gpt-3.5-turbo", - "config_key": "default_model", - "config_value": "true", - "config_type": "boolean", + "config_key": "api_key", + "config_value": "your_api_key_here", + "config_type": "string", "created_at": "2024-10-20T12:00:00Z", "updated_at": "2024-10-20T12:00:00Z" } }, { - "model": "config.config", - "pk": 2, - "fields": { - "llm_model": "gpt-4", - "config_key": "api_key", - "config_value": "your_api_key_here", - "config_type": "string", - "created_at": "2024-10-20T12:05:00Z", - "updated_at": "2024-10-20T12:05:00Z" - } + "model": "config.config", + "pk": 2, + "fields": { + "llm_model": "gpt-3.5-turbo", + "config_key": "endpoint", + "config_value": "model_endpoint_here", + "config_type": "string", + "created_at": "2024-10-20T12:00:00Z", + "updated_at": "2024-10-20T12:00:00Z" + } }, { - "model": "config.config", - "pk": 3, - "fields": { - "llm_model": null, - "config_key": "max_tokens", - "config_value": "150", - "config_type": "integer", - "created_at": "2024-10-20T12:10:00Z", - "updated_at": "2024-10-20T12:10:00Z" - } + "model": "config.config", + "pk": 3, + "fields": { + "llm_model": "gpt-3.5-turbo", + "config_key": "prompt", + "config_value": "prompt goes here", + "config_type": "string", + "created_at": "2024-10-20T12:00:00Z", + "updated_at": "2024-10-20T12:00:00Z" + } + }, + { + "model": "config.config", + "pk": 4, + "fields": { + "llm_model": "gpt-3.5-turbo", + "config_key": "response_format", + "config_value": "response_format goes here", + "config_type": "string", + "created_at": "2024-10-20T12:00:00Z", + "updated_at": "2024-10-20T12:00:00Z" + } } ] diff --git a/labs/celery.py b/labs/celery.py index e1f6799..67f61c8 100644 --- a/labs/celery.py +++ b/labs/celery.py @@ -3,7 +3,7 @@ from kombu import Queue from redbeat import RedBeatSchedulerEntry, schedulers import redis -from config import configuration_variables as settings +from config import configuration_variables as settings import logging diff --git a/labs/database/vectorize.py b/labs/database/vectorize.py index e3c4e85..29a9d96 100644 --- a/labs/database/vectorize.py +++ b/labs/database/vectorize.py @@ -8,7 +8,7 @@ import logging -from config import configuration_variables as settings +from config import configuration_variables as settings from labs.database.embeddings import reembed_code diff --git a/labs/github/github.py b/labs/github/github.py index ffb91e1..7f1b38b 100644 --- a/labs/github/github.py +++ b/labs/github/github.py @@ -1,7 +1,7 @@ import base64 import requests from dataclasses import dataclass -from config import configuration_variables as settings +from config import configuration_variables as settings import git import os import logging diff --git a/labs/litellm_service/request.py b/labs/litellm_service/request.py index 0b5c9ef..b1bac78 100644 --- a/labs/litellm_service/request.py +++ b/labs/litellm_service/request.py @@ -1,7 +1,7 @@ from litellm import completion import requests from pydantic import BaseModel -from config import configuration_variables as settings +from config import configuration_variables as settings class Step(BaseModel): diff --git a/labs/llm.py b/labs/llm.py index 87bc7ac..ebc9748 100644 --- a/labs/llm.py +++ b/labs/llm.py @@ -1,6 +1,6 @@ from labs.decorators import time_and_log_function import logging -from config import configuration_variables as settings +from config import configuration_variables as settings from labs.litellm_service.request import RequestLiteLLM from labs.database.embeddings import find_similar_embeddings from labs.database.vectorize import vectorize_to_database diff --git a/labs/run.py b/labs/run.py index fb70d28..d101e77 100644 --- a/labs/run.py +++ b/labs/run.py @@ -2,7 +2,7 @@ from labs.decorators import time_and_log_function from labs.llm import call_llm_with_context -from config import configuration_variables as settings +from config import configuration_variables as settings from labs.repo import ( commit_changes, create_branch, diff --git a/labs/tasks/llm.py b/labs/tasks/llm.py index ca6dcfe..7498cce 100644 --- a/labs/tasks/llm.py +++ b/labs/tasks/llm.py @@ -1,5 +1,5 @@ import redis -from config import configuration_variables as settings +from config import configuration_variables as settings import logging import json diff --git a/labs/tasks/repo.py b/labs/tasks/repo.py index 4a7d825..615fc16 100644 --- a/labs/tasks/repo.py +++ b/labs/tasks/repo.py @@ -1,5 +1,5 @@ import redis -from config import configuration_variables as settings +from config import configuration_variables as settings import logging import json from labs.celery import app diff --git a/labs/tasks/run.py b/labs/tasks/run.py index 661ea5b..82b19dd 100644 --- a/labs/tasks/run.py +++ b/labs/tasks/run.py @@ -12,7 +12,7 @@ prepare_prompt_and_context_task, vectorize_repo_to_database_task, ) -from config import configuration_variables as settings +from config import configuration_variables as settings import logging from labs.celery import app From 33e7f7c37ebca9f96efab32c440dbda55f3ec1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Tue, 22 Oct 2024 16:44:34 +0100 Subject: [PATCH 06/11] Fixes merge reversion --- labs/litellm_service/local.py | 2 +- tests/conftest.py | 2 +- tests/database/conftest.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/labs/litellm_service/local.py b/labs/litellm_service/local.py index 5e60e4d..e7764b0 100644 --- a/labs/litellm_service/local.py +++ b/labs/litellm_service/local.py @@ -1,6 +1,6 @@ from ollama import Client -from labs.config import settings +from config import configuration_variables as settings class RequestLocalLLM: diff --git a/tests/conftest.py b/tests/conftest.py index bc7da3e..5dd479f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ import random import pytest -from labs.config import settings +from config import configuration_variables as settings from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, declarative_base diff --git a/tests/database/conftest.py b/tests/database/conftest.py index ad367d4..65a54f0 100644 --- a/tests/database/conftest.py +++ b/tests/database/conftest.py @@ -1,6 +1,6 @@ import random import pytest -from labs.config import settings +from config import configuration_variables as settings from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, declarative_base From 2135a782c10190c1d459ffef4c05535befc46767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Tue, 22 Oct 2024 16:50:35 +0100 Subject: [PATCH 07/11] Fixes warnings --- config/models/__init__.py | 2 +- config/settings.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config/models/__init__.py b/config/models/__init__.py index cca5d9b..887253a 100644 --- a/config/models/__init__.py +++ b/config/models/__init__.py @@ -1 +1 @@ -from .config import Config +from .config import Config as Config diff --git a/config/settings.py b/config/settings.py index bcbeef8..1b0da64 100644 --- a/config/settings.py +++ b/config/settings.py @@ -11,7 +11,6 @@ """ import os from pathlib import Path -from dotenv import load_dotenv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent From 56075bd1c9915e6d0f46a5b9efb12d5914b862ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Wed, 23 Oct 2024 17:51:49 +0100 Subject: [PATCH 08/11] Addresses PR comments --- .env.sample | 4 ++- Makefile | 4 +-- config/admin.py | 4 +-- config/fixtures/config.json | 50 ------------------------------- config/migrations/0001_initial.py | 8 ++--- config/models/config.py | 10 +++---- config/settings.py | 14 ++++----- 7 files changed, 23 insertions(+), 71 deletions(-) delete mode 100644 config/fixtures/config.json diff --git a/.env.sample b/.env.sample index 2ab98e8..903b41e 100644 --- a/.env.sample +++ b/.env.sample @@ -1,4 +1,6 @@ TEST_ENVIRONMENT=False +DJANGO_DEBUG=True +DJANGO_ALLOWED_HOSTS=localhost LITELLM_MASTER_KEY= LITELLM_API_KEY= @@ -38,4 +40,4 @@ REDIS_HOST=redis REDIS_PORT=6379 LOCAL_LLM=False -LOCAL_LLM_HOST=http://localhost:11434 \ No newline at end of file +LOCAL_LLM_HOST=http://localhost:11434 diff --git a/Makefile b/Makefile index f6bfaed..e17da72 100644 --- a/Makefile +++ b/Makefile @@ -89,5 +89,5 @@ runserver: asgi_api: poetry run uvicorn asgi_app:app --reload --port 8000 -load_config: - python manage.py loaddata config.json +load_fixtures: + python manage.py loaddata $(wildcard config/fixtures/*.json) diff --git a/config/admin.py b/config/admin.py index 90a9055..e2cbd44 100644 --- a/config/admin.py +++ b/config/admin.py @@ -3,5 +3,5 @@ @admin.register(Config) class ConfigAdmin(admin.ModelAdmin): - list_display = ('llm_model', 'config_key', 'config_value', 'config_type', 'created_at', 'updated_at') - search_fields = (['config_key', 'llm_model']) + list_display = ('llm_model', 'key', 'value', 'type', 'created_at', 'updated_at') + search_fields = (['key', 'llm_model']) diff --git a/config/fixtures/config.json b/config/fixtures/config.json deleted file mode 100644 index 0306254..0000000 --- a/config/fixtures/config.json +++ /dev/null @@ -1,50 +0,0 @@ -[ - { - "model": "config.config", - "pk": 1, - "fields": { - "llm_model": "gpt-3.5-turbo", - "config_key": "api_key", - "config_value": "your_api_key_here", - "config_type": "string", - "created_at": "2024-10-20T12:00:00Z", - "updated_at": "2024-10-20T12:00:00Z" - } - }, - { - "model": "config.config", - "pk": 2, - "fields": { - "llm_model": "gpt-3.5-turbo", - "config_key": "endpoint", - "config_value": "model_endpoint_here", - "config_type": "string", - "created_at": "2024-10-20T12:00:00Z", - "updated_at": "2024-10-20T12:00:00Z" - } - }, - { - "model": "config.config", - "pk": 3, - "fields": { - "llm_model": "gpt-3.5-turbo", - "config_key": "prompt", - "config_value": "prompt goes here", - "config_type": "string", - "created_at": "2024-10-20T12:00:00Z", - "updated_at": "2024-10-20T12:00:00Z" - } - }, - { - "model": "config.config", - "pk": 4, - "fields": { - "llm_model": "gpt-3.5-turbo", - "config_key": "response_format", - "config_value": "response_format goes here", - "config_type": "string", - "created_at": "2024-10-20T12:00:00Z", - "updated_at": "2024-10-20T12:00:00Z" - } - } -] diff --git a/config/migrations/0001_initial.py b/config/migrations/0001_initial.py index 415801f..58ea254 100644 --- a/config/migrations/0001_initial.py +++ b/config/migrations/0001_initial.py @@ -24,16 +24,16 @@ class Migration(migrations.Migration): ), ), ("llm_model", models.TextField(blank=True, null=True)), - ("config_key", models.TextField(unique=True)), - ("config_value", models.TextField(blank=True, null=True)), - ("config_type", models.TextField(blank=True, null=True)), + ("key", models.TextField(unique=True)), + ("value", models.TextField(blank=True, null=True)), + ("type", models.TextField(blank=True, null=True)), ("created_at", models.DateTimeField(default=django.utils.timezone.now)), ("updated_at", models.DateTimeField(auto_now=True)), ], options={ "indexes": [ models.Index( - fields=["config_key", "llm_model"], + fields=["key", "llm_model"], name="config_conf_config__4d9363_idx", ) ], diff --git a/config/models/config.py b/config/models/config.py index be952ce..0e6f824 100644 --- a/config/models/config.py +++ b/config/models/config.py @@ -3,16 +3,16 @@ class Config(models.Model): llm_model = models.TextField(blank=True, null=True) - config_key = models.TextField(unique=True) - config_value = models.TextField(blank=True, null=True) - config_type = models.TextField(blank=True, null=True) + key = models.TextField(unique=True) + value = models.TextField(blank=True, null=True) + type = models.TextField(blank=True, null=True) created_at = models.DateTimeField(default=timezone.now) updated_at = models.DateTimeField(auto_now=True) def __str__(self): - return f"{self.config_key}: {self.config_value}" + return f"{self.key}: {self.value}" class Meta: indexes = [ - models.Index(fields=['config_key', 'llm_model']) + models.Index(fields=['key', 'llm_model']) ] diff --git a/config/settings.py b/config/settings.py index 1b0da64..cc09de7 100644 --- a/config/settings.py +++ b/config/settings.py @@ -22,9 +22,9 @@ SECRET_KEY = "django-insecure-hxak7+phh51^p%vuxxk5%28b4tz^%e1m=6@q*tmf1eq-0$32_3" # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = os.environ.get('DJANGO_DEBUG', "True") == "True" -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = [s.strip() for s in os.environ.get("DJANGO_ALLOWED_HOSTS", []).split(",")] # Application definition @@ -76,11 +76,11 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", - "NAME": os.environ.get("DATABASE_NAME"), - "USER": os.environ.get("DATABASE_USER"), - "PASSWORD": os.environ.get("DATABASE_PASS"), - "HOST": os.environ.get("DATABASE_HOST"), - "PORT": os.environ.get("DATABASE_PORT"), + "NAME": os.environ.get("DATABASE_NAME", "postgres"), + "USER": os.environ.get("DATABASE_USER", "postgres"), + "PASSWORD": os.environ.get("DATABASE_PASS", "postgres"), + "HOST": os.environ.get("DATABASE_HOST", "localhost"), + "PORT": os.environ.get("DATABASE_PORT", "5432"), } } From fa7157dcf2574dbf873d4f81d86c1f48b1f1a31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Thu, 24 Oct 2024 11:05:09 +0100 Subject: [PATCH 09/11] Adds django secret key env variable --- .env.sample | 1 + config/settings.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index 903b41e..c67827f 100644 --- a/.env.sample +++ b/.env.sample @@ -1,6 +1,7 @@ TEST_ENVIRONMENT=False DJANGO_DEBUG=True DJANGO_ALLOWED_HOSTS=localhost +DJANGO_SECRET_KEY= LITELLM_MASTER_KEY= LITELLM_API_KEY= diff --git a/config/settings.py b/config/settings.py index cc09de7..c024b3f 100644 --- a/config/settings.py +++ b/config/settings.py @@ -19,7 +19,7 @@ # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-hxak7+phh51^p%vuxxk5%28b4tz^%e1m=6@q*tmf1eq-0$32_3" +SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', '') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.environ.get('DJANGO_DEBUG', "True") == "True" From bc661b7c8462c5da6178b66346a33215d75e3f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Thu, 24 Oct 2024 14:29:43 +0100 Subject: [PATCH 10/11] Fixes poetry lock file --- poetry.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 7f1dd27..22340a6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -5463,4 +5463,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.11.7" -content-hash = "0dd08082e758631b63a02067838034d1dde1fcc5645eb834d3bedce715f27b3f" +content-hash = "631613defed221cf7ed749dcacc992624ff8c569a6401f2d206cd625fb00846f" From cf2273c55d251653a21fa8f57c05d81a870e6a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Borrego?= Date: Thu, 24 Oct 2024 14:37:50 +0100 Subject: [PATCH 11/11] Fixes merged imports for settings --- labs/database/vectorize/chunk_vectorizer.py | 2 +- labs/database/vectorize/python_vectorizer.py | 2 +- notebooks/embeddings.ipynb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/labs/database/vectorize/chunk_vectorizer.py b/labs/database/vectorize/chunk_vectorizer.py index 65e18f4..36540bf 100644 --- a/labs/database/vectorize/chunk_vectorizer.py +++ b/labs/database/vectorize/chunk_vectorizer.py @@ -9,7 +9,7 @@ import logging -from labs.config import settings +from config import configuration_variables as settings from labs.database.embeddings import reembed_code diff --git a/labs/database/vectorize/python_vectorizer.py b/labs/database/vectorize/python_vectorizer.py index c3b7079..b134542 100644 --- a/labs/database/vectorize/python_vectorizer.py +++ b/labs/database/vectorize/python_vectorizer.py @@ -9,7 +9,7 @@ import logging -from labs.config import settings +from config import configuration_variables as settings from labs.database.embeddings import reembed_code from labs.parsers.python import get_lines_code, parse_python_file diff --git a/notebooks/embeddings.ipynb b/notebooks/embeddings.ipynb index beec85e..941aa0f 100644 --- a/notebooks/embeddings.ipynb +++ b/notebooks/embeddings.ipynb @@ -48,7 +48,7 @@ "outputs": [], "source": [ "from importlib import reload\n", - "from labs.config import settings\n", + "from config import configuration_variables as settings\n", "\n", "reload(settings)\n", "\n",