Skip to content
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

New Writing Feedback Generator Expedition #126

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/api/tools_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
"6": {
"path": "features.syllabus_generator.core",
"metadata_file": "metadata.json"
},
"14": {
"path": "features.writing_feedback_generator.core",
"metadata_file": "metadata.json"
}
}
Empty file.
67 changes: 67 additions & 0 deletions app/features/writing_feedback_generator/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from app.features.writing_feedback_generator.tools import WritingFeedbackGeneratorPipeline
from app.services.schemas import WritingFeedbackGeneratorArgs
from app.utils.document_loaders import get_docs
from app.services.logger import setup_logger
from app.api.error_utilities import LoaderError, ToolExecutorError

logger = setup_logger()

def executor(grade_level: str,
assignment_description: str,
criteria: str,
writing_to_review: str,
criteria_file_url: str,
criteria_file_type: str,
wtr_file_url: str,
wtr_file_type: str,
lang: str,
verbose=False):

try:
if (criteria_file_type):
logger.info(f"Generating docs. from {criteria_file_type}")

if (wtr_file_type):
logger.info(f"Generating docs. from {wtr_file_type}")

docs = None

def fetch_docs(file_url, file_type):
return get_docs(file_url, file_type, True) if file_url and file_type else None

criteria_docs = fetch_docs(criteria_file_url, criteria_file_type)
wtr_docs = fetch_docs(wtr_file_url, wtr_file_type)

docs = (
criteria_docs + wtr_docs
if criteria_docs and wtr_docs
else criteria_docs or wtr_docs
)

writing_feedback_generator = WritingFeedbackGeneratorArgs(
grade_level=grade_level,
assignment_description=assignment_description,
criteria=criteria,
writing_to_review=writing_to_review,
criteria_file_url=criteria_file_url,
criteria_file_type=criteria_file_type,
wtr_file_url=wtr_file_url,
wtr_file_type=wtr_file_type,
lang=lang
)

output = WritingFeedbackGeneratorPipeline(args=writing_feedback_generator, verbose=verbose).generate_feedback(docs)

logger.info(f"Writing Feedback generated successfully")

except LoaderError as e:
error_message = e
logger.error(f"Error in Writing Feedback Generator Pipeline -> {error_message}")
raise ToolExecutorError(error_message)

except Exception as e:
error_message = f"Error in executor: {e}"
logger.error(error_message)
raise ValueError(error_message)

return output
49 changes: 49 additions & 0 deletions app/features/writing_feedback_generator/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"inputs": [
{
"label": "Grade Level",
"name": "grade_level",
"type": "text"
},
{
"label": "Assignment Description",
"name": "assignment_description",
"type": "text"
},
{
"label": "Rubric Criteria/Feedback Focus",
"name": "criteria",
"type": "text"
},
{
"label": "Writing to Review",
"name": "writing_to_review",
"type": "text"
},
{
"label": "Criteria File URL",
"name": "criteria_file_url",
"type": "text"
},
{
"label": "Criteria File Type",
"name": "criteria_file_type",
"type": "text"
},
{
"label": "Writing to Review File URL",
"name": "wtr_file_url",
"type": "text"
},
{
"label": "Writing to Review File Type",
"name": "wtr_file_type",
"type": "text"
},
{
"label": "Language",
"name": "lang",
"type": "text"
}
]
}
Empty file.
186 changes: 186 additions & 0 deletions app/features/writing_feedback_generator/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import pytest
from app.features.writing_feedback_generator.core import executor
from app.features.writing_feedback_generator.tools import WritingFeedback

# Base attributes reused across all tests
base_attributes = {
"grade_level": "university",
"assignment_description": "Review and provide feedback on the assigned text.",
"criteria": "",
"writing_to_review": "",
"criteria_file_url": "https://docs.google.com/document/d/1IsTPJSgWMdD20tXMm1sXJSCc0xz9Kxmn/edit?usp=sharing&ouid=107052763106493355624&rtpof=true&sd=true",
"criteria_file_type": "gdoc",
"lang": "en"
}

# PDF Tests
def test_executor_pdf_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/pdf/sample1.pdf",
wtr_file_type="pdf"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_pdf_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/pdf/sample1.pdf",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# CSV Tests
def test_executor_csv_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/csv/sample1.csv",
wtr_file_type="csv"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_csv_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/csv/sample1.csv",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# TXT Tests
def test_executor_txt_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/txt/sample1.txt",
wtr_file_type="txt"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_txt_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/txt/sample1.txt",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# MD Tests
def test_executor_md_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://github.com/radicalxdev/kai-ai-backend/blob/main/README.md",
wtr_file_type="md"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_md_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://github.com/radicalxdev/kai-ai-backend/blob/main/README.md",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# PPTX Tests
def test_executor_pptx_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://scholar.harvard.edu/files/torman_personal/files/samplepptx.pptx",
wtr_file_type="pptx"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_pptx_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://scholar.harvard.edu/files/torman_personal/files/samplepptx.pptx",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# DOCX Tests
def test_executor_docx_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/docx/sample1.docx",
wtr_file_type="docx"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_docx_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/docx/sample1.docx",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# XLS Tests
def test_executor_xls_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/xls/sample1.xls",
wtr_file_type="xls"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_xls_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/xls/sample1.xls",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# XLSX Tests
def test_executor_xlsx_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/xlsx/sample1.xlsx",
wtr_file_type="xlsx"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_xlsx_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://filesamples.com/samples/document/xlsx/sample1.xlsx",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# GPDF Tests
def test_executor_gpdf_wtr_url_valid():
writing_feedback = executor(
**base_attributes,
wtr_file_url="https://drive.google.com/file/d/1fUj1uWIMh6QZsPkt0Vs7mEd2VEqz3O8l/view",
wtr_file_type="gpdf"
)
assert isinstance(writing_feedback, WritingFeedback)

def test_executor_gpdf_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://drive.google.com/file/d/1fUj1uWIMh6QZsPkt0Vs7mEd2VEqz3O8l/view",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)

# MP3 Tests
def test_executor_mp3_wtr_url_invalid():
with pytest.raises(ValueError) as exc_info:
executor(
**base_attributes,
wtr_file_url="https://raw.githubusercontent.com/asleem/uploaded_files/main/dummy.mp3",
wtr_file_type=1
)
assert isinstance(exc_info.value, ValueError)
Loading