-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_server.py
More file actions
112 lines (96 loc) · 3.21 KB
/
web_server.py
File metadata and controls
112 lines (96 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
Flask web server for EduAgent demonstration
Provides a simple interface to interact with the agent
"""
from flask import Flask, render_template, request, jsonify
from flask_cors import CORS
import asyncio
import json
from typing import Optional
from models import QuestionRequest, ConceptType
app = Flask(__name__)
CORS(app)
# Global reference to agent (will be set when agent starts)
agent_instance = None
agent_address = None
def set_agent_instance(agent, address):
"""Set the agent instance for web server to use"""
global agent_instance, agent_address
agent_instance = agent
agent_address = address
@app.route('/')
def index():
"""Serve the main page"""
return render_template('index.html')
@app.route('/api/agent/info', methods=['GET'])
def get_agent_info():
"""Get information about the agent"""
if not agent_instance:
return jsonify({"error": "Agent not initialized"}), 500
return jsonify({
"name": agent_instance.name,
"address": agent_address,
"status": "active",
"capabilities": [
"answer_questions",
"explain_concepts",
"provide_practice_problems",
"track_student_progress"
]
})
@app.route('/api/ask', methods=['POST'])
def ask_question():
"""Submit a question to the agent"""
data = request.json
if not data or 'question' not in data:
return jsonify({"error": "Question is required"}), 400
question = data.get('question')
concept_type = data.get('concept_type', 'mathematics')
difficulty_level = data.get('difficulty_level', 'intermediate')
student_id = data.get('student_id')
try:
# Create question request
question_req = QuestionRequest(
question=question,
concept_type=ConceptType(concept_type),
difficulty_level=difficulty_level,
student_id=student_id
)
return jsonify({
"status": "success",
"message": "Question submitted to agent",
"question": question,
"request_id": student_id or "anonymous"
})
except Exception as e:
return jsonify({"error": str(e)}), 400
@app.route('/api/concepts', methods=['GET'])
def get_concepts():
"""Get available concept types"""
return jsonify({
"concepts": [
{"value": "mathematics", "label": "Mathematics"},
{"value": "programming", "label": "Programming"},
{"value": "algorithm", "label": "Algorithm"},
{"value": "data_structure", "label": "Data Structure"}
]
})
@app.route('/api/difficulty-levels', methods=['GET'])
def get_difficulty_levels():
"""Get available difficulty levels"""
return jsonify({
"levels": [
{"value": "beginner", "label": "Beginner"},
{"value": "intermediate", "label": "Intermediate"},
{"value": "advanced", "label": "Advanced"}
]
})
@app.route('/api/health', methods=['GET'])
def health_check():
"""Health check endpoint"""
return jsonify({
"status": "healthy",
"agent_running": agent_instance is not None
})
if __name__ == '__main__':
app.run(debug=True, port=5000)