From 44a69e06fb1a6dbf7d1a0aaa3bde917d534275f8 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Mon, 11 Sep 2023 12:46:36 -0400 Subject: [PATCH] Fly Deployment --- .dockerignore | 1 + Dockerfile | 34 +++++++++++++++++++++ chain.py | 81 ++++++++++++++++++++++++++------------------------- fly.toml | 26 +++++++++++++++++ 4 files changed, 103 insertions(+), 39 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..0501d092 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +fly.toml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..30e3275c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# https://pythonspeed.com/articles/base-image-python-docker-images/ +# https://testdriven.io/blog/docker-best-practices/ +FROM python:3.10-slim-bullseye + +WORKDIR /app + +# https://stackoverflow.com/questions/53835198/integrating-python-poetry-with-docker +ENV PYTHONFAULTHANDLER=1 \ + PYTHONUNBUFFERED=1 \ + PYTHONHASHSEED=random \ + PIP_NO_CACHE_DIR=off \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + PIP_DEFAULT_TIMEOUT=100 \ + POETRY_VERSION=1.4.1 + +RUN pip install "poetry==$POETRY_VERSION" + +# Copy only requirements to cache them in docker layer +WORKDIR /app +COPY poetry.lock pyproject.toml /app/ + +# Project initialization: +RUN poetry config virtualenvs.create false \ + && poetry install --no-root --no-interaction --no-ansi --without dev + +WORKDIR /app + +RUN addgroup --system app && adduser --system --group app +USER app + +COPY . . + +# https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker +CMD ["python", "-m", "uvicorn", "main:app", "--port", "80"] diff --git a/chain.py b/chain.py index 2934489b..728c9e05 100644 --- a/chain.py +++ b/chain.py @@ -248,57 +248,60 @@ class BloomChain: @classmethod async def stream(cls, cache: Conversation, inp: str ): # VoE has to happen first. If there's user prediction history, derive and store fact(s) - if cache.messages('user_prediction_thought_revision'): - user_prediction_thought_revision = cache.messages('user_prediction_thought_revision')[-1].content + try: + if cache.messages('user_prediction_thought_revision'): + user_prediction_thought_revision = cache.messages('user_prediction_thought_revision')[-1].content - voe_thought = await cls.think_violation_of_expectation(cache, inp, user_prediction_thought_revision) - voe_facts = await cls.violation_of_expectation(cache, inp, user_prediction_thought_revision, voe_thought) + voe_thought = await cls.think_violation_of_expectation(cache, inp, user_prediction_thought_revision) + voe_facts = await cls.violation_of_expectation(cache, inp, user_prediction_thought_revision, voe_thought) - if not voe_facts or voe_facts[0] == "None": - pass - else: - await cls.check_voe_list(cache, voe_facts) + if not voe_facts or voe_facts[0] == "None": + pass + else: + await cls.check_voe_list(cache, voe_facts) - print("=========================================") - print("Finished Init") - print("=========================================") + print("=========================================") + print("Finished Init") + print("=========================================") - thought_iterator = cls.think(cache, inp) - thought = "" - async for item in thought_iterator: - # escape ❀ if present - item = item.replace("❀", "🌸") - thought += item - yield item - yield "❀" + thought_iterator = cls.think(cache, inp) + thought = "" + async for item in thought_iterator: + # escape ❀ if present + item = item.replace("❀", "🌸") + thought += item + yield item + yield "❀" - print("=========================================") - print("Finished Thought") - print("=========================================") + print("=========================================") + print("Finished Thought") + print("=========================================") - thought_revision_iterator = cls.revise_thought(cache, inp, thought) - thought_revision = await thought_revision_iterator() + thought_revision_iterator = cls.revise_thought(cache, inp, thought) + thought_revision = await thought_revision_iterator() - response_iterator = cls.respond(cache, thought_revision, inp) - #response = "" + response_iterator = cls.respond(cache, thought_revision, inp) + #response = "" - async for item in response_iterator: - # if "❀" in item: - item = item.replace("❀", "🌸") - #response += item - yield item + async for item in response_iterator: + # if "❀" in item: + item = item.replace("❀", "🌸") + #response += item + yield item - print("=========================================") - print("Finished Response") - print("=========================================") + print("=========================================") + print("Finished Response") + print("=========================================") - user_prediction_thought = await cls.think_user_prediction(cache, inp) - user_prediction_thought_revision = await cls.revise_user_prediction_thought(cache, user_prediction_thought, inp) + user_prediction_thought = await cls.think_user_prediction(cache, inp) + user_prediction_thought_revision = await cls.revise_user_prediction_thought(cache, user_prediction_thought, inp) - print("=========================================") - print("Finished User Prediction") - print("=========================================") + print("=========================================") + print("Finished User Prediction") + print("=========================================") + finally: + yield "TERMINATED SEQUENCE" diff --git a/fly.toml b/fly.toml index e69de29b..3239dd6d 100644 --- a/fly.toml +++ b/fly.toml @@ -0,0 +1,26 @@ +# fly.toml app configuration file generated for honcho on 2023-09-11T10:58:33-04:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = "honcho" +primary_region = "bos" +kill_signal = "SIGINT" +kill_timeout = "5s" + +[experimental] + auto_rollback = true + +[processes] +api = "python -m uvicorn main:app --host 0.0.0.0 --port 8000" + +[http_service] + internal_port = 8000 + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ["api"] + [http_service.concurrency] + type = "requests" + soft_limit = 200 + hard_limit = 250