Skip to content
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

[Inference doc] Next gen inference snippets #1643

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Mar 21, 2025

Opening this PR as a draft as it'll requires some deeper changes in doc-builder cc @julien-c @gary149 @mishig25 @SBrandeis @hanouticelina

This PR updates the script to generate the tasks pages of the Inference API docs (e.g. text-to-image page). The short-term goal is to revamp the "Inference API" docs as an "Inference Providers" one, making them more provider-centric. With this PR, each task page will have

  • a Recommended models section => same as today. Recommended models taken from hf.co/tasks + filtered to keep only warm ones
  • an API specification section => same as today. Specs are taken from the jsonschema specs that we have and rendered in a table.
  • a Using the API section => this is the revamped one. We want to display snippets for all providers supporting the task, and for all clients for which we have code snippets. To chose which model to highlight, I'm taking for each provider the "live" model with the most "likes30d". My only concern with this strategy is that it might lead to recurrent changes in the docs (which are automated daily).
    • In practice, it would be very nice to extend the current <inferencesnippets> tag to have an interface similar to the one on the model page
      image

What I did in this PR is to generate the snippets and serialize them inside some <snippet provider="..." language="..." client="..."> tags. This is where doc-builder should be updated to take them into account.


New <inferencesnippet> format:

<inferencesnippet>

<snippet provider="fal-ai" language="python" client="huggingface_hub">

``python
import fal_client

result = fal_client.subscribe(
    "fal-ai/flux/dev",
    arguments={
        "prompt": "Astronaut riding a horse",
    },
)
print(result)
``

</snippet>

<snippet provider="fal-ai" language="python" client="fal_client">
This is the snippet template for provider `fal-ai`, language `python`, and client `fal_client`.
</snippet>

<snippet provider="fal-ai" language="js" client="fetch">
This is the snippet template for provider `fal-ai`, language `js`, and client `fetch`.
</snippet>

<snippet provider="fal-ai" language="js" client="huggingface.js">
This is the snippet template for provider `fal-ai`, language `js`, and client `huggingface.js`.
</snippet>

<snippet provider="hf-inference" language="python" client="huggingface_hub">
This is the snippet template for provider `hf-inference`, language `python`, and client `huggingface_hub`.
</snippet>

<snippet provider="hf-inference" language="python" client="requests">
This is the snippet template for provider `hf-inference`, language `python`, and client `requests`.
</snippet>

<snippet provider="hf-inference" language="js" client="fetch">
This is the snippet template for provider `hf-inference`, language `js`, and client `fetch`.
</snippet>

<snippet provider="hf-inference" language="js" client="huggingface.js">
This is the snippet template for provider `hf-inference`, language `js`, and client `huggingface.js`.
</snippet>

... # same for other providers

</inferencesnippet>

to be discussed further, we can make the format evolve...


Side note: it has also been quickly discussed to integrate the model page modal directly as an iframe inside the docs to minimize changes. However we concluded that serializing all the snippets in markdown will be much more powerful for LLM-first documentation (e.g. AI Agent-readable documentation). The iframe solution would only work for user browsing the documentation manually .

@Wauplin Wauplin marked this pull request as draft March 21, 2025 15:13
@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.

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.

2 participants