reddmann007 commited on
Commit
52151f0
·
verified ·
1 Parent(s): 04544a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import os
3
  from langchain_groq import ChatGroq
4
  from langchain_community.agent_toolkits.load_tools import load_tools
 
5
  from langgraph.prebuilt import create_react_agent
6
 
7
  # 1. Page Configuration
@@ -31,21 +32,32 @@ llm = ChatGroq(
31
 
32
  # 4. Load Math Tools
33
  # Load the tools FIRST
34
- tools = load_tools(["llm-math"], llm=llm)
 
 
 
 
 
 
 
35
  from langchain_core.messages import SystemMessage
36
 
37
  system_message = SystemMessage(
38
  content=(
39
- "You are a strict Mathematics Assistant. "
40
- "Your ONLY task is to solve mathematical problems using your tools. "
41
- "If a user asks about anything other than math (such as history, general knowledge, "
42
- "coding, or personal opinions), you must politely refuse and explain that you "
43
- "only provide assistance with mathematics."
 
 
 
 
 
44
  )
45
  )
46
 
47
-
48
- # We will pass the system message in the actual chat logic instead
49
  agent_executor = create_react_agent(llm, tools)
50
 
51
  # 5. Chat Interface Setup
 
2
  import os
3
  from langchain_groq import ChatGroq
4
  from langchain_community.agent_toolkits.load_tools import load_tools
5
+ from langchain_experimental.tools import PythonREPLTool
6
  from langgraph.prebuilt import create_react_agent
7
 
8
  # 1. Page Configuration
 
32
 
33
  # 4. Load Math Tools
34
  # Load the tools FIRST
35
+ # Create the Python Tool
36
+ python_tool = PythonREPLTool()
37
+
38
+ # Load the standard math tools
39
+ math_tools = load_tools(["llm-math"], llm=llm)
40
+
41
+ # Combine them into a single list for the agent
42
+ tools = [python_tool] + math_tools
43
  from langchain_core.messages import SystemMessage
44
 
45
  system_message = SystemMessage(
46
  content=(
47
+ "You are a specialized Mathematics Assistant. Your ONLY task is to solve problems "
48
+ "within these branches: Arithmetic, Algebra, Geometry, Calculus, Analysis, "
49
+ "Statistics & Probability, Trigonometry, Number Theory, and Topology.\n\n"
50
+ "GUIDELINES:\n"
51
+ "1. Use the 'python_repl' tool for complex formulas, symbolic algebra (SymPy), "
52
+ "or statistical analysis (SciPy/NumPy).\n"
53
+ "2. Use 'llm-math' for simple arithmetic.\n"
54
+ "3. If a user asks about history, coding (non-math), or any non-mathematical topic, "
55
+ "politely refuse.\n"
56
+ "4. Always show your work or explain the mathematical steps taken."
57
  )
58
  )
59
 
60
+ # Re-create the agent with the new tools and instructions
 
61
  agent_executor = create_react_agent(llm, tools)
62
 
63
  # 5. Chat Interface Setup