Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,10 +23,28 @@ llm = ChatGroq(
|
|
| 23 |
groq_api_key=api_key
|
| 24 |
)
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
|
|
|
| 28 |
tools = load_tools(["llm-math"], llm=llm)
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# 5. Chat Interface Setup
|
| 32 |
if "messages" not in st.session_state:
|
|
|
|
| 23 |
groq_api_key=api_key
|
| 24 |
)
|
| 25 |
|
| 26 |
+
# ... (Keep your imports and LLM initialization the same)
|
| 27 |
+
|
| 28 |
+
# 4. Load Math Tools
|
| 29 |
tools = load_tools(["llm-math"], llm=llm)
|
| 30 |
+
|
| 31 |
+
# --- ADD THE NEW BLOCK HERE ---
|
| 32 |
+
system_message = (
|
| 33 |
+
"You are a strict Mathematics Assistant. "
|
| 34 |
+
"Your ONLY task is to solve mathematical problems using your tools. "
|
| 35 |
+
"If a user asks about anything other than math (such as history, general knowledge, "
|
| 36 |
+
"coding, or personal opinions), you must politely refuse and explain that you "
|
| 37 |
+
"only provide assistance with mathematics."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
agent_executor = create_react_agent(
|
| 41 |
+
llm,
|
| 42 |
+
tools,
|
| 43 |
+
state_modifier=system_message
|
| 44 |
+
)
|
| 45 |
+
# --- END OF NEW BLOCK ---
|
| 46 |
+
|
| 47 |
+
# ... (Keep the Chat Interface logic below this)
|
| 48 |
|
| 49 |
# 5. Chat Interface Setup
|
| 50 |
if "messages" not in st.session_state:
|