From 35b9ab6dd74e398bc9ba665f69f8027739d0ce1d Mon Sep 17 00:00:00 2001 From: tmanik Date: Fri, 10 Jul 2026 15:38:28 -0400 Subject: [PATCH] chore: remove legacy chat clients, move status script to scripts/ - Delete chat_frontend.py (legacy Streamlit UI, superseded by frontend/) - Delete chat_test.py (CLI smoke-test client) - Move check_processing_status.sh to scripts/ alongside run_sync.sh - Drop now-unused streamlit from requirements.txt - Update README references --- README.md | 6 +- chat_frontend.py | 187 ------------------ chat_test.py | 80 -------- requirements.txt | 1 - .../check_processing_status.sh | 0 5 files changed, 2 insertions(+), 272 deletions(-) delete mode 100644 chat_frontend.py delete mode 100644 chat_test.py rename check_processing_status.sh => scripts/check_processing_status.sh (100%) diff --git a/README.md b/README.md index ff1f0c5..1d23597 100644 --- a/README.md +++ b/README.md @@ -157,16 +157,14 @@ python run_step_function.py --reset-cache # forget previously-processed files ### Check ingestion progress ```bash -./check_processing_status.sh +./scripts/check_processing_status.sh ``` Reports files in DynamoDB, recently processed files, files in S3, and the remaining backlog. ### Test the chatbot -- **Production frontend** — the CloudFront or custom-domain URL. -- **CLI** — `python chat_test.py` -- **Streamlit (legacy)** — `streamlit run chat_frontend.py` +Use the production frontend — the CloudFront or custom-domain URL. Response quality improves as more documents finish ingestion; partial answers are expected during the initial run. diff --git a/chat_frontend.py b/chat_frontend.py deleted file mode 100644 index ba08c1c..0000000 --- a/chat_frontend.py +++ /dev/null @@ -1,187 +0,0 @@ -import json -import boto3 -import requests -import streamlit as st -import uuid -import yaml - -config = yaml.safe_load(open("./config.yaml")) - -API_URL = config["rag_api_endpoint"] + "chat-response" -FEEDBACK_URL = config["rag_api_endpoint"] + "feedback" -# The deploy publishes the generated API key to SSM (single source of truth) -API_KEY = boto3.client("ssm", region_name=config.get("aws_region", "us-east-1")).get_parameter( - Name="/chatbot/api-key" -)["Parameter"]["Value"] - - -def display_response(raw_text: str): - # Decode escaped characters like \n and \" - decoded_text = raw_text.encode('utf-8').decode('utf-8').replace('"', "") - st.markdown(decoded_text) - - -def send_feedback_callback(timestamp: int, rating: str, feedback_text: str = ""): - """Callback function for feedback buttons.""" - if send_feedback(st.session_state.session_id, timestamp, rating, feedback_text): - if rating in ["thumbs_up", "thumbs_down"]: - thumb_key = f"{timestamp}_thumb" - st.session_state.feedback_sent.add(thumb_key) - # Store which thumb was pressed - rating_key = f"{timestamp}_rating" - st.session_state[rating_key] = rating - else: - text_key = f"{timestamp}_text" - st.session_state.feedback_sent.add(text_key) - st.success("Thanks for your feedback!") - - -def send_feedback(session_id: str, timestamp: int, rating: str, feedback_text: str = ""): - """Send feedback to the API.""" - headers = {"x-api-key": API_KEY} - data = { - "session_id": session_id, - "timestamp": timestamp, - "rating": rating, - "feedback_text": feedback_text - } - try: - response = requests.post(FEEDBACK_URL, json=data, headers=headers) - response.raise_for_status() - return True - except Exception as e: - st.error(f"Error sending feedback: {e}") - return False - - -# Initialize session state -if "messages" not in st.session_state: - st.session_state.messages = [] -if "session_id" not in st.session_state: - st.session_state.session_id = str(uuid.uuid4()) -if "feedback_sent" not in st.session_state: - st.session_state.feedback_sent = set() - -# Streamlit App Setup -st.set_page_config(page_title="Internet2 Chatbot PoC", page_icon="💬 ") -st.title("Internet2 Chatbot PoC") - -with st.sidebar: - st.markdown(""" - *Some questions you can ask me* - - What workloads can I run on AWS? - - What workloads can I run on GCP? - - What did Lee Pang say about Amazon Omics? - - What is AWS Omics? - - How do I convince my leadership of the importance of FinOps practices? - - Who has a Cloud Center of Excellence? - - How are people doing account provisioning? - - I've got a consultant coming in to install Control Tower for us, but they don't have any higher ed experience. What questions should I be asking to make sure I don't have to redo the work later? - - Do I have to set up a cloud networking architecture for each platform or is there a single strategy to rule them all? - """) - - # Add session reset button - if st.button("New Conversation"): - st.session_state.messages = [] - st.session_state.session_id = str(uuid.uuid4()) - st.session_state.feedback_sent = set() - st.rerun() - - -# Display the chat messages -for i, msg in enumerate(st.session_state.messages): - role = "You" if msg["role"] == "user" else "Bot" - with st.chat_message(msg["role"]): - display_response(msg["content"]) - - # Add feedback buttons for assistant messages - if msg["role"] == "assistant" and "timestamp" in msg: - timestamp = msg["timestamp"] - thumb_key = f"{timestamp}_thumb" - text_key = f"{timestamp}_text" - rating_key = f"{timestamp}_rating" - - col1, col2, col3 = st.columns([1, 1, 8]) - - with col1: - if thumb_key in st.session_state.feedback_sent: - if st.session_state.get(rating_key) == "thumbs_up": - st.markdown('
👍
', unsafe_allow_html=True) - else: - st.text("👍") - else: - if st.button("👍", key=f"up_{i}", on_click=lambda t=timestamp: send_feedback_callback(t, "thumbs_up")): - pass - - with col2: - if thumb_key in st.session_state.feedback_sent: - if st.session_state.get(rating_key) == "thumbs_down": - st.markdown('
👎
', unsafe_allow_html=True) - else: - st.text("👎") - else: - if st.button("👎", key=f"down_{i}", on_click=lambda t=timestamp: send_feedback_callback(t, "thumbs_down")): - pass - - # Feedback text input - if text_key not in st.session_state.feedback_sent: - feedback_text = st.text_input("Additional feedback (optional):", key=f"feedback_{i}") - if st.button("Submit Feedback", key=f"submit_{i}") and feedback_text: - send_feedback_callback(timestamp, "text_feedback", feedback_text) - else: - st.text("✓ Text feedback submitted") - - -# User input field -user_input = st.chat_input("Type your question here...") - -if user_input: - # Add user message to history - st.session_state.messages.append({"role": "user", "content": user_input}) - with st.chat_message("user"): - display_response(user_input) - - # Send to API with session ID - headers = {"x-api-key": API_KEY} - data = { - "query": user_input, - "session_id": st.session_state.session_id - } - try: - response = requests.post(API_URL, json=data, headers=headers) - response.raise_for_status() - response_data = json.loads(response.text) - bot_reply = response_data.get("response", response.text) - timestamp = response_data.get("timestamp") - # Update session ID if provided - if "session_id" in response_data: - st.session_state.session_id = response_data["session_id"] - except Exception as e: - bot_reply = f"Error: {e}" - timestamp = None - - # Add bot response to history with timestamp - message_data = {"role": "assistant", "content": bot_reply} - if timestamp: - message_data["timestamp"] = timestamp - - st.session_state.messages.append(message_data) - with st.chat_message("assistant"): - display_response(bot_reply) - - # Add feedback buttons for the new response - if timestamp: - col1, col2, col3 = st.columns([1, 1, 8]) - - with col1: - if st.button("👍", key=f"up_new", on_click=lambda: send_feedback_callback(timestamp, "thumbs_up")): - pass - - with col2: - if st.button("👎", key=f"down_new", on_click=lambda: send_feedback_callback(timestamp, "thumbs_down")): - pass - - # Feedback text input - feedback_text = st.text_input("Additional feedback (optional):", key=f"feedback_new") - if st.button("Submit Feedback", key=f"submit_new") and feedback_text: - send_feedback_callback(timestamp, "text_feedback", feedback_text) diff --git a/chat_test.py b/chat_test.py deleted file mode 100644 index f2da4ce..0000000 --- a/chat_test.py +++ /dev/null @@ -1,80 +0,0 @@ -import json -import boto3 -import requests -import uuid -import yaml - -config = yaml.safe_load(open("./config.yaml")) - -API_URL = config["rag_api_endpoint"] + "chat-response" -FEEDBACK_URL = config["rag_api_endpoint"] + "feedback" -# The deploy publishes the generated API key to SSM (single source of truth) -API_KEY = boto3.client("ssm", region_name=config.get("aws_region", "us-east-1")).get_parameter( - Name="/chatbot/api-key" -)["Parameter"]["Value"] - -headers = { - "x-api-key": API_KEY, -} - -session_id = str(uuid.uuid4()) - -def format_response(raw_text: str): - # Decode escaped characters like \n and \" - decoded_text = raw_text.encode('utf-8').decode('utf-8').replace('"', "") - return decoded_text - -def send_feedback(session_id: str, timestamp: int, rating: str, feedback_text: str = ""): - """Send feedback to the API.""" - data = { - "session_id": session_id, - "timestamp": timestamp, - "rating": rating, - "feedback_text": feedback_text - } - try: - response = requests.post(FEEDBACK_URL, json=data, headers=headers) - response.raise_for_status() - return True - except Exception as e: - print(f"Error sending feedback: {e}") - return False - -print("Internet2 Chatbot - Type 'quit' to exit") -print(f"Session ID: {session_id}") -print("-" * 50) - -while True: - question = input("\nAsk a question: ") - if question.lower() == 'quit': - break - - data = { - "query": question, - "session_id": session_id - } - - try: - response = requests.post(API_URL, json=data, headers=headers) - response.raise_for_status() - response_data = json.loads(response.text) - bot_reply = response_data.get("response", response.text) - timestamp = response_data.get("timestamp") - print(f"\nBot: {format_response(bot_reply)}") - - # Ask for feedback - if timestamp: - feedback = input("\nRate this response (u=👍, d=👎, enter=skip): ").lower() - if feedback == 'u': - if send_feedback(session_id, timestamp, "thumbs_up"): - print("Thanks for your feedback!") - elif feedback == 'd': - if send_feedback(session_id, timestamp, "thumbs_down"): - print("Thanks for your feedback!") - # Ask for additional feedback on thumbs down - text_feedback = input("Any additional feedback? (optional): ") - if text_feedback: - send_feedback(session_id, timestamp, "text_feedback", text_feedback) - - except Exception as e: - print(f"Error: {e}") diff --git a/requirements.txt b/requirements.txt index ce68398..a2b7ef6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ boto3==1.42.84 requests-aws4auth==1.3.1 pyyaml==6.0.3 requests==2.33.1 -streamlit==1.56.0 aws-cdk-lib==2.248.0 constructs>=10.0.0,<11.0.0 beautifulsoup4==4.14.3 diff --git a/check_processing_status.sh b/scripts/check_processing_status.sh similarity index 100% rename from check_processing_status.sh rename to scripts/check_processing_status.sh