Skip to content

[Inference] request() returns a request context to avoid redundant makeRequestOptions calls #1314

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

Merged
merged 9 commits into from
Apr 2, 2025

Conversation

hanouticelina
Copy link
Contributor

Related to @SBrandeis's comment here #1292 (comment). This PR addresses the original concern about redundant makeRequestOptions calls introduced in #1292.The solution implemented here updates the request function to return both the response and a request context when needed, allowing provider-specific polling code to reuse this context without redundant calls to makeRequestOptions.

This differs from the initial suggestion in the comment as each provider implements polling differently with different parameters / response formats. Making a generic .poll property would require mixing provider-specific logic into the core request function (we don't want that, right? 😄 ).
In the end, we want to keep provider-specific logic isolated in their respective provider files (PR coming today to push that further!).

Copy link
Member

@coyotte508 coyotte508 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds different return types, not sure the complication is worth it (unless it saves network calls)

@Wauplin
Copy link
Contributor

Wauplin commented Mar 25, 2025

FWIW in the Python client we've deprecated the "custom requests" method to make it internal-only and gain some flexibility -which would prove useful here-.

Copy link
Contributor

@SBrandeis SBrandeis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
I would be in favor of removing the request method from the public API as suggested by @Wauplin
Or at least, don't make the return type conditioned by a parameter (always return ResponseWrapper<T>)

@coyotte508
Copy link
Member

just to reiterate a bit, it's totally fine to call a "light" sync function twice to simplify things

@hanouticelina
Copy link
Contributor Author

I added a deprecation for custom requests through request and streamingRequest to be removed from the public API (I was not sure if I can just remove them directly or go through a deprecation cycle). I also made the inner request method to always return ResponseWrapper<T>.
Let's wait for @SBrandeis final review to see if it's still worth merging this PR or just keep the two call to makeRequestOptions as suggested by @coyotte508 (I'm okay with both solutions).

@hanouticelina hanouticelina requested a review from SBrandeis March 31, 2025 14:40
@Wauplin
Copy link
Contributor

Wauplin commented Mar 31, 2025

just to reiterate a bit, it's totally fine to call a "light" sync function twice to simplify things

AFAIU in this case makeRequestOptions is not a light function as it requires to fetch the provider model id from an HTTP call

@HuggingFaceDocBuilderDev

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.

@hanouticelina
Copy link
Contributor Author

AFAIU in this case makeRequestOptions is not a light function as it requires to fetch the provider model id from an HTTP call

ah yes, forgot that we call api/models/{model_id}?expand[]=inferenceProviderMapping in makeRequestOptions, thanks!

@coyotte508

This comment was marked as outdated.

@SBrandeis SBrandeis self-assigned this Apr 2, 2025
Copy link
Contributor

@SBrandeis SBrandeis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice - thanks for keeping the diff very low !!

I have some suggestion regarding syntax / code style, otherwise LGTM

Copy link
Contributor

@SBrandeis SBrandeis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's goooo

@hanouticelina hanouticelina merged commit 0f26700 into main Apr 2, 2025
6 checks passed
@hanouticelina hanouticelina deleted the update-request-func branch April 2, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants