🧹 Refactor: Consolidate numeric extraction into shared utility#6
🧹 Refactor: Consolidate numeric extraction into shared utility#6dhanush342 wants to merge 1 commit intomainfrom
Conversation
Co-authored-by: dhanush342 <187305764+dhanush342@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR centralizes numeric-answer extraction by moving duplicated parsing logic into a shared utils.extract_numeric() helper, and updates the evaluation script(s) to use it.
Changes:
- Added
utils.pywith sharedextract_numeric()implementation. - Updated
evaluate_gsm8k.pyandweb/streamlit_dashboard.pyto use the shared helper (and removed the local implementations/imports). - Added a small test script and a
.gitignoreentry for Python bytecode.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
web/streamlit_dashboard.py |
Removes local numeric parsing; imports extract_numeric (and adds a runtime sys.path tweak). |
utils.py |
Introduces shared extract_numeric() utility using regex + Fraction. |
tests/test_utils.py |
Adds coverage script for common numeric extraction cases. |
evaluate_gsm8k.py |
Replaces bespoke parse_numeric() with utils.extract_numeric(). |
.gitignore |
Ignores __pycache__ and *.pyc. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| import sys | ||
| import os | ||
|
|
||
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
| from utils import extract_numeric | ||
| from inference import generate_solution |
| import sys | ||
| import os | ||
|
|
||
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
🎯 What: The duplicated numeric extraction logic (previously in
web/streamlit_dashboard.pyandevaluate_gsm8k.py) has been consolidated into a new, sharedutils.pymodule. The function now handles non-string inputs safely by enforcing a type cast and uses robust regular expressions to extract negative numbers, fractions, and decimals consistently.💡 Why: This improves maintainability and readability by ensuring a single source of truth for numeric extraction. If future extraction tweaks are needed, they only have to be made in one place. Additionally, redundant logic and unused imports have been cleaned up across the involved files.
✅ Verification:
test_utils.pycovering standard numbers, fractions, decimals, text mixed with numbers, and missing (None) inputs.web/streamlit_dashboard.pylogic appropriately importsutils.py.evaluate_gsm8k.pyimports and usesextract_numericseamlessly, ensuring the math evaluation logic is preserved.re,Fractionfrom bothevaluate_gsm8k.pyandweb/streamlit_dashboard.py..gitignoreto keep__pycache__out of version control and ensure tests remain in thetests/directory.✨ Result: A cleaner, deduplicated codebase with a centralized, robust utility function for extracting math answers.
PR created automatically by Jules for task 15683755180382661517 started by @dhanush342