Spaces:
Sleeping
Sleeping
File size: 3,388 Bytes
217abc3 | 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 | from typing import List, Dict, Any
from openai import OpenAI
from models import BaseLearningObjective, LearningObjective
from .base_generation import generate_base_learning_objectives
from .enhancement import generate_incorrect_answer_options
from .grouping_and_ranking import group_base_learning_objectives, get_best_in_group_objectives
from .suggestion_improvement import regenerate_incorrect_answers
class LearningObjectiveGenerator:
"""Simple orchestrator for learning objective generation."""
def __init__(self, api_key: str, model: str = "gpt-5", temperature: float = 1.0):
self.client = OpenAI(api_key=api_key)
self.model = model
self.temperature = temperature
def generate_base_learning_objectives(self, file_contents: List[str], num_objectives: int) -> List[BaseLearningObjective]:
"""Generate base learning objectives without incorrect answer suggestions."""
return generate_base_learning_objectives(
self.client, self.model, self.temperature, file_contents, num_objectives
)
def group_base_learning_objectives(self, base_objectives: List[BaseLearningObjective], file_contents: List[str]) -> Dict[str, List]:
"""Group base learning objectives and identify the best in each group."""
return group_base_learning_objectives(
self.client, self.model, self.temperature, base_objectives, file_contents
)
def generate_incorrect_answer_options(self, file_contents: List[str], base_objectives: List[BaseLearningObjective], model_override: str = None) -> List[LearningObjective]:
"""Generate incorrect answer options for the given base learning objectives."""
return generate_incorrect_answer_options(
self.client, self.model, self.temperature, file_contents, base_objectives, model_override
)
def generate_and_group_learning_objectives(self, file_contents: List[str], num_objectives: int, model_override: str = None) -> Dict[str, List]:
"""Complete workflow: generate base objectives, group them, and generate incorrect answers only for best in group."""
# Step 1: Generate base learning objectives
base_objectives = self.generate_base_learning_objectives(file_contents, num_objectives)
# Step 2: Group base learning objectives and get best in group
grouped_result = self.group_base_learning_objectives(base_objectives, file_contents)
best_in_group_base = grouped_result["best_in_group"]
# Step 3: Generate incorrect answer suggestions only for best in group objectives
enhanced_best_objectives = self.generate_incorrect_answer_options(file_contents, best_in_group_base, model_override)
# Return both the full grouped list (without enhancements) and the enhanced best-in-group list
return {
"all_grouped": grouped_result["all_grouped"],
"best_in_group": enhanced_best_objectives
}
def regenerate_incorrect_answers(self, learning_objectives: List[LearningObjective], file_contents: List[str]) -> List[LearningObjective]:
"""Regenerate incorrect answer suggestions for learning objectives that need improvement."""
return regenerate_incorrect_answers(
self.client, self.model, self.temperature, learning_objectives, file_contents
) |