Skip to content

DST-252: set up code for accordion implementation #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions 05-assistive-chatbot/.chainlit/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ github = "https://github.com/navapbc/labs-gen-ai-experiments/tree/main/05-assist

# 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.
# custom_css = "/public/test.css"

custom_css = "https://cdnjs.cloudflare.com/ajax/libs/uswds/3.8.1/css/uswds.min.css"
# Specify a Javascript file that can be used to customize the user interface.
# The Javascript file can be served from the public directory.
# custom_js = "/public/test.js"
custom_js = "https://cdnjs.cloudflare.com/ajax/libs/uswds/3.8.1/js/uswds.min.js"

# Specify a custom font url.
# custom_font = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
Expand Down
24 changes: 13 additions & 11 deletions 05-assistive-chatbot/chatbot-chainlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ async def init_chat():
}

await cl.Message(
metadata=metadata,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed due to unexpected key error

disable_feedback=True,
content=f"Welcome to the Assistive Chat prototype (built {build_date})",
content=f"Welcome to the Assistive Chat prototype (built {build_date}, {metadata})",
).send()

available_llms = llms.available_llms()
Expand Down Expand Up @@ -128,7 +127,7 @@ async def apply_settings():

error = chatbot.validate_settings(settings)
if error:
await cl.Message(author="backend", metadata=settings, content=f"! Validation error: {error}").send()
await cl.Message(author="backend", content=f"! Validation error: {error}").send()
else:
cl.user_session.set("settings_applied", True)
return settings
Expand Down Expand Up @@ -208,23 +207,26 @@ def convert_to_message_args(response_obj: str | dict):
def format_v2_results_as_markdown(gen_results, response_msg):
resp = ["", f"## Q: {gen_results.question}"]

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

cards_resp = []
for i, card in enumerate(gen_results.cards, 1):
if card.summary:
cards_resp += [
f"<details><summary>{i}. <a href='https://link/to/guru_card'>{card.card_title}</a></summary>",
"",
f" Summary: {card.summary}",
"",
f"""<div class="usa-accordion" id=accordion-{i}>
<h4 class="usa-accordion__heading">
<button
type="button"
class="usa-accordion__button"
aria-expanded="false"
aria-controls="a-{i}"
><a href='https://link/to/guru_card'>{card.card_title}</a></button></h4>
<div id="a-{i}" class="usa-accordion__content usa-prose" hidden><p>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>", ""]
cards_resp += ["</p></div></div>", ""]

response_msg.content = "\n".join(resp + dq_resp + cards_resp)
response_msg.elements = [
Expand Down
5 changes: 2 additions & 3 deletions 05-assistive-chatbot/chatbot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import socket
from functools import cached_property
from io import StringIO
from typing import Dict

import dotenv
from fastapi import Body, FastAPI, Request, status
Expand Down Expand Up @@ -47,8 +46,8 @@ def chat_engine(self):

# This function cannot be async because it uses a single non-thread-safe app_state
@app.post("/query")
def query(message: str | Dict):
response = app_state.chat_engine().gen_response(message)
def query(message: str):
Copy link
Contributor Author

@ccheng26 ccheng26 Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed Dict type, causes error in populate_summaries in ll 196, key errors for gen_results.question

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed the underlying error? I'm a bit surprised, since I didn't think type annotations could affect runtime!

response = app_state.chat_engine.gen_response(message)
return response


Expand Down