EnCoach Odoo 19 custom modules
Full backend implementation with custom Odoo modules: - encoach_api: Core API, user management, JWT auth - encoach_exam: Exam generation (reading, writing, listening, speaking) - encoach_evaluate: AI-powered evaluation (writing, speaking) - encoach_training: Training tips and walkthrough - encoach_storage: File storage management - encoach_payment: Stripe, PayPal, Paymob integration - encoach_mail: Email notifications Made-with: Cursor
This commit is contained in:
65
encoach_api/controllers/grading.py
Normal file
65
encoach_api/controllers/grading.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
|
||||
from .base import EncoachMixin
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GradingController(EncoachMixin, http.Controller):
|
||||
|
||||
# ------------------------------------------------- grade multiple
|
||||
@http.route('/api/grading/multiple', type='http', auth='public', methods=['POST', 'OPTIONS'], csrf=False, cors='*')
|
||||
def grade_multiple(self, **kwargs):
|
||||
"""Grade multiple short-answer exercises using GPT-4o."""
|
||||
try:
|
||||
user = self._authenticate()
|
||||
if not user:
|
||||
return self._error_response('Unauthorized', 401)
|
||||
|
||||
body = self._get_json_body()
|
||||
text = body.get('text', '')
|
||||
questions = body.get('questions', [])
|
||||
answers = body.get('answers', [])
|
||||
|
||||
if not questions or not answers:
|
||||
return self._error_response('questions and answers are required', 400)
|
||||
if len(questions) != len(answers):
|
||||
return self._error_response('questions and answers must have the same length', 400)
|
||||
|
||||
GradingService = request.env['encoach.ai.grading'].sudo()
|
||||
result = GradingService.grade_short_answers(
|
||||
text=text,
|
||||
questions=questions,
|
||||
answers=answers,
|
||||
)
|
||||
|
||||
return self._json_response({'exercises': result})
|
||||
except Exception:
|
||||
_logger.exception("Grade multiple error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
|
||||
# ------------------------------------------------ grading summary
|
||||
@http.route('/api/exam/grade/summary', type='http', auth='public', methods=['POST', 'OPTIONS'], csrf=False, cors='*')
|
||||
def grading_summary(self, **kwargs):
|
||||
"""Generate a grading summary for a full exam session."""
|
||||
try:
|
||||
user = self._authenticate()
|
||||
if not user:
|
||||
return self._error_response('Unauthorized', 401)
|
||||
|
||||
body = self._get_json_body()
|
||||
sections = body.get('sections', [])
|
||||
if not sections:
|
||||
return self._error_response('sections array is required', 400)
|
||||
|
||||
GradingService = request.env['encoach.ai.grading'].sudo()
|
||||
result = GradingService.generate_grading_summary(sections=sections)
|
||||
|
||||
return self._json_response({'sections': result})
|
||||
except Exception:
|
||||
_logger.exception("Grading summary error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
Reference in New Issue
Block a user