From a458d15729d52941e52c3a7cf7eb56c722e9c95b Mon Sep 17 00:00:00 2001 From: Lino Mediavilla Date: Mon, 24 Feb 2025 21:03:36 -0500 Subject: [PATCH] Update route handler to handle empty questions An exception was thrown when the user submitted an empty question. --- .../docs_agent/interfaces/chatbot/chatui.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py b/examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py index 73e7378f0..7990ce19e 100644 --- a/examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py +++ b/examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py @@ -245,11 +245,14 @@ def feedback(): # using input text box. @bp.route("/result", methods=["GET", "POST"]) def result(): - if request.method == "POST": - question = request.form["question"] - return ask_model(question, agent=docs_agent, template=app_template) - else: + if request.method != "POST": + return redirect(url_for(redirect_index)) + + question = request.form.get("question", "").strip() + if not question: return redirect(url_for(redirect_index)) + + return ask_model(question, agent=docs_agent, template=app_template) # Render a response page when the user clicks a question # from the related questions list.