Skip to content

Conversation

Shreya6901
Copy link

Description

Introduces a Text Rewriter tool under app/tools/text_rewriter/ that enables users to transform input text or documents according to custom instructions—such as “Simplify for middle school,” “Paraphrase,” or “Translate to French/Spanish.” This feature mirrors the existing Notes Generator structure for consistency, leveraging get_docs for file loading and rewriting. It includes input validation, clear error handling, and comprehensive unit tests.

Related Issue

Issue #128

Type of Change

  • New feature: A non-breaking change that adds functionality
  • Documentation update: Changes or updates to documentation
  • Test enhancement: Adding or updating tests; no production code change

Proposed Solution

  1. Input Handling
    • Validates that either text or text_file_url is provided
    • Requires text_file_type when a URL is supplied, casting non-string types to trigger a controlled error
    • Uses get_docs(...) to fetch and parse CSV, PDF, DOCX, PPTX, TXT, MD, and Google-hosted PDFs
  2. Rewriting Logic
    • Executor (core.py): Coordinates validation, document loading, and calls TextRewriterPipeline
    • Pipeline (tools.py):
      • If documents are loaded, concatenates their content and calls the LLM with the user instruction
      • Otherwise, invokes the LLM directly on raw text
      • Embeds rewrite_instruction and lang into the prompt template
  3. Metadata & UI Discovery
    • Defined metadata.json to describe form fields for instruction, text, URL, type, and language, enabling auto-generated UIs
  4. Testing
    • Added tests/test_core.py that mocks get_docs and TextRewriterPipeline.rewrite() to isolate and verify executor behavior
    • Covers valid text-only rewrites, missing-input errors, and valid/invalid file-type scenarios for each supported format

How to Test

  1. Install dependencies:
pip install -r requirements.txt
  2. Run the Text Rewriter tests:
PYTHONPATH=./ pytest app/tools/text_rewriter/tests/test_core.py
  3. Confirm that all tests pass without warnings

Unit Tests

  • test_core.py
    • test_executor_text_valid: Verifies direct-text rewriting
    • test_executor_missing_all_inputs: Checks missing-input error
    • test_executor__text_file_url_valid: Confirms success for each supported file type
    • test_executor__text_file_url_invalid: Verifies error when text_file_type is not a string

Documentation Updates

Indicate whether documentation needs to be updated due to this PR.

N/A

Checklist

  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

Additional Information

Looking Forward to your review and feedback

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.

1 participant