Skip to content

Commit

Permalink
feat: Prep Dockerfile for AWS deployments (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomlam authored May 20, 2024
1 parent aa8563b commit 8bb18c3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ jobs:
if: inputs.build_image
run: |
cd ${{ inputs.dockerfile_folder }}
docker build -t "${{ inputs.image_name }}:${{ inputs.image_tag }}" .
echo "${{secrets.DOT_ENV_FILE_CONTENTS}}" > .env
docker build -t "${{ inputs.image_name }}:${{ inputs.image_tag }}" --build-arg GURU_CARDS_URL="https://docs.google.com/uc?export=download&id=${{ secrets.GURU_CARDS_URL_ID }}" .
- name: "Publish image to AWS ECR'"
if: inputs.build_image
Expand Down
13 changes: 6 additions & 7 deletions 02-household-queries/.chainlit/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[project]
# Whether to enable telemetry (default: true). No personal data is collected.
enable_telemetry = true

enable_telemetry = false

# List of environment variables to be provided by each user to use the app.
user_env = []
Expand All @@ -23,7 +22,7 @@ allow_origins = ["*"]
prompt_playground = true

# Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
unsafe_allow_html = false
unsafe_allow_html = true

# Process and display mathematical expressions. This can clash with "$" characters in messages.
latex = false
Expand All @@ -46,22 +45,22 @@ latex = false
name = "Household Chatbot"

# Show the readme while the thread is empty.
show_readme_as_default = true
show_readme_as_default = false

# Description of the app and chatbot. This is used for HTML tags.
# description = ""

# Large size content are by default collapsed for a cleaner ui
default_collapse_content = true
default_collapse_content = false

# The default value for the expand messages settings.
default_expand_messages = false
default_expand_messages = true

# Hide the chain of thought details from the user in the UI.
hide_cot = false

# Link to your github repo. This will add a github button in the UI's header.
# github = ""
github = "https://github.com/navapbc/labs-gen-ai-experiments/tree/main/02-household-queries"

# Specify a CSS file that can be used to customize the user interface.
# The CSS file can be served from the public directory or via an external link.
Expand Down
9 changes: 9 additions & 0 deletions 02-household-queries/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__pycache__
chroma_db/
*cache/
*.log
log/
compiled_module-*.json

*.DS_STORE

27 changes: 17 additions & 10 deletions 02-household-queries/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@ FROM python:3.11-slim

WORKDIR /app

# RUN apt-get update && apt-get install -y \
# build-essential \
# curl \
# software-properties-common \
# git \
# && rm -rf /var/lib/apt/lists/*

COPY . .
RUN pip3 install -r requirements.txt
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

# Associate GHCR package with GitHub repo; otherwise, it's associated with the navapbc GitHub organization
# See https://github.com/orgs/navapbc/packages?repo_name=labs-gen-ai-experiments
# LABEL org.opencontainers.image.source https://github.com/navapbc/labs-gen-ai-experiments

RUN apt-get update && apt-get install -y \
curl unzip \
&& rm -rf /var/lib/apt/lists/*

COPY . .
ARG GURU_CARDS_URL
RUN echo "Downloading from ${GURU_CARDS_URL}" \
&& curl -L "${GURU_CARDS_URL}" > download.zip \
&& unzip -o download.zip \
&& rm download.zip \
&& mv guru_cards_for_nava--Multi-benefit.json guru_cards_for_nava.json

RUN ./decompose-questions.py 0

EXPOSE 8000
HEALTHCHECK CMD curl http://localhost:8000 || exit 1
ENTRYPOINT ["chainlit", "run", "--port", "8000", "-h", "chainlit-household-bot.py"]
ENTRYPOINT ["chainlit", "run", "--port", "8000", "-h", "chainlit-summaries.py"]

# To test:
# docker build -t chainlit1 .
Expand Down
41 changes: 33 additions & 8 deletions 02-household-queries/chainlit-summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
@cl.on_chat_start
async def init_chat():
# settings = das.init()

# elements = [
# cl.Text(name="side-text", display="side", content="Side Text"),
# cl.Text(name="page-text", display="page", content="Page Text"),
# ]
# await cl.Message("hello side-text and page-text", elements=elements).send()

pass


Expand All @@ -25,19 +32,37 @@ async def message_submitted(message: cl.Message):
generated_results = on_question(message.content)
print(json.dumps(dataclasses.asdict(generated_results), indent=2))

await cl.Message(format_as_markdown(generated_results)).send()
message_args = format_as_markdown(generated_results)
# await cl.Message(**message_args).send()
await cl.Message(content=message_args["content"], elements=message_args["elements"]).send()
# await cl.Message(content= message_args["content"], elements=[cl.Text(content="SIDE", display="inline")]).send()


def format_as_markdown(gen_results):
resp = ["", f"## Q: {gen_results.question}", "### Derived Questions"]
resp = ["", f"## Q: {gen_results.question}"]

dq_resp = ["<details><summary>Derived Questions</summary>", ""]
for dq in gen_results.derived_questions:
resp.append(f"1. {dq.derived_question}")
dq_resp.append(f"- {dq.derived_question}")
dq_resp += ["</details>", ""]

resp.append("### Guru cards")
for card in gen_results.cards:
cards_resp = []
for i, card in enumerate(gen_results.cards, 1):
if card.summary:
resp += [f"#### {card.card_title}", f"Summary: {card.summary}", ""]
resp += [f"\n.\n> {q}" for q in card.quotes]
cards_resp += [
f"<details><summary>{i}. <a href='https://link/to/guru_card'>{card.card_title}</a></summary>",
"",
f" Summary: {card.summary}",
"",
]
indented_quotes = [q.strip().replace("\n", "\n ") for q in card.quotes]
cards_resp += [f"\n Quote:\n ```\n {q}\n ```" for q in indented_quotes]
cards_resp += ["</details>", ""]

return "\n".join(resp)
return {
"content": "\n".join(resp + dq_resp + cards_resp),
"elements": [
# cl.Text(name="Derived Questions", content="\n".join(dq_resp), display="side"),
# cl.Text(name="Guru Cards", content="\n".join(cards_resp), display="inline")
],
}
3 changes: 3 additions & 0 deletions 02-household-queries/decompose_and_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def collect_retrieved_cards(derived_qs, gen_results):
gen_results.cards = collate_by_card_score_sum(gen_results.derived_questions)


@debugging.timer
def collate_by_card_score_sum(derived_question_entries):
all_retrieved_cards = dict()
for dq_entry in derived_question_entries:
Expand Down Expand Up @@ -230,6 +231,7 @@ def retrieve_cards(derived_qs, vectordb, retrieve_k=5):
return results


@debugging.timer
def create_summaries(gen_results, summarizer, guru_card_texts):
print(f"Summarizing {len(gen_results.cards)} retrieved cards...")
for i, card_entry in enumerate(gen_results.cards):
Expand All @@ -246,6 +248,7 @@ def create_summaries(gen_results, summarizer, guru_card_texts):
card_entry.summary = prediction.answer


@debugging.timer
def format_response(gen_results):
resp = ["==="]
resp.append("Q: {gen_results.question}")
Expand Down

0 comments on commit 8bb18c3

Please sign in to comment.