-
Notifications
You must be signed in to change notification settings - Fork 761
Recursive filter_none in Inference Providers #3178
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
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Thank you! I pushed additional commits that should solve the issue you mentioned in the PR description, I added additional test cases as well.
I tested tiny-agents with the PR, it works as expected.
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.
Left some minor comments but the logic itself looks good to me. I can't approve the PR since it's originally mine but LGTM once comments are addressed ✔️
), | ||
], | ||
) | ||
def test_prepare_payload_filters_messages(self, raw_messages, expected_messages): |
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.
thanks for adding this :)
* Recursive filter_none in Inference Providers * filter none values from messages as well * update filter_none and add test cases * don't drop empty dicts in list * better typing and refactor logic into a list of comrpehension --------- Co-authored-by: Celina Hanouti <hanouticelina@gmail.com>
* Recursive filter_none in Inference Providers * filter none values from messages as well * update filter_none and add test cases * don't drop empty dicts in list * better typing and refactor logic into a list of comrpehension --------- Co-authored-by: Celina Hanouti <hanouticelina@gmail.com>
None
values in payload can lead to a BadRequest error if the Inference Provider did not expect the field and is doing input validation. This is for instance what's happening in #3170 with groq complaining iftool_calls
andtool_call_id
are both set (with None values in them). Groq is complying to the OpenAI specs, this is more a problem on our side but won't be in this PR (*).What we currently do to avoid these issues is to filter out None values using
filter_none
. However this helper only removes None values at the top-level of the dictionary. This PR updatesfilter_none
to recursively remove None values. I added some tests to ensure that values like""
,0
and[]
are not removed. This PR should fix the Groq issue and will likely avoid some other errors in the future.(*) regarding why we don't exactly follow the OpenAI specs in our inference types is that we don't have a good way to generate Union type. If a schema is defined as "oneOf", our script will generate a class that is in fact a superset of all possible values, with all of them being optional. See huggingface/huggingface.js#1537 or glideapps/quicktype#1266 for more details. This issue might be annoying on the long run but there is no easy way to address it. Pydantic defines discriminators unions for that which we could also implement. What's harder is to have a reliable and generic
parse_obj
method extending a Union type (which doesn't seem possible). Let's see if/when it becomes for urgent to tackle it.cc @Vaibhavs10 @burtenshaw