Skip to content

Improved Question Generation with Automated Retries & Sanity Checks#72

Open
MukeshAofficial wants to merge 11 commits intosatvik314:mainfrom
MukeshAofficial:Sanity
Open

Improved Question Generation with Automated Retries & Sanity Checks#72
MukeshAofficial wants to merge 11 commits intosatvik314:mainfrom
MukeshAofficial:Sanity

Conversation

@MukeshAofficial
Copy link
Copy Markdown
Contributor

@MukeshAofficial MukeshAofficial commented Mar 11, 2025

Description:

Modified the question generation function for better efficiency.
Added automated retries to handle failures gracefully.
Implemented batch-wise question generation for optimized processing.
Introduced a sanity check function to ensure output quality.
Changes:

🔄 Refactored question generation logic.
🔁 Added automated retry mechanism.
📦 Enabled batch-wise processing.
✅ Implemented a sanity check function.

Summary by CodeRabbit

  • New Features

    • Enhanced question generation with batch processing, retry mechanisms, and CSV import support.
    • Introduced comprehensive sanity checks with detailed evaluation of question quality and optional auto-correction.
    • Added summary reports that aggregate evaluation results for clearer feedback.
    • Improved prompt customization including learning objectives and difficulty levels.
  • Chores

    • Removed the starter guide notebook for question generation.
    • Updated documentation links for smoother navigation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 11, 2025

Walkthrough

This pull request introduces new Pydantic models SanityCheckResult and SanityCheckSummary for detailed question evaluation and summary reporting. It refactors import statements in educhain/models/__init__.py to include these models. The QnAEngine class in educhain/engines/qna_engine.py is extensively enhanced with batch question generation, CSV loading, a robust sanity check with auto-correction, and related helper methods. The starter guide notebook is removed, and a minor README badge link update is made.

Changes

File(s) Change Summary
educhain/models/init.py Reformatted import statements to multi-line style; added exports for SanityCheckResult and SanityCheckSummary.
educhain/models/qna_models.py Added new Pydantic classes SanityCheckResult and SanityCheckSummary capturing detailed question evaluation data and aggregate summaries with a display method.
educhain/engines/qna_engine.py Major enhancements to QnAEngine: batch question generation with retries, CSV question loading, comprehensive sanity_check method with auto-correction and retries, new helper methods (_generate_batch, _correct_question), and added SanityCheckResult and SanityCheckSummary classes. Also improved prompt handling and duplicate detection.
README.md Updated the URL fragment identifier in the "Open In Colab" badge link in the Starter Guide section.
cookbook/starters/Starter_guide_question_generation.ipynb Deleted the entire notebook that served as a comprehensive starter guide for question generation using the Educhain package.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Caller
    participant Engine as QnAEngine
    participant Result as SanityCheckResult
    participant Summary as SanityCheckSummary
    Client->>Engine: Call sanity_check(question_list, options)
    Engine->>Result: Evaluate each question, create SanityCheckResult(s)
    Engine->>Engine: Auto-correct failed questions if enabled
    Engine->>Summary: Aggregate results into SanityCheckSummary
    Engine->>Client: Return SanityCheckSummary
    Client->>Summary: Optionally call show() to display results
Loading

Possibly related PRs

  • Revert "added bulk generation function" #97: Related code reintroduces and extends bulk question generation, validation, and sanity check models previously removed, closely connected to the new batch processing and sanity check features.

Poem

🐇 Hopping through code with a curious mind,
Questions and answers, all neatly aligned.
Sanity checks keep the errors at bay,
Auto-correcting as I bounce on my way.
With batches and retries, the questions grow bright,
In Educhain’s garden, I leap with delight! 🌱✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
educhain/models/__init__.py (2)

2-6: Consider pruning unused imports or exporting them.

Several imports (MultipleChoiceQuestion, ShortAnswerQuestion, TrueFalseQuestion, FillInBlankQuestion, MCQList, ShortAnswerQuestionList, TrueFalseQuestionList, FillInBlankQuestionList, Option, MCQMath, MCQListMath, SanityCheckResult, SanityCheckSummary) appear unused in this module. Consider removing them or adding them to an __all__ list to clarify their intended usage and reduce lint warnings.

Example removal for unused imports:

-from .qna_models import (
-    MultipleChoiceQuestion, ShortAnswerQuestion, TrueFalseQuestion, FillInBlankQuestion,
-    MCQList, ShortAnswerQuestionList, TrueFalseQuestionList, FillInBlankQuestionList,
-    Option, MCQMath, MCQListMath, SanityCheckResult, SanityCheckSummary
-)
+from .qna_models import (
+    SanityCheckResult, SanityCheckSummary
+)
🧰 Tools
🪛 Ruff (0.8.2)

3-3: .qna_models.MultipleChoiceQuestion imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


3-3: .qna_models.ShortAnswerQuestion imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


3-3: .qna_models.TrueFalseQuestion imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


3-3: .qna_models.FillInBlankQuestion imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


4-4: .qna_models.MCQList imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


4-4: .qna_models.ShortAnswerQuestionList imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


4-4: .qna_models.TrueFalseQuestionList imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


4-4: .qna_models.FillInBlankQuestionList imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.Option imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.MCQMath imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.MCQListMath imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.SanityCheckResult imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.SanityCheckSummary imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: Consider pruning unused imports or exporting them.

The imports from .content_models in this line do not appear to be referenced in this file. You might remove them or export them in __all__ if you intend to make them publicly accessible.

🧰 Tools
🪛 Ruff (0.8.2)

7-7: .content_models.ContentElement imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.SubTopic imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.MainTopic imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.LessonPlan imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.Flashcard imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.FlashcardSet imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

educhain/models/qna_models.py (1)

153-191: Remove unnecessary f-string prefix.

Line 173 uses an f-string but does not include any substitution placeholders. This triggers a static analysis warning. You can safely remove the f prefix:

- print(f"Sanity Check Summary")
+ print("Sanity Check Summary")
🧰 Tools
🪛 Ruff (0.8.2)

173-173: f-string without any placeholders

Remove extraneous f prefix

(F541)

educhain/engines/qna_engine.py (3)

26-29: Remove the unused VisualMCQ import.

Static analysis indicates that VisualMCQ is imported but never used in this file. Removing unused imports keeps the codebase clean:

-from educhain.models.qna_models import (
-    MCQList, ShortAnswerQuestionList, TrueFalseQuestionList,
-    FillInBlankQuestionList, MCQListMath, Option ,SolvedDoubt, SpeechInstructions,
-    VisualMCQList, VisualMCQ, BulkMCQ, BulkMCQList,
-    SanityCheckSummary, SanityCheckResult,
-    MultipleChoiceQuestion, ShortAnswerQuestion, TrueFalseQuestion, FillInBlankQuestion
+from educhain.models.qna_models import (
+    MCQList, ShortAnswerQuestionList, TrueFalseQuestionList,
+    FillInBlankQuestionList, MCQListMath, Option, SolvedDoubt, SpeechInstructions,
+    VisualMCQList, BulkMCQ, BulkMCQList,
+    SanityCheckSummary, SanityCheckResult,
+    MultipleChoiceQuestion, ShortAnswerQuestion, TrueFalseQuestion, FillInBlankQuestion
)
🧰 Tools
🪛 Ruff (0.8.2)

26-26: educhain.models.qna_models.VisualMCQ imported but unused

Remove unused import

(F401)


1362-1362: Remove extraneous f-string.

Line 1362 references an f-string without placeholders:

- additional_fields = f"Options:\n" + "\n".join(failed_result.options)
+ additional_fields = "Options:\n" + "\n".join(failed_result.options)
🧰 Tools
🪛 Ruff (0.8.2)

1362-1362: f-string without any placeholders

Remove extraneous f prefix

(F541)


1429-1429: Unused variable assignment.

response_model at line 1429 is never used. To eliminate confusion, remove the assignment:

- response_model = self._get_response_model(question_type)
🧰 Tools
🪛 Ruff (0.8.2)

1429-1429: Local variable response_model is assigned to but never used

Remove assignment to unused variable response_model

(F841)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b92e6d6 and 4f995d0.

📒 Files selected for processing (4)
  • educhain/models/__init__.py (1 hunks)
  • educhain/models/qna_models.py (1 hunks)
  • educhain/engines/qna_engine.py (6 hunks)
  • educhain/engines/qna_engine.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
educhain/models/__init__.py

3-3: .qna_models.MultipleChoiceQuestion imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


3-3: .qna_models.ShortAnswerQuestion imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


3-3: .qna_models.TrueFalseQuestion imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


3-3: .qna_models.FillInBlankQuestion imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


4-4: .qna_models.MCQList imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


4-4: .qna_models.ShortAnswerQuestionList imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


4-4: .qna_models.TrueFalseQuestionList imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


4-4: .qna_models.FillInBlankQuestionList imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.Option imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.MCQMath imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.MCQListMath imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.SanityCheckResult imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


5-5: .qna_models.SanityCheckSummary imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.ContentElement imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.SubTopic imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.MainTopic imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.LessonPlan imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.Flashcard imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .content_models.FlashcardSet imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

educhain/models/qna_models.py

173-173: f-string without any placeholders

Remove extraneous f prefix

(F541)

educhain/engines/qna_engine.py

26-26: educhain.models.qna_models.VisualMCQ imported but unused

Remove unused import

(F401)


1362-1362: f-string without any placeholders

Remove extraneous f prefix

(F541)


1429-1429: Local variable response_model is assigned to but never used

Remove assignment to unused variable response_model

(F841)

🔇 Additional comments (12)
educhain/engines/qna_engine.py (12)

5-5: No significant change detected.


41-42: Good import addition.

The new imports time and csv are used later for retry backoff and CSV operations, respectively. This is appropriate.


123-131: Automatic model selection looks good.

The _get_response_model dictionary is straightforward and covers all question types. Defaulting to MCQList for unrecognized input is acceptable.


132-140: Single-response model fallback is sufficient.

Similarly, _get_single_response_model covers known question types, defaulting to MultipleChoiceQuestion. This is consistent with the multi-response approach.


374-375: Feature acceptance: batch parameters.

Introducing batch_size and max_retries_per_batch is a good way to improve reliability and performance in question generation.


380-381: Clear docstring improvement.

The updated docstring accurately reflects automated retries and batch generation.


384-420: Incremental question generation logic.

The while loop logic and batch retry flow are well-structured, ensuring partial results are accumulated.


422-426: Final question slicing.

Capping the accumulated questions to the requested number prevents over-generation. Looks good.


1207-1264: New _generate_batch method.

The helper method is neatly modularized: prompts, parse, and returns. This structure is consistent and maintainable.


1266-1321: CSV loader is adequately structured.

load_questions_from_csv properly constructs different question models. CSV columns align well with each question type.


1323-1406: Automatic question correction is well-implemented.

The _correct_question method is a helpful approach for iterative question refinement. Retries guard against parse failures.

🧰 Tools
🪛 Ruff (0.8.2)

1362-1362: f-string without any placeholders

Remove extraneous f prefix

(F541)


1408-1567: Complete sanity check process.

The expanded sanity_check method with retries, auto-correction, and summary building is comprehensive. Implementation details appear correct and consistent with the new data models.

🧰 Tools
🪛 Ruff (0.8.2)

1429-1429: Local variable response_model is assigned to but never used

Remove assignment to unused variable response_model

(F841)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🔭 Outside diff range comments (1)
educhain/engines/qna_engine.py (1)

37-37: ⚠️ Potential issue

Remove duplicate csv import

The csv module is imported twice - once on line 37 and again on line 43. Remove the duplicate import.

 import csv
 import matplotlib.pyplot as plt
 import pandas as pd
 import dataframe_image as dfi
 from IPython.display import display, HTML
 import time
-import csv

Also applies to: 43-43

🧹 Nitpick comments (1)
educhain/models/qna_models.py (1)

159-160: Remove unnecessary f-string prefix

The f-string on line 160 doesn't contain any placeholders, making the 'f' prefix unnecessary.

-        print("=" * 80)
-        print(f"Sanity Check Summary")
+        print("=" * 80)
+        print("Sanity Check Summary")
🧰 Tools
🪛 Ruff (0.11.9)

160-160: f-string without any placeholders

Remove extraneous f prefix

(F541)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f995d0 and c4e902e.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • cookbook/starters/Starter_guide_question_generation.ipynb (0 hunks)
  • educhain/engines/qna_engine.py (13 hunks)
  • educhain/models/qna_models.py (1 hunks)
💤 Files with no reviewable changes (1)
  • cookbook/starters/Starter_guide_question_generation.ipynb
✅ Files skipped from review due to trivial changes (1)
  • README.md
🧰 Additional context used
🧬 Code Graph Analysis (2)
educhain/engines/qna_engine.py (2)
educhain/models/qna_models.py (21)
  • SanityCheckSummary (152-177)
  • SanityCheckResult (142-150)
  • MCQList (69-70)
  • ShortAnswerQuestionList (72-73)
  • TrueFalseQuestionList (75-76)
  • FillInBlankQuestionList (78-79)
  • MultipleChoiceQuestion (6-16)
  • ShortAnswerQuestion (44-51)
  • TrueFalseQuestion (53-59)
  • FillInBlankQuestion (61-67)
  • show (9-16)
  • show (34-38)
  • show (47-51)
  • show (56-59)
  • show (64-67)
  • show (91-97)
  • show (102-105)
  • show (121-133)
  • show (158-177)
  • show (233-240)
  • show (268-275)
archive/models.py (9)
  • MCQList (75-76)
  • ShortAnswerQuestionList (78-79)
  • TrueFalseQuestionList (81-82)
  • FillInBlankQuestionList (84-85)
  • MultipleChoiceQuestion (30-40)
  • ShortAnswerQuestion (42-49)
  • TrueFalseQuestion (51-57)
  • FillInBlankQuestion (59-65)
  • show (23-28)
educhain/models/qna_models.py (2)
educhain/engines/qna_engine.py (3)
  • SanityCheckResult (1262-1270)
  • SanityCheckSummary (1272-1298)
  • show (1278-1298)
archive/experimental.py (1)
  • show (220-226)
🪛 Ruff (0.11.9)
educhain/engines/qna_engine.py

1299-1299: SyntaxError: Expected a statement


1299-1299: SyntaxError: Expected a statement


1299-1299: SyntaxError: Expected a statement


1299-1299: SyntaxError: Expected a statement


2153-2153: SyntaxError: Expected a statement

educhain/models/qna_models.py

160-160: f-string without any placeholders

Remove extraneous f prefix

(F541)

🔇 Additional comments (4)
educhain/models/qna_models.py (1)

142-178: Well-structured Pydantic models for sanity check functionality

The new SanityCheckResult and SanityCheckSummary models are well-designed with clear field descriptions and a useful show() method for formatted output display.

🧰 Tools
🪛 Ruff (0.11.9)

160-160: f-string without any placeholders

Remove extraneous f prefix

(F541)

educhain/engines/qna_engine.py (3)

225-225: Good improvement to text splitter overlap

Increasing the chunk overlap from 0 to 200 characters will provide better context continuity when splitting text for vector store creation.


401-462: Excellent implementation of batch generation with retries

The enhanced generate_questions method now includes:

  • Batch processing to avoid overwhelming the LLM
  • Automatic retry logic with backoff
  • Dynamic batch size reduction on failures
  • Proper accumulation and trimming of results

This makes the question generation process more robust and reliable.


1097-1257: Comprehensive sanity check implementation

The sanity_check method provides excellent functionality:

  • Batch processing for efficiency
  • Detailed validation of answer correctness, clarity, and distractor plausibility
  • Auto-correction of failed questions
  • Retry logic for resilience
  • In-place updates when auto_correct is enabled

This significantly improves the quality assurance of generated questions.

print(f" Question Clarity: {result.question_clarity}")
print(f" Distractor Plausibility: {result.distractor_plausibility}")
print(f" Passed: {result.passed}\n")
=======
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Resolve merge conflict

There's an unresolved merge conflict marker (=======) on line 1299. This needs to be resolved by choosing the appropriate code version and removing the conflict markers.

🧰 Tools
🪛 Ruff (0.11.9)

1299-1299: SyntaxError: Expected a statement


1299-1299: SyntaxError: Expected a statement


1299-1299: SyntaxError: Expected a statement


1299-1299: SyntaxError: Expected a statement


1299-1300: SyntaxError: Expected a statement

🤖 Prompt for AI Agents
In educhain/engines/qna_engine.py at line 1299, there is an unresolved merge
conflict marker (`=======`). Remove this marker and resolve the conflict by
selecting the correct code version to keep, ensuring the file is clean and
syntactically correct.

Comment on lines +1373 to +1384
}

validated_question = self._validate_individual_question(q_dict, question_model=question_model)
if validated_question:
batch_validated_questions.append(validated_question)

# Add to existing questions to prevent duplicates in future batches
if csv_output_file:
for field in ['question', 'question_text', 'stem', 'prompt']:
if field in q_dict and q_dict[field]:
existing_questions.add(q_dict[field].strip())
break
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined variable 'combo' in metadata assignment

The code references combo["topic"], combo["subtopic"], and combo["learning_objective"] on lines 1370-1373, but combo is not defined in this scope. This appears to be within the _write_questions_to_csv method which doesn't have access to a combo variable.

This metadata assignment logic should either:

  1. Be removed from this generic CSV writing method, or
  2. The metadata should be passed as a parameter to the method
🤖 Prompt for AI Agents
In educhain/engines/qna_engine.py around lines 1373 to 1384, the variable
'combo' is used for metadata assignment but is not defined in this scope,
causing an error. To fix this, either remove the metadata assignment referencing
'combo' from this generic CSV writing method or modify the method signature to
accept the necessary metadata as parameters and use those instead of 'combo'.
Ensure the method only uses variables passed to it or defined within its scope.

Comment on lines +1259 to +1298
from typing import List
from pydantic import BaseModel

class SanityCheckResult(BaseModel):
question: str
answer: str
options: Optional[List[str]] = None
keywords: Optional[List[str]] = None
answer_correctness: str
question_clarity: str
distractor_plausibility: str
passed: bool

class SanityCheckSummary(BaseModel):
results: List[SanityCheckResult]
total_questions: int
passed_questions: int
failed_questions: int

def show(self):
"""Displays the sanitized questions with their options and sanity check results."""
print("\nSanity Check Summary:")
print(f"Total Questions: {self.total_questions}")
print(f"Passed Questions: {self.passed_questions}")
print(f"Failed Questions: {self.failed_questions}\n")

for i, result in enumerate(self.results):
print(f"Question {i + 1}:")
print(f" Question Text: {result.question}")
print(f" Answer: {result.answer}")

if result.options:
print(" Options:")
for option in result.options:
print(f" - {option}")

print(f" Answer Correctness: {result.answer_correctness}")
print(f" Question Clarity: {result.question_clarity}")
print(f" Distractor Plausibility: {result.distractor_plausibility}")
print(f" Passed: {result.passed}\n")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove duplicate model definitions

The SanityCheckResult and SanityCheckSummary models are already defined in educhain/models/qna_models.py and imported on line 28. These duplicate definitions should be removed to avoid confusion and potential conflicts.

-# Extending SanityCheckSummary to include a show() method
-from typing import List
-from pydantic import BaseModel
-
-class SanityCheckResult(BaseModel):
-    question: str
-    answer: str
-    options: Optional[List[str]] = None
-    keywords: Optional[List[str]] = None
-    answer_correctness: str
-    question_clarity: str
-    distractor_plausibility: str
-    passed: bool
-
-class SanityCheckSummary(BaseModel):
-    results: List[SanityCheckResult]
-    total_questions: int
-    passed_questions: int
-    failed_questions: int
-
-    def show(self):
-        """Displays the sanitized questions with their options and sanity check results."""
-        print("\nSanity Check Summary:")
-        print(f"Total Questions: {self.total_questions}")
-        print(f"Passed Questions: {self.passed_questions}")
-        print(f"Failed Questions: {self.failed_questions}\n")
-
-        for i, result in enumerate(self.results):
-            print(f"Question {i + 1}:")
-            print(f"  Question Text: {result.question}")
-            print(f"  Answer: {result.answer}")
-
-            if result.options:
-                print("  Options:")
-                for option in result.options:
-                    print(f"    - {option}")
-
-            print(f"  Answer Correctness: {result.answer_correctness}")
-            print(f"  Question Clarity: {result.question_clarity}")
-            print(f"  Distractor Plausibility: {result.distractor_plausibility}")
-            print(f"  Passed: {result.passed}\n")

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In educhain/engines/qna_engine.py around lines 1259 to 1298, the
SanityCheckResult and SanityCheckSummary models are redefined but already
imported from educhain/models/qna_models.py on line 28. Remove these duplicate
class definitions entirely from this file to avoid conflicts and rely on the
imported models instead.

Comment on lines +1375 to +1378
validated_question = self._validate_individual_question(q_dict, question_model=question_model)
if validated_question:
batch_validated_questions.append(validated_question)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined variable 'batch_validated_questions'

The code references batch_validated_questions on line 1377, but this variable is not defined in the current scope. This appears to be a copy-paste error or incomplete refactoring.

The code should use written_questions instead:

-                validated_question = self._validate_individual_question(q_dict, question_model=question_model)
-                if validated_question:
-                    batch_validated_questions.append(validated_question)
+                # Validation is already handled by the Pydantic model
+                written_questions.append(question)

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In educhain/engines/qna_engine.py around lines 1375 to 1378, the variable
batch_validated_questions is used but not defined in the current scope. Replace
all occurrences of batch_validated_questions with written_questions to use the
correctly defined list and fix the undefined variable error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants