Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -123,6 +123,31 @@ You recognize that students may seek direct answers to homework, assignments, or
|
|
| 123 |
- **Encourage original thinking**: Help students develop their own reasoning and analytical skills
|
| 124 |
- **Suggest study strategies**: Recommend effective learning approaches for the subject matter
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
## Tool Usage
|
| 127 |
You have access to a create_graph tool. Use this tool naturally when a visual representation would enhance understanding or when discussing concepts that involve data, relationships, patterns, or quantitative information. Consider creating graphs for:
|
| 128 |
- Mathematical concepts (functions, distributions, relationships)
|
|
@@ -381,28 +406,75 @@ class Qwen25SmallLLM(LLM):
|
|
| 381 |
return "qwen25_small"
|
| 382 |
|
| 383 |
def create_langchain_agent():
|
|
|
|
|
|
|
|
|
|
| 384 |
# Use the smaller local model
|
| 385 |
llm = Qwen25SmallLLM()
|
| 386 |
|
| 387 |
-
|
|
|
|
| 388 |
memory = ConversationBufferWindowMemory(
|
| 389 |
memory_key="chat_history",
|
| 390 |
k=10,
|
| 391 |
return_messages=True
|
| 392 |
)
|
| 393 |
|
|
|
|
| 394 |
agent = initialize_agent(
|
| 395 |
tools=tools,
|
| 396 |
llm=llm,
|
| 397 |
-
agent=AgentType.
|
| 398 |
memory=memory,
|
| 399 |
-
verbose=False,
|
| 400 |
max_iterations=3,
|
| 401 |
early_stopping_method="generate"
|
| 402 |
)
|
| 403 |
|
|
|
|
| 404 |
return agent
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
# --- Global Agent Instance ---
|
| 407 |
agent = None
|
| 408 |
|
|
|
|
| 123 |
- **Encourage original thinking**: Help students develop their own reasoning and analytical skills
|
| 124 |
- **Suggest study strategies**: Recommend effective learning approaches for the subject matter
|
| 125 |
|
| 126 |
+
# Visual Learning Enhancement
|
| 127 |
+
You have the ability to create graphs and charts to enhance your explanations. Use this capability proactively when:
|
| 128 |
+
|
| 129 |
+
- Explaining mathematical concepts (functions, distributions, relationships)
|
| 130 |
+
- Teaching statistical analysis or data interpretation
|
| 131 |
+
- Discussing scientific trends, patterns, or experimental results
|
| 132 |
+
- Comparing different options, outcomes, or scenarios
|
| 133 |
+
- Illustrating economic principles, business metrics, or financial concepts
|
| 134 |
+
- Showing survey results, demographic data, or research findings
|
| 135 |
+
- Demonstrating any concept where visualization aids comprehension
|
| 136 |
+
|
| 137 |
+
**When to create graphs:**
|
| 138 |
+
- The concept involves numerical data or relationships
|
| 139 |
+
- Visual representation would clarify a complex idea
|
| 140 |
+
- Students benefit from seeing patterns or comparisons
|
| 141 |
+
- You're teaching about graph interpretation itself
|
| 142 |
+
- The topic involves trends, distributions, or proportions
|
| 143 |
+
- A multiple choice question requires a visual, such as a graph, to be answered.
|
| 144 |
+
|
| 145 |
+
**How to create graphs:**
|
| 146 |
+
Generate realistic, educational data that illustrates your teaching point. Create meaningful examples that help students understand the underlying concepts, not just random numbers.
|
| 147 |
+
|
| 148 |
+
Example: When explaining normal distribution, create a graph showing test scores distributed normally around a mean, with appropriate labels and educational context.
|
| 149 |
+
|
| 150 |
+
|
| 151 |
## Tool Usage
|
| 152 |
You have access to a create_graph tool. Use this tool naturally when a visual representation would enhance understanding or when discussing concepts that involve data, relationships, patterns, or quantitative information. Consider creating graphs for:
|
| 153 |
- Mathematical concepts (functions, distributions, relationships)
|
|
|
|
| 406 |
return "qwen25_small"
|
| 407 |
|
| 408 |
def create_langchain_agent():
|
| 409 |
+
"""Creates the LangChain agent with educational graph capabilities."""
|
| 410 |
+
logger.info("Creating educational LangChain agent...")
|
| 411 |
+
|
| 412 |
# Use the smaller local model
|
| 413 |
llm = Qwen25SmallLLM()
|
| 414 |
|
| 415 |
+
# Use the educational graph tool
|
| 416 |
+
tools = [create_educational_graph_tool()]
|
| 417 |
memory = ConversationBufferWindowMemory(
|
| 418 |
memory_key="chat_history",
|
| 419 |
k=10,
|
| 420 |
return_messages=True
|
| 421 |
)
|
| 422 |
|
| 423 |
+
# Use standard agent type
|
| 424 |
agent = initialize_agent(
|
| 425 |
tools=tools,
|
| 426 |
llm=llm,
|
| 427 |
+
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 428 |
memory=memory,
|
| 429 |
+
verbose=False, # Set to True for debugging
|
| 430 |
max_iterations=3,
|
| 431 |
early_stopping_method="generate"
|
| 432 |
)
|
| 433 |
|
| 434 |
+
logger.info("Educational LangChain agent created successfully!")
|
| 435 |
return agent
|
| 436 |
|
| 437 |
+
# Example of how the AI should use the tool
|
| 438 |
+
def example_usage_for_ai():
|
| 439 |
+
"""
|
| 440 |
+
This shows how the AI should autonomously create graphs in its responses.
|
| 441 |
+
The AI doesn't wait for user data - it creates meaningful educational examples.
|
| 442 |
+
"""
|
| 443 |
+
|
| 444 |
+
# Example: Teaching about normal distribution
|
| 445 |
+
example_config = {
|
| 446 |
+
"data": {
|
| 447 |
+
"Below 60": 5,
|
| 448 |
+
"60-70": 15,
|
| 449 |
+
"70-80": 25,
|
| 450 |
+
"80-90": 35,
|
| 451 |
+
"90-100": 20
|
| 452 |
+
},
|
| 453 |
+
"plot_type": "bar",
|
| 454 |
+
"title": "Typical Test Score Distribution",
|
| 455 |
+
"x_label": "Score Range",
|
| 456 |
+
"y_label": "Number of Students",
|
| 457 |
+
"educational_context": "This shows how test scores often follow a bell-curve pattern, with most students scoring in the middle range."
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
# Example: Teaching about compound interest
|
| 461 |
+
compound_interest_example = {
|
| 462 |
+
"data": {
|
| 463 |
+
"Year 1": 1000,
|
| 464 |
+
"Year 5": 1276,
|
| 465 |
+
"Year 10": 1629,
|
| 466 |
+
"Year 15": 2079,
|
| 467 |
+
"Year 20": 2653
|
| 468 |
+
},
|
| 469 |
+
"plot_type": "line",
|
| 470 |
+
"title": "Compound Interest Growth ($1000 at 5% Annual)",
|
| 471 |
+
"x_label": "Time (Years)",
|
| 472 |
+
"y_label": "Account Value ($)",
|
| 473 |
+
"educational_context": "Notice how the growth accelerates over time - this is the power of compound interest!"
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
return "These examples show how the AI creates educational data to illustrate concepts"
|
| 477 |
+
|
| 478 |
# --- Global Agent Instance ---
|
| 479 |
agent = None
|
| 480 |
|