-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Epic 7.7.1: Syllabus Generator - Logic Legion #84
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 8c57a59.
Includes LLM validaion
added updated files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see changes
.gitignore
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the PDF to include a summary of what the tests were and what edge cases were accounted for
""" | ||
try: | ||
# Assuming reponse is already a dict | ||
if not isinstance(response, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from pydantic import BaseModel, Field, model_validator
from typing import Optional
from typing_extensions import Annotation
class LLMOutput(BaseModel):
title: str
overview: str
description: Annotation[str, Field(default="This is a default desc.")]
assignments: Annotation[List[Assignment], Field(default_factory=list)]
....
Pydantic for validation can be useful here for validating the output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find any documentation on Annotation
but I found Annotated
, I assume this is what you meant.
Should I use this over just Field
in model.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it still useful to have a default values if, depending on the input options, some fields are not returned at all and are typed as Optional
?
Or is the current implementation sufficient?
if not isinstance(key, str) or not isinstance(value, str): | ||
print(6) | ||
return False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need to validate response fields with Pydantic's model_validator
from pydantic import BaseModel, model_validator, Field
class MultipleChoiceQuestion(BaseModel):
answer: str
choices: List[str]
@model_validator()
def validate_answer(cls, v):
# Checks to make sure answer exists in the choice
assert answer in choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have replaced the response validation code by simply calling SyllabusModel(**response)
, which does all of the validation for me.
This should be enough for now.
flake.lock
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is needed to be committed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sure everyone is using the same versions of packages.
Can be updated using nix flake update
.
The whole flake.nix is more of a quality of life addition for those familiar with nix.
It can be extended to run the whole backend in a declarative environment using nix run
.
I watched the code review and I appreciate the feedback by the way 👍. |
Syllabus Generator
Summary:
options
api parameter.Changes:
features/
containing:tools.py
includesSyllabusBuilder
class responsible for all logic involved in using the LLM to create the syllabus.model.py
includes the Pydantic model for validating output.core.py
includes the executor function.metadata.json
includes expected inputs for the api.prompt/
includes various text files for prompt generation.tests/
includestest_sb.py
used for testing all components of the SyllabusBuilder as well astest.json
which includes a sample input for the api.tools_config.json
to be able to access the syllabus_generator straight from the api.flake.nix
for better LSP support and simplified environment set up.nix develop
and--command <prefered shell>
to enter env.bash
is default.Example:
Input
Output
Test Coverage
Input Validation Tests:
•
test_invalid_input
: Ensures that invalid inputs such as an empty subject ormissing grade level raise appropriate errors.
•
test_valid_model
andtest_invalid_model
: Validates the Pydantic model(SyllabusModel) to ensure that it correctly accepts valid data and raises
errors for missing or incorrect fields.
Functionality Tests:
•
test_create_prompt_temp_with_mocked_read_text_file
: Checks if thecreate_prompt_temp
function correctly assigns the appropriate gradingpolicy based on the grade level, using mock inputs to simulate different
school levels.
•
test_compile
: Verifies that the compile function correctly generates theprompt and model chain based on the type of compilation ("customization"
or "syllabus").
•
test_validate_response_valid
andtest_validate_response_invalid
: Checksthe
validate_response
method to ensure it correctly identifies valid andinvalid syllabus structures.
How Tests Were Conducted
The tests were conducted using the pytest framework, which provides a
robust environment for running test cases. This includes using fixtures for
setting up test cases (sb fixture for the SyllabusBuilder instance) and
mocking functions to simulate and control the behavior of dependencies.
Cases Covered
Input validation to ensure that the correct types and values are passed.
Prompt creation based on different grade levels to ensure the proper
grading policies are applied.
Syllabus compilation to ensure that the model and prompt chains are
correctly assembled and invoked.
Model validation to confirm that the syllabus structure adheres to the
expected schema.
Response validation to make sure that the generated syllabus meets all
necessary requirements.
Code Snippets
Input Validation Tests
test_invalid_input
:test_valid_model
andtest_invalid_model
:Functionality Tests
test_compile
:Testing documentation by @ElyasBinothman
Documentation made by team members
Syllabus Generator.pdf @YomnaEisa