Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1835,13 +1835,18 @@ def handle_prompt(prompt):
|
|
| 1835 |
|
| 1836 |
if bucket in valid_buckets:
|
| 1837 |
content_to_save = st.session_state.pop("missing_trustbucket_content")
|
| 1838 |
-
handle_save_trustbuilder(content_to_save, bucket)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1839 |
else:
|
| 1840 |
with st.chat_message("assistant"):
|
| 1841 |
st.markdown("Invalid Trust Bucket. Please choose from Stability, Development, Relationship, Benefit, Vision, or Competence.")
|
| 1842 |
st.session_state["handled"] = True
|
|
|
|
| 1843 |
|
| 1844 |
-
# Handle fetching saved TrustBuilders
|
| 1845 |
if ("find my saved trustbuilders" in prompt.lower() or "show my saved trustbuilders" in prompt.lower()) and not st.session_state["handled"]:
|
| 1846 |
trustbuilders = fetch_trustbuilders(st.session_state.get("wix_user_id", "default_user"))
|
| 1847 |
if trustbuilders:
|
|
@@ -1849,14 +1854,12 @@ def handle_prompt(prompt):
|
|
| 1849 |
assistant_response = f"Here are your saved TrustBuilders:\n{saved_content}"
|
| 1850 |
else:
|
| 1851 |
assistant_response = "You haven't saved any TrustBuilders yet."
|
| 1852 |
-
|
| 1853 |
-
# Append assistant's response to chat history
|
| 1854 |
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
| 1855 |
-
|
| 1856 |
-
# Display the assistant's response
|
| 1857 |
with st.chat_message("assistant"):
|
| 1858 |
st.markdown(assistant_response)
|
| 1859 |
st.session_state["handled"] = True
|
|
|
|
| 1860 |
|
| 1861 |
# Handle save TrustBuilder command
|
| 1862 |
if not st.session_state["handled"]:
|
|
@@ -1865,7 +1868,7 @@ def handle_prompt(prompt):
|
|
| 1865 |
content_to_save = save_match.group(5).strip() if save_match.group(5) else None
|
| 1866 |
specified_bucket = None
|
| 1867 |
|
| 1868 |
-
# Check for explicit bucket mention
|
| 1869 |
bucket_match = re.search(r"\b(stability|development|relationship|benefit|vision|competence)\b", prompt, re.IGNORECASE)
|
| 1870 |
if bucket_match:
|
| 1871 |
specified_bucket = bucket_match.group(1).capitalize()
|
|
@@ -1876,42 +1879,33 @@ def handle_prompt(prompt):
|
|
| 1876 |
st.session_state.chat_history.append({"role": "assistant", "content": response})
|
| 1877 |
with st.chat_message("assistant"):
|
| 1878 |
st.markdown(response)
|
| 1879 |
-
|
| 1880 |
-
|
| 1881 |
-
|
| 1882 |
-
else:
|
| 1883 |
-
# Prompt user to provide content if missing
|
| 1884 |
-
with st.chat_message("assistant"):
|
| 1885 |
-
st.markdown("Please provide the content to save as a TrustBuilder.")
|
| 1886 |
|
| 1887 |
-
# Mark as handled and exit to prevent further processing
|
| 1888 |
st.session_state["handled"] = True
|
| 1889 |
-
return # Exit
|
| 1890 |
|
| 1891 |
-
# Handle other memory queries
|
| 1892 |
if not st.session_state["handled"]:
|
| 1893 |
memory_response = handle_memory_queries(prompt)
|
| 1894 |
-
if memory_response
|
| 1895 |
-
|
| 1896 |
-
st.session_state["handled"] = True
|
| 1897 |
-
elif memory_response:
|
| 1898 |
with st.chat_message("assistant"):
|
| 1899 |
st.markdown(memory_response)
|
| 1900 |
st.session_state["handled"] = True
|
|
|
|
| 1901 |
|
| 1902 |
-
# If
|
| 1903 |
if not st.session_state["handled"]:
|
| 1904 |
-
# Generate a response with AI for other types of queries
|
| 1905 |
with st.chat_message("user"):
|
| 1906 |
st.markdown(prompt)
|
|
|
|
| 1907 |
response_placeholder = st.empty()
|
| 1908 |
with response_placeholder:
|
| 1909 |
with st.chat_message("assistant"):
|
| 1910 |
add_dot_typing_animation()
|
| 1911 |
-
display_typing_indicator()
|
| 1912 |
-
|
| 1913 |
-
cleaned_text = ""
|
| 1914 |
-
# Specialized responses if keywords detected
|
| 1915 |
try:
|
| 1916 |
output = agent_executor.invoke({
|
| 1917 |
"input": f"{prompt} Avoid flowery language and AI-Jargons.Only when asked to write an article, blog, newsletter, adhere to the following structure and ensure trust builders are fluidly interconnected for cohesive and logical flow. Use clear subheaders for each paragraph to structure the content effectively and Use explicit transitions to show how one section leads to or supports the next.Do-not mention trustbucket names literally and word 'trust' in the copy applications.*Use only knowledgebase when asked about top trust buckets and builders give exactly those*. ",
|
|
|
|
| 1835 |
|
| 1836 |
if bucket in valid_buckets:
|
| 1837 |
content_to_save = st.session_state.pop("missing_trustbucket_content")
|
| 1838 |
+
response = handle_save_trustbuilder(content_to_save, bucket)
|
| 1839 |
+
if response:
|
| 1840 |
+
st.session_state.chat_history.append({"role": "assistant", "content": response})
|
| 1841 |
+
with st.chat_message("assistant"):
|
| 1842 |
+
st.markdown(response)
|
| 1843 |
else:
|
| 1844 |
with st.chat_message("assistant"):
|
| 1845 |
st.markdown("Invalid Trust Bucket. Please choose from Stability, Development, Relationship, Benefit, Vision, or Competence.")
|
| 1846 |
st.session_state["handled"] = True
|
| 1847 |
+
return # Exit to prevent further processing
|
| 1848 |
|
| 1849 |
+
# Handle fetching saved TrustBuilders
|
| 1850 |
if ("find my saved trustbuilders" in prompt.lower() or "show my saved trustbuilders" in prompt.lower()) and not st.session_state["handled"]:
|
| 1851 |
trustbuilders = fetch_trustbuilders(st.session_state.get("wix_user_id", "default_user"))
|
| 1852 |
if trustbuilders:
|
|
|
|
| 1854 |
assistant_response = f"Here are your saved TrustBuilders:\n{saved_content}"
|
| 1855 |
else:
|
| 1856 |
assistant_response = "You haven't saved any TrustBuilders yet."
|
| 1857 |
+
|
|
|
|
| 1858 |
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
|
|
|
|
|
|
| 1859 |
with st.chat_message("assistant"):
|
| 1860 |
st.markdown(assistant_response)
|
| 1861 |
st.session_state["handled"] = True
|
| 1862 |
+
return # Exit to prevent further processing
|
| 1863 |
|
| 1864 |
# Handle save TrustBuilder command
|
| 1865 |
if not st.session_state["handled"]:
|
|
|
|
| 1868 |
content_to_save = save_match.group(5).strip() if save_match.group(5) else None
|
| 1869 |
specified_bucket = None
|
| 1870 |
|
| 1871 |
+
# Check for explicit bucket mention
|
| 1872 |
bucket_match = re.search(r"\b(stability|development|relationship|benefit|vision|competence)\b", prompt, re.IGNORECASE)
|
| 1873 |
if bucket_match:
|
| 1874 |
specified_bucket = bucket_match.group(1).capitalize()
|
|
|
|
| 1879 |
st.session_state.chat_history.append({"role": "assistant", "content": response})
|
| 1880 |
with st.chat_message("assistant"):
|
| 1881 |
st.markdown(response)
|
| 1882 |
+
else:
|
| 1883 |
+
with st.chat_message("assistant"):
|
| 1884 |
+
st.markdown("Please provide the content to save as a TrustBuilder.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1885 |
|
|
|
|
| 1886 |
st.session_state["handled"] = True
|
| 1887 |
+
return # Exit to prevent further processing
|
| 1888 |
|
| 1889 |
+
# Handle other memory queries
|
| 1890 |
if not st.session_state["handled"]:
|
| 1891 |
memory_response = handle_memory_queries(prompt)
|
| 1892 |
+
if memory_response:
|
| 1893 |
+
st.session_state.chat_history.append({"role": "assistant", "content": memory_response})
|
|
|
|
|
|
|
| 1894 |
with st.chat_message("assistant"):
|
| 1895 |
st.markdown(memory_response)
|
| 1896 |
st.session_state["handled"] = True
|
| 1897 |
+
return # Exit to prevent further processing
|
| 1898 |
|
| 1899 |
+
# If no specific handling, generate a general AI response
|
| 1900 |
if not st.session_state["handled"]:
|
|
|
|
| 1901 |
with st.chat_message("user"):
|
| 1902 |
st.markdown(prompt)
|
| 1903 |
+
|
| 1904 |
response_placeholder = st.empty()
|
| 1905 |
with response_placeholder:
|
| 1906 |
with st.chat_message("assistant"):
|
| 1907 |
add_dot_typing_animation()
|
| 1908 |
+
display_typing_indicator() # Specialized responses if keywords detected
|
|
|
|
|
|
|
|
|
|
| 1909 |
try:
|
| 1910 |
output = agent_executor.invoke({
|
| 1911 |
"input": f"{prompt} Avoid flowery language and AI-Jargons.Only when asked to write an article, blog, newsletter, adhere to the following structure and ensure trust builders are fluidly interconnected for cohesive and logical flow. Use clear subheaders for each paragraph to structure the content effectively and Use explicit transitions to show how one section leads to or supports the next.Do-not mention trustbucket names literally and word 'trust' in the copy applications.*Use only knowledgebase when asked about top trust buckets and builders give exactly those*. ",
|