Refactor: Centralize model settings and add validation tests#119
Merged
seratch merged 1 commit intoseratch:mainfrom Aug 17, 2025
Merged
Refactor: Centralize model settings and add validation tests#119seratch merged 1 commit intoseratch:mainfrom
seratch merged 1 commit intoseratch:mainfrom
Conversation
Decouple model-specific configurations from application logic to improve
maintainability and extensibility.
- Centralize Settings:
- Moved hardcoded context lengths from `openai_ops.py` into a new
`MODEL_CONTEXT_LENGTHS` dictionary in `openai_constants.py`.
- Extracted the default token calculation model into a new
`DEFAULT_TOKEN_COUNT_MODEL` constant.
- Unify Alias Resolution:
- Created a single `resolve_model_alias()` helper function in
`openai_constants.py` to handle alias chains and prevent circular
dependencies.
- Refactored `context_length()` and `calculate_num_tokens()` to use
this shared function, removing duplicated logic.
- Add Validation Tests:
- Introduced a new test suite (`tests/model_constants_test.py`) to
verify the refactoring.
- Tests cover alias resolution, error handling for unregistered
models, circular dependency detection, and configuration
completeness for all model aliases.
b7ae546 to
cc82ac6
Compare
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.
Decouple model-specific configurations from application logic to improve maintainability and extensibility.
Centralize Settings:
openai_ops.pyinto a newMODEL_CONTEXT_LENGTHSdictionary inopenai_constants.py.DEFAULT_TOKEN_COUNT_MODELconstant.Unify Alias Resolution:
resolve_model_alias()helper function inopenai_constants.pyto handle alias chains and prevent circular dependencies.context_length()andcalculate_num_tokens()to use this shared function, removing duplicated logic.Add Validation Tests:
tests/model_constants_test.py) to verify the refactoring.Change summary from GitHub Copilot: