fix: deduplicate OmniParser init and reuse HeuristicEngine as singleton - #33
Open
Pranjal0410 wants to merge 1 commit into
Open
fix: deduplicate OmniParser init and reuse HeuristicEngine as singleton#33Pranjal0410 wants to merge 1 commit into
Pranjal0410 wants to merge 1 commit into
Conversation
…gine as singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: remove duplicate OmniParser initialization and store HeuristicEvaluationEngine as singleton
Problem
Two issues in the current startup and request handling:
Duplicate OmniParser initialization in
main.py—OmniParserClient()is created and initialized twice during startup (lines 36–37 and lines 44–45), meaning the model is loaded into memory twice unnecessarily.HeuristicEvaluationEngine re-created on every request — In
evaluation.py, the/evaluateendpoint creates a newHeuristicEvaluationEngine()and callsawait evaluation_engine.initialize()on every single request. This re-initializes the OpenAI client and the RAG knowledge base each time, adding unnecessary latency and memory overhead.Fix
main.py: Removed the duplicateOmniParserClientinitialization. StoredHeuristicEvaluationEngineonapp.state.heuristic_engineas a singleton, matching the existing pattern used forapp.state.omniparser_client.app/api/routes/evaluation.py: Updated the/evaluateendpoint to userequest.app.state.heuristic_engineinstead of creating a new engine instance per request.Files Changed
Testing
tests/test_integration_real.py) is unaffected — it creates its own engine instance directly./evaluateendpoint behavior is unchanged; only the initialization strategy differs.