Skip to content

Commit

Permalink
remove feedback request as well if user refreshes immediately after r…
Browse files Browse the repository at this point in the history
…equest; only store new response on refreshes
  • Loading branch information
mdr223 committed Oct 29, 2023
1 parent 6741dcc commit 41ba719
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
20 changes: 13 additions & 7 deletions A2rchi/interfaces/chat_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def query_conversation_history(self, conversation_id):
return history


def insert_conversation(self, conversation_id, user_message, a2rchi_message) -> List[int]:
def insert_conversation(self, conversation_id, user_message, a2rchi_message, is_refresh=False) -> List[int]:
"""
"""
print(" INFO - entered insert_conversation.")
Expand All @@ -120,11 +120,17 @@ def insert_conversation(self, conversation_id, user_message, a2rchi_message) ->
a2rchi_sender, a2rchi_content, a2rchi_msg_ts = a2rchi_message

# construct insert_tups
insert_tups = [
# (conversation_id, sender, content, ts)
(conversation_id, user_sender, user_content, user_msg_ts),
(conversation_id, a2rchi_sender, a2rchi_content, a2rchi_msg_ts),
]
insert_tups = (
[
# (conversation_id, sender, content, ts)
(conversation_id, user_sender, user_content, user_msg_ts),
(conversation_id, a2rchi_sender, a2rchi_content, a2rchi_msg_ts),
]
if not is_refresh
else [
(conversation_id, a2rchi_sender, a2rchi_content, a2rchi_msg_ts),
]
)

# create connection to database
self.conn = psycopg2.connect(**self.pg_config)
Expand Down Expand Up @@ -218,7 +224,7 @@ def __call__(self, message: List[str], conversation_id: int, is_refresh: bool, m
print(user_message)
print(a2rchi_message)

message_ids = self.insert_conversation(conversation_id, user_message, a2rchi_message)
message_ids = self.insert_conversation(conversation_id, user_message, a2rchi_message, is_refresh)

except Exception as e:
raise e
Expand Down
13 changes: 12 additions & 1 deletion A2rchi/interfaces/chat_app/static/script.js-template
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let userText = null;
let conversation_id = null;
let conversation = []
let num_responses_since_last_rating = 0;
let last_response_is_feedback_request = false;

const loadDataFromLocalstorage = () => {
// Load saved chats and theme from local storage and apply/add on the page
Expand Down Expand Up @@ -50,8 +51,16 @@ const refreshChat = async () => {
return;
}

// remove message to be regenerated from conversation
conversation.pop();
chatContainer.removeChild(chatContainer.lastChild);

// if the last response generated a feedback request, make sure to remove it here as well
if (last_response_is_feedback_request) {
chatContainer.removeChild(chatContainer.lastChild);
}

// generate new response
showTypingAnimation(isRefresh=true);
}

Expand Down Expand Up @@ -80,6 +89,7 @@ const getChatResponse = async (incomingChatDiv, isRefresh=false) => {
pElement.classList.add(".default-text");
conversation.push(["A2rchi", response.response]);
conversation_id = response.conversation_id;
last_response_is_feedback_request = false;
} catch (error) {
pElement.classList.add("error");
pElement.textContent = "Oops! Something went wrong while retrieving the response. Please try again.";
Expand Down Expand Up @@ -210,7 +220,7 @@ const showFeedbackRequest = () => {
<div class="chat-details">
<img src="/static/images/a2rchi.png" alt="chatbot-img">
<div class=".default-text">
<p>I've noticed you haven't rated any of my responses in awhile. Rating responses is crucial because it not only helps me improve, but it also ensures that this project remains open source and freely accessible for everyone. Your input is highly valuable in supporting the A2rchi mission! </p>
<p>I've noticed you haven't rated any of my responses in a while. Rating responses is crucial because it not only helps me improve, but it also ensures that this project remains open source and freely accessible for everyone. Your input is highly valuable in supporting the A2rchi mission! </p>
</div>
</div>
</div>`;
Expand All @@ -221,6 +231,7 @@ const showFeedbackRequest = () => {
chatContainer.appendChild(incomingChatDiv);
chatContainer.scrollTo(0, chatContainer.scrollHeight);
num_responses_since_last_rating = 0;
last_response_is_feedback_request = true;
}
}

Expand Down

0 comments on commit 41ba719

Please sign in to comment.