Skip to content

Extract resource-aware optimization logic into a tested module - #1

Open
denis-samatov wants to merge 1 commit into
AnkunHuang:mainfrom
denis-samatov:pr-resource-aware-optimization-hardening
Open

Extract resource-aware optimization logic into a tested module#1
denis-samatov wants to merge 1 commit into
AnkunHuang:mainfrom
denis-samatov:pr-resource-aware-optimization-hardening

Conversation

@denis-samatov

Copy link
Copy Markdown

Summary

  • Extracts the classify-route-respond logic from the resource-aware optimization notebook into notebooks/resource_aware_optimization.py
  • Adds a comprehensive test suite (18 tests, all mocked — no live API calls needed)
  • Fixes a few issues found while writing the tests:
    • Removes a hardcoded fallback API key
    • Fixes a prompt-injection vulnerability
    • Makes JSON parsing of LLM responses robust to markdown code fences and leading/trailing text, with a safe fallback instead of raising
    • Adds a timeout to the Google Custom Search HTTP request
    • Handles search errors in handle_prompt instead of letting them propagate uncaught
    • Removes dead/commented-out code

Test plan

  • pytest notebooks/test_resource_aware_optimization.py — 18/18 passed (mocked openai/requests/dotenv, no network access needed)

Extracts the classify-route-respond logic from the resource-aware
optimization notebook into notebooks/resource_aware_optimization.py,
adds a comprehensive test suite (18 tests, all mocked -- no live API
calls), and fixes several issues found along the way:

- Remove a hardcoded fallback API key.
- Fix a prompt-injection vulnerability.
- Make JSON parsing of LLM responses robust to markdown code fences
  and leading/trailing text, with a safe fallback instead of raising.
- Add a timeout to the Google Custom Search HTTP request.
- Handle search errors in handle_prompt instead of letting them
  propagate uncaught.
- Remove dead/commented-out code.

Verified: all 18 tests pass (pytest, mocked openai/requests/dotenv,
no network access needed).
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