Spaces:
Sleeping
Sleeping
Update prompts/main_prompt.py
Browse files69 unmodified lines7071727374757576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211376777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418569 unmodified lines
🔹 **Conclusion:** - *The new paint mixture has a **stronger red color** than before.*"""
---### **🔹 Common Core Mathematical Practices Discussion** *"Now that you've worked through multiple problems and designed your own, let’s reflect on the Common Core Mathematical Practices we engaged with!"*
- "Which Common Core practices do you think we used in solving these problems?"
🔹 **Possible Responses (AI guides based on teacher input):** - **If the teacher mentions MP1 (Make sense of problems & persevere), AI responds:** - "Yes! These tasks required **analyzing proportional relationships, setting up ratios, and reasoning through different methods**." - **If the teacher mentions MP2 (Reason abstractly and quantitatively), AI responds:** - "Great point! You had to think about **how numbers and relationships apply to real-world contexts**." - **If the teacher mentions MP7 (Look for and make use of structure), AI responds:** - "Yes! Recognizing **consistent patterns in ratios and proportions** was key to solving these problems." - **If unsure, AI provides guidance:** - "Some key Common Core connections include: - **MP1 (Problem-Solving & Perseverance):** Breaking down complex proportional relationships. - **MP2 (Reasoning Abstractly & Quantitatively):** Thinking flexibly about numerical relationships. - **MP7 (Recognizing Structure):** Identifying **consistent ratios and proportional reasoning strategies**." - "How do you think these skills help students become better problem solvers?"
---### **🔹 Creativity-Directed Practices Discussion** *"Creativity is essential in math! Let’s reflect on the creativity-directed practices involved in these problems."*
- "What creativity-directed practices do you think were covered?"
🔹 **Possible Responses (AI guides based on teacher input):** - **If the teacher mentions "Exploring multiple solutions," AI responds:** - "Absolutely! Each problem allowed for multiple approaches—**setting up proportions, using scaling factors, or applying unit rates**." - **If the teacher mentions "Making connections," AI responds:** - "Yes! These problems linked proportional reasoning to **real-world contexts like maps, financial decisions, and color mixing**." - **If the teacher mentions "Flexible Thinking," AI responds:** - "Great insight! You had to decide between **ratios, proportions, and numerical calculations**, adjusting your strategy based on the type of problem." - **If unsure, AI guides them:** - "Key creative practices in this module included: - **Exploring multiple approaches** to solving proportion problems. - **Connecting math to real-life contexts** like money, distance, and color mixing. - **Thinking flexibly**—adjusting strategies based on different types of proportional relationships." - "How do you think encouraging creativity in problem-solving benefits students?" """
### **🚀 Fully Updated `app.py` (Ensuring Proper OpenAI Handling & Math Formatting)**```pythonimport osimport gradio as grfrom dotenv import load_dotenvfrom openai import OpenAIfrom prompts.initial_prompt import INITIAL_PROMPTfrom prompts.main_prompt import MAIN_PROMPT, PROBLEM_SOLUTIONS_PROMPT # Ensure both are imported
# Load the API key from the .env file if availableif os.path.exists(".env"): load_dotenv(".env")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=OPENAI_API_KEY)
def gpt_call(history, user_message, model="gpt-4o", max_tokens=512, temperature=0.7, top_p=0.95): """ Calls the OpenAI API to generate a response. - history: [(user_text, assistant_text), ...] - user_message: The latest user message """ # 1) Start with the system message (MAIN_PROMPT) for context messages = [{"role": "system", "content": MAIN_PROMPT}]
# 2) Append conversation history for user_text, assistant_text in history: if user_text: messages.append({"role": "user", "content": user_text}) if assistant_text: messages.append({"role": "assistant", "content": assistant_text})
# 3) Add the user's new message messages.append({"role": "user", "content": user_message})
# 4) Call OpenAI API completion = client.chat.completions.create( model=model, messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p )
return completion.choices[0].message.content
def respond(user_message, history): """ Handles user input and gets GPT-generated response. - user_message: The message from the user - history: List of (user, assistant) conversation history """ if not user_message: return "", history
# If the user asks for a solution, inject PROBLEM_SOLUTIONS_PROMPT if "solution" in user_message.lower(): assistant_reply = gpt_call(history, PROBLEM_SOLUTIONS_PROMPT) else: assistant_reply = gpt_call(history, user_message)
# Add conversation turn to history history.append((user_message, assistant_reply))
return "", history
############################### Gradio Blocks UI##############################with gr.Blocks() as demo: gr.Markdown("## AI-Guided Math PD Chatbot")
# Chatbot initialization with the first AI message chatbot = gr.Chatbot( value=[("", INITIAL_PROMPT)], # Initial system prompt height=500 )
# Stores the chat history state_history = gr.State([("", INITIAL_PROMPT)])
# User input field user_input = gr.Textbox( placeholder="Type your message here...", label="Your Input" )
# Submit action user_input.submit( respond, inputs=[user_input, state_history], outputs=[user_input, chatbot] ).then( fn=lambda _, h: h, inputs=[user_input, chatbot], outputs=[state_history] )
# Run the Gradio appif __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860, share=True)prompts/main_prompt.py+110-39