Wajahat698 commited on
Commit
0232efa
·
verified ·
1 Parent(s): 5c924e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -16
app.py CHANGED
@@ -1290,7 +1290,7 @@ prompt_template = ChatPromptTemplate.from_messages([
1290
  ])
1291
 
1292
  # Create Langchain Agent
1293
- llm = ChatOpenAI(model="gpt-4o", temperature=0.7)
1294
  llm_with_tools = llm.bind_tools(tools)
1295
 
1296
  # Define the agent pipeline
@@ -1606,20 +1606,21 @@ def handle_memory_queries(prompt):
1606
  """
1607
  Main function to handle user commands and allocate Trust Buckets.
1608
  """
1609
- prompt = prompt.lower().strip()
1610
 
1611
- # Save and allocate TrustBuilder
1612
- match = re.search(r"\bsave\s+as\s+(\w+)\s+trustbuilder\s*:\s*(.+)", prompt, re.IGNORECASE)
1613
- if match:
1614
- specified_bucket = match.group(1).capitalize()
1615
- content_to_save = match.group(2).strip()
 
 
1616
 
1617
- valid_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
1618
  if specified_bucket in valid_buckets:
1619
  if content_to_save:
1620
  assistant_response = handle_save_trustbuilder(content_to_save, specified_bucket)
1621
  else:
1622
- assistant_response = "No content provided. Please include content after the 'save as' command."
1623
  else:
1624
  assistant_response = f"Invalid Trust Bucket '{specified_bucket}'. Valid buckets are: {', '.join(valid_buckets)}."
1625
 
@@ -1629,14 +1630,19 @@ def handle_memory_queries(prompt):
1629
  st.markdown(assistant_response)
1630
  return None
1631
 
1632
- # Show saved TrustBuilders
1633
- elif "find my saved trustbuilders" in prompt.lower() or "show my saved trustbuilders" in prompt.lower():
1634
- trustbuilders = fetch_trustbuilders(st.session_state.get("wix_user_id", "default_user"))
1635
- if trustbuilders:
1636
- saved_content = "\n".join([f"- {entry['message']}" for entry in trustbuilders.values()])
1637
- assistant_response = f"Here are your saved TrustBuilders:\n{saved_content}"
 
 
 
 
 
1638
  else:
1639
- assistant_response = "You haven't saved any TrustBuilders yet."
1640
 
1641
  # Save response to chat history and display it
1642
  st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
@@ -1644,6 +1650,31 @@ def handle_memory_queries(prompt):
1644
  st.markdown(assistant_response)
1645
  return None
1646
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1647
  return None
1648
 
1649
  def handle_save_trustbuilder(content, specified_bucket=None):
 
1290
  ])
1291
 
1292
  # Create Langchain Agent
1293
+ llm = ChatOpenAI(model="gpt-4o", temperature=0.6)
1294
  llm_with_tools = llm.bind_tools(tools)
1295
 
1296
  # Define the agent pipeline
 
1606
  """
1607
  Main function to handle user commands and allocate Trust Buckets.
1608
  """
1609
+ prompt = prompt.strip()
1610
 
1611
+ valid_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
1612
+
1613
+ # Case 1: Save this as [bucket] trust builder: [content]
1614
+ match_save_this_specific = re.search(r"\bsave\s+(this\s+)?as\s+(\w+)\s+trust\s+builders?\s*:\s*(.+)", prompt, re.IGNORECASE)
1615
+ if match_save_this_specific:
1616
+ specified_bucket = match_save_this_specific.group(2).capitalize()
1617
+ content_to_save = match_save_this_specific.group(3).strip()
1618
 
 
1619
  if specified_bucket in valid_buckets:
1620
  if content_to_save:
1621
  assistant_response = handle_save_trustbuilder(content_to_save, specified_bucket)
1622
  else:
1623
+ assistant_response = "No content provided. Please include content after 'save this as [bucket] trust builder:'."
1624
  else:
1625
  assistant_response = f"Invalid Trust Bucket '{specified_bucket}'. Valid buckets are: {', '.join(valid_buckets)}."
1626
 
 
1630
  st.markdown(assistant_response)
1631
  return None
1632
 
1633
+ # Case 2: Save this under [bucket]: [content]
1634
+ match_save_under_specific = re.search(r"\bsave\s+(this\s+)?under\s+(\w+)\s*:\s*(.+)", prompt, re.IGNORECASE)
1635
+ if match_save_under_specific:
1636
+ specified_bucket = match_save_under_specific.group(2).capitalize()
1637
+ content_to_save = match_save_under_specific.group(3).strip()
1638
+
1639
+ if specified_bucket in valid_buckets:
1640
+ if content_to_save:
1641
+ assistant_response = handle_save_trustbuilder(content_to_save, specified_bucket)
1642
+ else:
1643
+ assistant_response = "No content provided. Please include content after 'save this under [bucket]:'."
1644
  else:
1645
+ assistant_response = f"Invalid Trust Bucket '{specified_bucket}'. Valid buckets are: {', '.join(valid_buckets)}."
1646
 
1647
  # Save response to chat history and display it
1648
  st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
 
1650
  st.markdown(assistant_response)
1651
  return None
1652
 
1653
+ # Case 3: Save and allocate: [content] (automatic allocation)
1654
+ match_save_allocate_auto = re.search(r"\bsave\s+(this\s+)?and\s+allocate\s*:\s*(.+)", prompt, re.IGNORECASE)
1655
+ if match_save_allocate_auto:
1656
+ content_to_save = match_save_allocate_auto.group(2).strip()
1657
+ if content_to_save:
1658
+ assistant_response = handle_save_trustbuilder(content_to_save) # Automatically allocate bucket
1659
+ else:
1660
+ assistant_response = "No content provided. Please include content after 'save and allocate:'."
1661
+
1662
+ # Save response to chat history and display it
1663
+ st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
1664
+ with st.chat_message("assistant"):
1665
+ st.markdown(assistant_response)
1666
+ return None
1667
+
1668
+ # Default case: Unrecognized command
1669
+ assistant_response = (
1670
+ "Command not recognized. Please use a valid format like:\n"
1671
+ "- Save this as [bucket] trust builder: [content]\n"
1672
+ "- Save and allocate: [content]\n"
1673
+ "- Save this under [bucket]: [content]"
1674
+ )
1675
+ st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
1676
+ with st.chat_message("assistant"):
1677
+ st.markdown(assistant_response)
1678
  return None
1679
 
1680
  def handle_save_trustbuilder(content, specified_bucket=None):