class_factory.utils package
class_factory.utils.llm_validator module
- class class_factory.utils.llm_validator.Validator(llm: Any, parser: Any, temperature: float = 0.6, log_level=20)[source]
Bases:
object
A class for validating responses generated by an LLM (Language Model).
The Validator checks the accuracy, completeness, and relevance of the LLM’s response to ensure it meets the requirements specified in the task prompt. Validation results include a score, status, reasoning, and any additional guidance.
- validate(task_description: str, generated_response: str, specific_guidance: str = '', min_eval_score: int = 8) Dict[str, Any] [source]
Validates a generated response by providing the task description, the generated response, and any specific guidance for evaluation.
- Parameters:
task_description (str) – Description of the task that the LLM was originally given.
generated_response (str) – The output generated by the LLM that needs validation.
specific_guidance (str, optional) – Additional guidance for the LLM during validation. Defaults to “”.
min_eval_score (int, optional) – Minimum score required for a valid response. Affects the status in the return value. Defaults to 8.
- Returns:
- Validation result containing:
evaluation_score (float): Score from 0.0 to 10.0 based on response quality
status (int): 1 if score >= min_eval_score, 0 otherwise
reasoning (str): Explanation of the assigned score
additional_guidance (str): Improvement suggestions if status is 0, empty string otherwise
- Return type:
Dict[str, Any]
class_factory.utils.base_model module
- class class_factory.utils.base_model.BaseModel(lesson_no: int, course_name: str, lesson_loader: LessonLoader, output_dir: Path | str = None, verbose: bool = False)[source]
Bases:
object
A base class for educational modules that provides common setup and utility functions, such as loading lesson readings and setting user-defined objectives.
- lesson_no
The specific lesson number for the current instance.
- Type:
int
- course_name
Name of the course, used as context in other methods and prompts.
- Type:
str
- lesson_loader
Instance for loading lesson-related data.
- Type:
LessonLoader
- output_dir
Directory where outputs are saved; defaults to ‘ClassFactoryOutput’.
- Type:
Path
- logger
Logger instance for the class.
- Type:
Logger
- user_objectives
Dictionary of user-defined objectives, if provided.
- Type:
Optional[Dict[str, str]]
- _load_readings(lesson_numbers
Union[int, range]) -> Dict[str, List[str]]: Loads and returns readings for the specified lesson(s) as a dictionary.
- set_user_objectives(objectives
Union[List[str], Dict[str, str]], lesson_range: Union[int, range]) -> Dict[str, str]: Sets user-defined objectives for each lesson in the specified range and updates self.user_objectives.
- _get_lesson_objectives(lesson_num
int) -> str: Retrieves lesson objectives for a given lesson number, falling back to extracted objectives if no user objectives exist.
- set_user_objectives(objectives: List[str] | Dict[str, str], lesson_range: int | range) Dict[str, str] [source]
Set user-defined objectives for each lesson in lesson_range, supporting both list and dictionary formats. Updates the self.user_objectives attribute with the processed objectives.
- Parameters:
objectives (Union[List[str], Dict[str, str]]) – User-provided objectives, either as a list (converted to a dictionary) or as a dictionary keyed by lesson numbers as strings.
lesson_range (Union[int, range]) – Single lesson number or range of lesson numbers for objectives.
- Returns:
Processed dictionary of user objectives keyed by lesson numbers as strings.
- Return type:
Dict[str, str]
- Raises:
ValueError – If the number of objectives in the list does not match the number of lessons in lesson_range.
TypeError – If objectives is neither a list nor a dictionary.