Repository navigation
fix(translator): guard rate_limit_params before .get() in do_llm_translate - #623
Closed
Morningstar202604 wants to merge 1 commit into
Closed
Morningstar202604 wants to merge 1 commit into
Morningstar202604 wants to merge 1 commit into
Conversation
…slate do_llm_translate dereferences rate_limit_params.get(...) when enable_json_mode_if_requested is set, but llm_translate() passes its rate_limit_params through with a default of None. A caller that does not supply rate_limit_params (e.g. a custom translator built on OpenAITranslator) then crashes with AttributeError: 'NoneType' object has no attribute 'get'. Match the guard already used in babeldoc/tools/executor/translator.py.
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.
Description
OpenAITranslator.do_llm_translatedereferencesrate_limit_params.get(...)wheneverenable_json_mode_if_requestedis set, butllm_translate()forwards itsrate_limit_paramswith a default ofNone:A caller that does not supply
rate_limit_params(e.g. a custom translator subclass built onOpenAITranslatorwith json mode enabled) crashes withAttributeError: 'NoneType' object has no attribute 'get'.The fix adds the same truthiness guard already used in
babeldoc/tools/executor/translator.py.Verified:
None,{},{"request_json_mode": False}and{"request_json_mode": True}all evaluate without error.Summary by cubic
Fixes a crash in
OpenAITranslator.do_llm_translatewhenrate_limit_paramsisNoneand JSON mode is enabled.Noneguard before calling.get()onrate_limit_params, matching the existing guard intranslator.py.rate_limit_params(e.g., custom translator subclasses) no longer raiseAttributeError.Written for commit 1c70cd9. Summary will update on new commits.