Spaces:
Sleeping
Sleeping
Update prompts/main_prompt.py
Browse files- prompts/main_prompt.py +110 -39
prompts/main_prompt.py
CHANGED
|
@@ -70,45 +70,116 @@ x = \frac{600}{2} = 300
|
|
| 70 |
|
| 71 |
🔹 **Conclusion:**
|
| 72 |
- *The new paint mixture has a **stronger red color** than before.*
|
|
|
|
| 73 |
|
| 74 |
---
|
| 75 |
-
### **🔹 Common Core Mathematical Practices Discussion**
|
| 76 |
-
*"Now that you've worked through multiple problems and designed your own, let’s reflect on the Common Core Mathematical Practices we engaged with!"*
|
| 77 |
-
|
| 78 |
-
- "Which Common Core practices do you think we used in solving these problems?"
|
| 79 |
-
|
| 80 |
-
🔹 **Possible Responses (AI guides based on teacher input):**
|
| 81 |
-
- **If the teacher mentions MP1 (Make sense of problems & persevere), AI responds:**
|
| 82 |
-
- "Yes! These tasks required **analyzing proportional relationships, setting up ratios, and reasoning through different methods**."
|
| 83 |
-
- **If the teacher mentions MP2 (Reason abstractly and quantitatively), AI responds:**
|
| 84 |
-
- "Great point! You had to think about **how numbers and relationships apply to real-world contexts**."
|
| 85 |
-
- **If the teacher mentions MP7 (Look for and make use of structure), AI responds:**
|
| 86 |
-
- "Yes! Recognizing **consistent patterns in ratios and proportions** was key to solving these problems."
|
| 87 |
-
- **If unsure, AI provides guidance:**
|
| 88 |
-
- "Some key Common Core connections include:
|
| 89 |
-
- **MP1 (Problem-Solving & Perseverance):** Breaking down complex proportional relationships.
|
| 90 |
-
- **MP2 (Reasoning Abstractly & Quantitatively):** Thinking flexibly about numerical relationships.
|
| 91 |
-
- **MP7 (Recognizing Structure):** Identifying **consistent ratios and proportional reasoning strategies**."
|
| 92 |
-
- "How do you think these skills help students become better problem solvers?"
|
| 93 |
-
|
| 94 |
-
---
|
| 95 |
-
### **🔹 Creativity-Directed Practices Discussion**
|
| 96 |
-
*"Creativity is essential in math! Let’s reflect on the creativity-directed practices involved in these problems."*
|
| 97 |
-
|
| 98 |
-
- "What creativity-directed practices do you think were covered?"
|
| 99 |
-
|
| 100 |
-
🔹 **Possible Responses (AI guides based on teacher input):**
|
| 101 |
-
- **If the teacher mentions "Exploring multiple solutions," AI responds:**
|
| 102 |
-
- "Absolutely! Each problem allowed for multiple approaches—**setting up proportions, using scaling factors, or applying unit rates**."
|
| 103 |
-
- **If the teacher mentions "Making connections," AI responds:**
|
| 104 |
-
- "Yes! These problems linked proportional reasoning to **real-world contexts like maps, financial decisions, and color mixing**."
|
| 105 |
-
- **If the teacher mentions "Flexible Thinking," AI responds:**
|
| 106 |
-
- "Great insight! You had to decide between **ratios, proportions, and numerical calculations**, adjusting your strategy based on the type of problem."
|
| 107 |
-
- **If unsure, AI guides them:**
|
| 108 |
-
- "Key creative practices in this module included:
|
| 109 |
-
- **Exploring multiple approaches** to solving proportion problems.
|
| 110 |
-
- **Connecting math to real-life contexts** like money, distance, and color mixing.
|
| 111 |
-
- **Thinking flexibly**—adjusting strategies based on different types of proportional relationships."
|
| 112 |
-
- "How do you think encouraging creativity in problem-solving benefits students?"
|
| 113 |
-
"""
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
🔹 **Conclusion:**
|
| 72 |
- *The new paint mixture has a **stronger red color** than before.*
|
| 73 |
+
"""
|
| 74 |
|
| 75 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
### **🚀 Fully Updated `app.py` (Ensuring Proper OpenAI Handling & Math Formatting)**
|
| 78 |
+
```python
|
| 79 |
+
import os
|
| 80 |
+
import gradio as gr
|
| 81 |
+
from dotenv import load_dotenv
|
| 82 |
+
from openai import OpenAI
|
| 83 |
+
from prompts.initial_prompt import INITIAL_PROMPT
|
| 84 |
+
from prompts.main_prompt import MAIN_PROMPT, PROBLEM_SOLUTIONS_PROMPT # Ensure both are imported
|
| 85 |
+
|
| 86 |
+
# Load the API key from the .env file if available
|
| 87 |
+
if os.path.exists(".env"):
|
| 88 |
+
load_dotenv(".env")
|
| 89 |
+
|
| 90 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 91 |
+
|
| 92 |
+
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def gpt_call(history, user_message,
|
| 96 |
+
model="gpt-4o",
|
| 97 |
+
max_tokens=512,
|
| 98 |
+
temperature=0.7,
|
| 99 |
+
top_p=0.95):
|
| 100 |
+
"""
|
| 101 |
+
Calls the OpenAI API to generate a response.
|
| 102 |
+
- history: [(user_text, assistant_text), ...]
|
| 103 |
+
- user_message: The latest user message
|
| 104 |
+
"""
|
| 105 |
+
# 1) Start with the system message (MAIN_PROMPT) for context
|
| 106 |
+
messages = [{"role": "system", "content": MAIN_PROMPT}]
|
| 107 |
+
|
| 108 |
+
# 2) Append conversation history
|
| 109 |
+
for user_text, assistant_text in history:
|
| 110 |
+
if user_text:
|
| 111 |
+
messages.append({"role": "user", "content": user_text})
|
| 112 |
+
if assistant_text:
|
| 113 |
+
messages.append({"role": "assistant", "content": assistant_text})
|
| 114 |
+
|
| 115 |
+
# 3) Add the user's new message
|
| 116 |
+
messages.append({"role": "user", "content": user_message})
|
| 117 |
+
|
| 118 |
+
# 4) Call OpenAI API
|
| 119 |
+
completion = client.chat.completions.create(
|
| 120 |
+
model=model,
|
| 121 |
+
messages=messages,
|
| 122 |
+
max_tokens=max_tokens,
|
| 123 |
+
temperature=temperature,
|
| 124 |
+
top_p=top_p
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
return completion.choices[0].message.content
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def respond(user_message, history):
|
| 131 |
+
"""
|
| 132 |
+
Handles user input and gets GPT-generated response.
|
| 133 |
+
- user_message: The message from the user
|
| 134 |
+
- history: List of (user, assistant) conversation history
|
| 135 |
+
"""
|
| 136 |
+
if not user_message:
|
| 137 |
+
return "", history
|
| 138 |
+
|
| 139 |
+
# If the user asks for a solution, inject PROBLEM_SOLUTIONS_PROMPT
|
| 140 |
+
if "solution" in user_message.lower():
|
| 141 |
+
assistant_reply = gpt_call(history, PROBLEM_SOLUTIONS_PROMPT)
|
| 142 |
+
else:
|
| 143 |
+
assistant_reply = gpt_call(history, user_message)
|
| 144 |
+
|
| 145 |
+
# Add conversation turn to history
|
| 146 |
+
history.append((user_message, assistant_reply))
|
| 147 |
+
|
| 148 |
+
return "", history
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
##############################
|
| 152 |
+
# Gradio Blocks UI
|
| 153 |
+
##############################
|
| 154 |
+
with gr.Blocks() as demo:
|
| 155 |
+
gr.Markdown("## AI-Guided Math PD Chatbot")
|
| 156 |
+
|
| 157 |
+
# Chatbot initialization with the first AI message
|
| 158 |
+
chatbot = gr.Chatbot(
|
| 159 |
+
value=[("", INITIAL_PROMPT)], # Initial system prompt
|
| 160 |
+
height=500
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
# Stores the chat history
|
| 164 |
+
state_history = gr.State([("", INITIAL_PROMPT)])
|
| 165 |
+
|
| 166 |
+
# User input field
|
| 167 |
+
user_input = gr.Textbox(
|
| 168 |
+
placeholder="Type your message here...",
|
| 169 |
+
label="Your Input"
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
# Submit action
|
| 173 |
+
user_input.submit(
|
| 174 |
+
respond,
|
| 175 |
+
inputs=[user_input, state_history],
|
| 176 |
+
outputs=[user_input, chatbot]
|
| 177 |
+
).then(
|
| 178 |
+
fn=lambda _, h: h,
|
| 179 |
+
inputs=[user_input, chatbot],
|
| 180 |
+
outputs=[state_history]
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
# Run the Gradio app
|
| 184 |
+
if __name__ == "__main__":
|
| 185 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|