Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgxue committed Feb 28, 2024
1 parent 6fbe2d4 commit daf6de8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api/ask_astro/services/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ask_astro.clients.firestore import firestore_client
from ask_astro.config import FirestoreCollections, PromptPreprocessingConfig
from ask_astro.models.request import AskAstroRequest, Source
from ask_astro.settings import SERVICE_MAINTENANCE_BANNER_STATUS

logger = getLogger(__name__)

Expand All @@ -19,6 +20,10 @@ class InvalidRequestPromptError(Exception):
"""Exception raised when the prompt string in the request object is invalid"""


class RequestDuringMaintenanceException(Exception):
"""Exception raised when a request is still somehow received on the backend when server is in maintenance"""


class QuestionAnsweringError(Exception):
"""Exception raised when an error occurs during question answering"""

Expand All @@ -37,6 +42,10 @@ async def _update_firestore_request(request: AskAstroRequest) -> None:


def _preprocess_request(request: AskAstroRequest) -> None:
if SERVICE_MAINTENANCE_BANNER_STATUS:
error_msg = "Ask Astro is currently undergoing maintenance and will be back shortly. We apologize for any inconvenience this may cause!"
request.response = error_msg
raise RequestDuringMaintenanceException(error_msg)
if len(request.prompt) > PromptPreprocessingConfig.max_char:
error_msg = "Question text is too long. Please try making a new thread and shortening your question."
request.response = error_msg
Expand Down Expand Up @@ -110,7 +119,7 @@ async def answer_question(request: AskAstroRequest) -> None:
except Exception as e:
# If there's an error, mark the request as errored and add it to the database
request.status = "error"
if not isinstance(e, InvalidRequestPromptError):
if not isinstance(e, InvalidRequestPromptError) and not isinstance(e, RequestDuringMaintenanceException):
request.response = "Sorry, something went wrong. Please try again later."
raise QuestionAnsweringError("An error occurred during question answering.") from e
else:
Expand Down
2 changes: 2 additions & 0 deletions api/ask_astro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
CONVERSATIONAL_RETRIEVAL_LOAD_QA_CHAIN_DEPLOYMENT_NAME = os.environ.get(
"CONVERSATIONAL_RETRIEVAL_LOAD_QA_CHAIN_DEPLOYMENT_NAME", "gpt-4-32k"
)

SERVICE_MAINTENANCE_BANNER_STATUS = os.environ.get("SERVICE_MAINTENANCE_BANNER", "False") == "True"

0 comments on commit daf6de8

Please sign in to comment.