From 1a9e4b4a299eca96edaac3771515e5b9fb20036d Mon Sep 17 00:00:00 2001 From: C Cheng Date: Fri, 14 Jun 2024 11:43:33 -0400 Subject: [PATCH 1/2] set up code for accordion implementation --- 05-assistive-chatbot/chatbot-chainlit.py | 25 +++++++++++++----------- 05-assistive-chatbot/chatbot_api.py | 5 ++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/05-assistive-chatbot/chatbot-chainlit.py b/05-assistive-chatbot/chatbot-chainlit.py index 4cb0236..64abf93 100755 --- a/05-assistive-chatbot/chatbot-chainlit.py +++ b/05-assistive-chatbot/chatbot-chainlit.py @@ -44,9 +44,9 @@ async def init_chat(): } await cl.Message( - metadata=metadata, + # metadata=metadata, 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() @@ -128,7 +128,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 @@ -208,23 +208,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 = ["
Derived Questions", ""] + dq_resp = ["Derived Questions", ""] for dq in gen_results.derived_questions: dq_resp.append(f"- {dq.derived_question}") - dq_resp += ["
", ""] - cards_resp = [] for i, card in enumerate(gen_results.cards, 1): if card.summary: cards_resp += [ - f"
{i}. {card.card_title}", - "", - f" Summary: {card.summary}", - "", + f"""
+

+

+
", ""] + cards_resp += ["

", ""] response_msg.content = "\n".join(resp + dq_resp + cards_resp) response_msg.elements = [ diff --git a/05-assistive-chatbot/chatbot_api.py b/05-assistive-chatbot/chatbot_api.py index 31e7c92..1105815 100755 --- a/05-assistive-chatbot/chatbot_api.py +++ b/05-assistive-chatbot/chatbot_api.py @@ -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 @@ -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): + response = app_state.chat_engine.gen_response(message) return response From 56c74ac17f42acc64edbd70f75fac971f49b599d Mon Sep 17 00:00:00 2001 From: C Cheng Date: Fri, 14 Jun 2024 12:04:41 -0400 Subject: [PATCH 2/2] add scripts --- 05-assistive-chatbot/.chainlit/config.toml | 5 ++--- 05-assistive-chatbot/chatbot-chainlit.py | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/05-assistive-chatbot/.chainlit/config.toml b/05-assistive-chatbot/.chainlit/config.toml index dbeba28..0ecfb35 100644 --- a/05-assistive-chatbot/.chainlit/config.toml +++ b/05-assistive-chatbot/.chainlit/config.toml @@ -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" diff --git a/05-assistive-chatbot/chatbot-chainlit.py b/05-assistive-chatbot/chatbot-chainlit.py index 64abf93..b21adce 100755 --- a/05-assistive-chatbot/chatbot-chainlit.py +++ b/05-assistive-chatbot/chatbot-chainlit.py @@ -44,7 +44,6 @@ async def init_chat(): } await cl.Message( - # metadata=metadata, disable_feedback=True, content=f"Welcome to the Assistive Chat prototype (built {build_date}, {metadata})", ).send()