diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 448f70e..59bc5fc 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -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 diff --git a/02-household-queries/.chainlit/config.toml b/02-household-queries/.chainlit/config.toml index 021afa3..39c046d 100644 --- a/02-household-queries/.chainlit/config.toml +++ b/02-household-queries/.chainlit/config.toml @@ -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 = [] @@ -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 @@ -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. diff --git a/02-household-queries/.dockerignore b/02-household-queries/.dockerignore new file mode 100644 index 0000000..2aa0595 --- /dev/null +++ b/02-household-queries/.dockerignore @@ -0,0 +1,9 @@ +__pycache__ +chroma_db/ +*cache/ +*.log +log/ +compiled_module-*.json + +*.DS_STORE + diff --git a/02-household-queries/Dockerfile b/02-household-queries/Dockerfile index 09c3a1c..40dcd82 100644 --- a/02-household-queries/Dockerfile +++ b/02-household-queries/Dockerfile @@ -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 . diff --git a/02-household-queries/chainlit-summaries.py b/02-household-queries/chainlit-summaries.py index 921386c..ae2e483 100755 --- a/02-household-queries/chainlit-summaries.py +++ b/02-household-queries/chainlit-summaries.py @@ -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 @@ -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 = ["
Derived Questions", ""] for dq in gen_results.derived_questions: - resp.append(f"1. {dq.derived_question}") + dq_resp.append(f"- {dq.derived_question}") + dq_resp += ["
", ""] - 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"
{i}. {card.card_title}", + "", + 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 += ["
", ""] - 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") + ], + } diff --git a/02-household-queries/decompose_and_summarize.py b/02-household-queries/decompose_and_summarize.py index 3f84cf5..cebed95 100644 --- a/02-household-queries/decompose_and_summarize.py +++ b/02-household-queries/decompose_and_summarize.py @@ -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: @@ -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): @@ -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}")