Skip to content

Commit

Permalink
add timeout handling on server-side
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr223 committed Nov 7, 2023
1 parent 8d1a8f2 commit 0ef02de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions A2rchi/interfaces/chat_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,20 @@ def get_chat_response(self):
import time
time.sleep(130)

# TODO: also need to add timeout to server

# compute timestamp at which message was received by server
msg_ts = datetime.now()

# get user input and conversation_id from the request
message = request.json.get('last_message')
conversation_id = request.json.get('conversation_id')
is_refresh = request.json.get('is_refresh')
client_msg_ts = request.json.get('client_msg_ts') / 1000
client_timeout = request.json.get('timeout') / 1000

# if timestamp from message is more than TIMEOUT_SECS in the past;
# do not generate response as the client will have timed out
if msg_ts - client_msg_ts > client_timeout:
return jsonify({'error': 'client timeout'}), 408

# query the chat and return the results.
print(" INFO - Calling the ChatWrapper()")
Expand Down
3 changes: 2 additions & 1 deletion A2rchi/interfaces/chat_app/static/script.js-template
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const getChatResponse = async (incomingChatDiv, isRefresh=false) => {
conversation_id: conversation_id,
is_refresh: isRefresh,
}),
client_msg_ts: Date.now(),
timeout: DEFAULT_TIMEOUT_SECS * 1000
}

Expand All @@ -115,7 +116,7 @@ const getChatResponse = async (incomingChatDiv, isRefresh=false) => {
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.";
pElement.textContent = "<p>Oops! Something went wrong while retrieving the response. Please try again.</p>";
}

// Remove the typing animation, append the paragraph element and save the chats to local storage
Expand Down

0 comments on commit 0ef02de

Please sign in to comment.