Skip to content

Commit

Permalink
Simplify dev server startup to enable reloading, fix a bug, add some …
Browse files Browse the repository at this point in the history
…default env settings
  • Loading branch information
mbertrand committed Dec 20, 2024
1 parent a7cb6ad commit b3e8ea7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ai_agents/agents_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ def test_get_completion(settings, mocker, debug, search_results):
"system_prompt": RecommendationAgent.INSTRUCTIONS,
}
}
comment_metadata = f"\n\n<!-- {json.dumps(metadata)} -->\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)),
Expand Down
2 changes: 1 addition & 1 deletion ai_agents/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions env/backend.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion scripts/run-django-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b3e8ea7

Please sign in to comment.