Support user-configurable parameter override for model completion parameters by albertvillanova · Pull Request #1678 · huggingface/smolagents (original) (raw)
Support user-configurable parameter override for model completion parameters.
This PR gives self.kwargs highest priority over method parameters and explicitly passed kwargs.
Why self.kwargs should have highest precedence
- User customization at model level: When users create a Model instance, they set self.kwargs to customize the model's behavior for all subsequent calls
- Limited runtime customization: Users cannot directly modify the parameters passed to _prepare_completion_kwargs since this method is called internally by the model
- Consistency expectation: Users expect their model-level configuration to take precedence over internal method calls
- Subclassing alternative: The only way users could override this behavior would be to subclass the Model class and override _prepare_completion_kwargs, which requires significantly more code
This ensures that model-level configuration (which users can control) always takes precedence over internal method calls (which users cannot control without subclassing).
This should allow users to easily fix issues like these for future models:
- BUG: Error while generating or parsing output: Error code: 400 - {'error': {'message': "Unsupported parameter: 'stop' is not supported with this model.", 'type': 'invalid_request_error', 'param': 'stop', 'code': 'unsupported_parameter'}} #1675
- Fix error for GPT-5 not supporting the stop parameter #1662
Test Coverage
Added comprehensive pytest test covering parameter precedence and REMOVE_PARAMETER functionality.
Fix #1676.