Wajahat698 commited on
Commit
602c701
·
verified ·
1 Parent(s): 6e3eb7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -1712,29 +1712,37 @@ welcome_placeholder.empty()
1712
  # Input field for chatbot interaction
1713
  prompt = st.chat_input("")
1714
  global combined_text
 
1715
  if st.session_state["used_messages"] < st.session_state["message_limit"]:
1716
  if prompt:
1717
  st.session_state.chat_started = True
1718
- # Prevent duplicate messages in chat history
 
1719
  if not any(msg["content"] == prompt for msg in st.session_state["chat_history"]):
1720
  st.session_state.chat_history.append({"role": "user", "content": prompt})
1721
 
1722
-
1723
-
1724
-
1725
- # Handle save commands based on the user prompt
1726
- memory_response = handle_memory_queries(prompt)
1727
- if memory_response:
1728
- with st.chat_message("assistant"):
1729
- st.markdown(memory_response)
1730
- elif st.session_state.get("missing_trustbucket_content"):
1731
- bucket = prompt.strip()
1732
  valid_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
 
1733
  if bucket in valid_buckets:
1734
  content_to_save = st.session_state.pop("missing_trustbucket_content")
1735
  handle_save_trustbuilder(content_to_save, bucket)
 
 
 
 
 
 
1736
  else:
1737
- # Generate a response with AI for general queries
 
 
 
 
 
 
1738
  with st.chat_message("user"):
1739
  st.markdown(prompt)
1740
  response_placeholder = st.empty()
@@ -1743,15 +1751,17 @@ if st.session_state["used_messages"] < st.session_state["message_limit"]:
1743
  add_dot_typing_animation()
1744
  display_typing_indicator()
1745
  cleaned_text = ""
 
1746
  try:
1747
  output = agent_executor.invoke({
1748
- "input": f"{prompt} Be in natural tone,doesn’t use flowery language and typical ai words .Use knowledge when user use 'our' or 'Volkswagen' pull only directly information from knowledgebase and display as it is if not found use google then provide relevant sources.Avoid AI jargons.Give short headings in conversational language with each paragraph in content of article,blogs,writeup and newsletter keeping mentioned format only when asked .",
1749
  "chat_history": st.session_state.chat_history
1750
  })
1751
  full_response = output["output"]
1752
  cleaned_text = clean_text(full_response)
1753
  trust_tip, suggestion = get_trust_tip_and_suggestion()
1754
  combined_text = f"{cleaned_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
 
1755
  with response_placeholder:
1756
  with st.chat_message("assistant"):
1757
  st.markdown(combined_text, unsafe_allow_html=True)
@@ -1761,6 +1771,6 @@ if st.session_state["used_messages"] < st.session_state["message_limit"]:
1761
  except Exception as e:
1762
  logger.error(f"Error generating response: {e}")
1763
  st.error("An error occurred while generating the response. Please try again.")
1764
-
1765
  st.session_state.chat_history.append({"role": "assistant", "content": cleaned_text})
1766
- copy_to_clipboard(cleaned_text)
 
1712
  # Input field for chatbot interaction
1713
  prompt = st.chat_input("")
1714
  global combined_text
1715
+
1716
  if st.session_state["used_messages"] < st.session_state["message_limit"]:
1717
  if prompt:
1718
  st.session_state.chat_started = True
1719
+
1720
+ # Prevent duplicate messages in chat history
1721
  if not any(msg["content"] == prompt for msg in st.session_state["chat_history"]):
1722
  st.session_state.chat_history.append({"role": "user", "content": prompt})
1723
 
1724
+ # Check if a missing bucket needs to be handled
1725
+ if st.session_state.get("missing_trustbucket_content"):
1726
+ bucket = prompt.strip().capitalize()
 
 
 
 
 
 
 
1727
  valid_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
1728
+
1729
  if bucket in valid_buckets:
1730
  content_to_save = st.session_state.pop("missing_trustbucket_content")
1731
  handle_save_trustbuilder(content_to_save, bucket)
1732
+ with st.chat_message("assistant"):
1733
+ st.markdown(f"Got it! I've saved this TrustBuilder under '{bucket}' Trust. Let me know if there's anything else you'd like to do!")
1734
+ else:
1735
+ with st.chat_message("assistant"):
1736
+ st.markdown("That doesn't seem to be a valid Trust Bucket. Please choose from Stability, Development, Relationship, Benefit, Vision, or Competence.")
1737
+
1738
  else:
1739
+ # Handle save commands or general queries
1740
+ memory_response = handle_memory_queries(prompt)
1741
+ if memory_response:
1742
+ with st.chat_message("assistant"):
1743
+ st.markdown(memory_response)
1744
+ else:
1745
+ # Generate a response for general queries using AI
1746
  with st.chat_message("user"):
1747
  st.markdown(prompt)
1748
  response_placeholder = st.empty()
 
1751
  add_dot_typing_animation()
1752
  display_typing_indicator()
1753
  cleaned_text = ""
1754
+
1755
  try:
1756
  output = agent_executor.invoke({
1757
+ "input": f"{prompt} Be in natural tone, avoid flowery language or typical AI words.Use knowledge directly from our base; if unavailable, use Google with sources.Avoid AI jargon and provide concise, conversational headings for each section.",
1758
  "chat_history": st.session_state.chat_history
1759
  })
1760
  full_response = output["output"]
1761
  cleaned_text = clean_text(full_response)
1762
  trust_tip, suggestion = get_trust_tip_and_suggestion()
1763
  combined_text = f"{cleaned_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
1764
+
1765
  with response_placeholder:
1766
  with st.chat_message("assistant"):
1767
  st.markdown(combined_text, unsafe_allow_html=True)
 
1771
  except Exception as e:
1772
  logger.error(f"Error generating response: {e}")
1773
  st.error("An error occurred while generating the response. Please try again.")
1774
+
1775
  st.session_state.chat_history.append({"role": "assistant", "content": cleaned_text})
1776
+ copy_to_clipboard(cleaned_text)