From b3e8ea7f74b25fae94df3f9f3742927594206b92 Mon Sep 17 00:00:00 2001 From: Matt Bertrand Date: Fri, 20 Dec 2024 10:10:07 -0500 Subject: [PATCH] Simplify dev server startup to enable reloading, fix a bug, add some default env settings --- ai_agents/agents_test.py | 3 +++ ai_agents/consumers.py | 2 +- env/backend.env | 2 ++ scripts/run-django-dev.sh | 5 ++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ai_agents/agents_test.py b/ai_agents/agents_test.py index 7c2882d..308df7d 100644 --- a/ai_agents/agents_test.py +++ b/ai_agents/agents_test.py @@ -122,7 +122,10 @@ def test_get_completion(settings, mocker, debug, search_results): "system_prompt": RecommendationAgent.INSTRUCTIONS, } } + comment_metadata = f"\n\n\n\n".encode() expected_return_value = [b"Here ", b"are ", b"some ", b"results"] + if debug: + expected_return_value.append(comment_metadata) mocker.patch( "ai_agents.agents.OpenAIAgent.stream_chat", return_value=mocker.Mock(response_gen=iter(expected_return_value)), diff --git a/ai_agents/consumers.py b/ai_agents/consumers.py index 8d9f2f8..d2b1f27 100644 --- a/ai_agents/consumers.py +++ b/ai_agents/consumers.py @@ -117,7 +117,7 @@ async def handle(self, message: str): # Headers are only sent after the first body event. # Set "more_body" to tell the interface server to not # finish the response yet: - payload = "\nevent: ping", "data: null\n\n\n" + payload = "\nevent: ping\ndata: null\n\n\n" await self.send_body(payload.encode("utf-8"), more_body=True) try: diff --git a/env/backend.env b/env/backend.env index 86e077e..72e2118 100644 --- a/env/backend.env +++ b/env/backend.env @@ -21,5 +21,7 @@ DATABASE_URL=postgres://postgres:postgres@db:5433/postgres MITOL_DB_DISABLE_SSL=True MITOL_FEATURES_DEFAULT=True MITOL_SECURE_SSL_REDIRECT=False +MAILGUN_SENDER_DOMAIN=fake-sender +MAILGUN_KEY=faker-key PORT=8002 diff --git a/scripts/run-django-dev.sh b/scripts/run-django-dev.sh index bcd1d70..f5f20c5 100755 --- a/scripts/run-django-dev.sh +++ b/scripts/run-django-dev.sh @@ -13,4 +13,7 @@ python3 manage.py createcachetable # run ONLY data migrations RUN_DATA_MIGRATIONS=true python3 manage.py migrate --noinput -gunicorn main.asgi:application -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8001 --workers 4 --threads 2 +uvicorn main.asgi:application --reload --host 0.0.0.0 --port 8001 + +# production might best be run via a combo of gunicorn and uvicorn? +#gunicorn main.asgi:application -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8001 --workers 4 --threads 2