Spaces:
Running
Running
siddhartharya
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -651,12 +651,12 @@ def chatbot_response(user_query, chat_history, state_bookmarks):
|
|
651 |
"""
|
652 |
if not GROQ_API_KEY:
|
653 |
logger.warning("GROQ_API_KEY not set.")
|
654 |
-
return chat_history + [
|
655 |
|
656 |
bookmarks = state_bookmarks
|
657 |
if not bookmarks:
|
658 |
logger.warning("No bookmarks available for chatbot")
|
659 |
-
return chat_history + [
|
660 |
|
661 |
logger.info(f"Chatbot received query: {user_query}")
|
662 |
|
@@ -679,7 +679,7 @@ def chatbot_response(user_query, chat_history, state_bookmarks):
|
|
679 |
if not matching_bookmarks:
|
680 |
response_text = "No relevant bookmarks found for your query."
|
681 |
logger.info(response_text)
|
682 |
-
return chat_history + [
|
683 |
|
684 |
# Format the response
|
685 |
bookmarks_info = "\n\n".join([
|
@@ -709,7 +709,7 @@ Provide a concise and helpful response.
|
|
709 |
)
|
710 |
answer = response['choices'][0]['message']['content'].strip()
|
711 |
logger.info("Chatbot response generated")
|
712 |
-
return chat_history + [
|
713 |
|
714 |
except openai.error.RateLimitError as e:
|
715 |
wait_time = int(e.headers.get("Retry-After", 5))
|
@@ -719,7 +719,7 @@ Provide a concise and helpful response.
|
|
719 |
except Exception as e:
|
720 |
error_message = f"⚠️ Error processing your query: {str(e)}"
|
721 |
logger.error(error_message, exc_info=True)
|
722 |
-
return chat_history + [
|
723 |
|
724 |
def build_app():
|
725 |
"""
|
|
|
651 |
"""
|
652 |
if not GROQ_API_KEY:
|
653 |
logger.warning("GROQ_API_KEY not set.")
|
654 |
+
return chat_history + [{"role": "system", "content": "⚠️ API key not set. Please set the GROQ_API_KEY environment variable in the Hugging Face Space settings."}]
|
655 |
|
656 |
bookmarks = state_bookmarks
|
657 |
if not bookmarks:
|
658 |
logger.warning("No bookmarks available for chatbot")
|
659 |
+
return chat_history + [{"role": "system", "content": "⚠️ No bookmarks available. Please upload and process your bookmarks first."}]
|
660 |
|
661 |
logger.info(f"Chatbot received query: {user_query}")
|
662 |
|
|
|
679 |
if not matching_bookmarks:
|
680 |
response_text = "No relevant bookmarks found for your query."
|
681 |
logger.info(response_text)
|
682 |
+
return chat_history + [{"role": "assistant", "content": response_text}]
|
683 |
|
684 |
# Format the response
|
685 |
bookmarks_info = "\n\n".join([
|
|
|
709 |
)
|
710 |
answer = response['choices'][0]['message']['content'].strip()
|
711 |
logger.info("Chatbot response generated")
|
712 |
+
return chat_history + [{"role": "user", "content": user_query}, {"role": "assistant", "content": answer}]
|
713 |
|
714 |
except openai.error.RateLimitError as e:
|
715 |
wait_time = int(e.headers.get("Retry-After", 5))
|
|
|
719 |
except Exception as e:
|
720 |
error_message = f"⚠️ Error processing your query: {str(e)}"
|
721 |
logger.error(error_message, exc_info=True)
|
722 |
+
return chat_history + [{"role": "assistant", "content": error_message}]
|
723 |
|
724 |
def build_app():
|
725 |
"""
|