-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Simplify max_output_tokens handling in LLM classes #9296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Remove complex default-setting logic in init_model_info() - Keep max_output_tokens as None if not explicitly set - Use conditional parameter inclusion in completion calls - Update tests to expect None values instead of computed defaults This simplifies the codebase by removing unnecessary complexity in determining max_output_tokens defaults.
Remove unnecessary conditional dictionary building. Since litellm.completion accepts Optional[int] = None for both max_completion_tokens and max_tokens parameters, we can simply pass None directly instead of conditionally including the parameters. This makes the code much cleaner and easier to understand.
The code is self-explanatory and doesn't need verbose comments.
The assertions are clear without explanatory comments.
model in self.config.model | ||
for model in ['claude-3-7-sonnet', 'claude-3.7-sonnet'] | ||
): | ||
self.config.max_output_tokens = 64000 # litellm set max to 128k, but that requires a header to be set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at least this one needs a quick test with 3.7. I’m not at my computer, but I can do that in a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm it works well. I think this was a litellm issue at some point in time, it must have been fixed, and we forgot this code here.
Re: the complex logic here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got LLMs to tell me stories, I also tried to look up the history of this code, and I don't find a reason not to clean it out. So let's go with this. If there are issues, we'll find out. 😅
Thank you! |
This reverts commit 1e33624.
Summary
This PR simplifies the handling of
max_output_tokens
in OpenHands LLM classes by removing complex default-setting logic and keeping the value asNone
when not explicitly set.Changes Made
Core Changes
init_model_info()
that attempted to determine default values formax_output_tokens
based on various conditionsmax_output_tokens
isNone
, it remainsNone
instead of being set to computed defaultsmax_output_tokens
only when it's notNone
Files Modified
openhands/llm/llm.py
: Removed lines 489-507 containing complex default determination logic, added conditional parameter inclusionopenhands/llm/async_llm.py
: Added conditionalmax_tokens
parameter inclusionopenhands/llm/streaming_llm.py
: Added conditionalmax_tokens
parameter inclusiontests/unit/test_llm.py
: Updated test expectations to expectNone
values instead of computed defaultsTesting
Benefits
max_output_tokens
is not setBackward Compatibility
This change maintains backward compatibility - the LLM providers will use their own defaults when
max_output_tokens
is not provided, which is the expected behavior.References
max_output_tokens
handlingNone
asNone
instead of complex default computationFixes #9227
@neubig can click here to continue refining the PR
To run this PR locally, use the following command: