Skip to content

Conversation

@burtenshaw
Copy link
Collaborator

This PR introduces a new tutorial on function calling.

@burtenshaw burtenshaw requested a review from Wauplin July 10, 2025 09:39
@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.

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Really cool guide, learnt a few things along the way ^^


# Initialize client
client = OpenAI(
base_url="https://router.huggingface.co/nebius/v1",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is slightly misleading since it won't work the same for all providers. Using URL "https://router.huggingface.co/v1" is more flexible and should work for all providers (provider selection when using this route is on its way server-side)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it thanks. Agreed that the router makes sense here.

Comment on lines 311 to 312
- base_url="https://router.huggingface.co/together/v1",
+ base_url="https://router.huggingface.co/nebius/v1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is typically where using "https://router.huggingface.co/v1" would be better for server-side model resolution.

If you look at

you'll see the model id must be "deepseek-ai/DeepSeek-R1" for Together vs "deepseek-ai/DeepSeek-R1-0528" for Nebius. Once we have a proper "auto route with provider selection", this should hopefully be much simpler to use with the openai client.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Using InferenceClient it's much simpler since all the resolution is done client-side for you. We are currently closing the gap between the two clients)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here is typically where using "https://router.huggingface.co/v1" would be better for server-side model resolution.

Totally agree on this, but my main effort is to show the power of provider selection. I think this commit solves it, where I show a working example with provider="auto" and the router but diff trace for other providers.

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

Very nice!

cc @sergiopaniego, we worked together on this notebook for tool calling with Llama (but most info should be general).

I also enjoyed @Rocketknight1's post, in particular the get_json_schema helper. Could we maybe leverage it here?


# Get final response with function results
final_response = client.chat.completions.create(
model="meta-llama/Llama-3.1-8B-Instruct",
Copy link
Member

Choose a reason for hiding this comment

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

Why do we use a different model here? (Not saying it's wrong, just pointing out it could be potentially puzzling)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. This is wrong.

Copy link
Member

@sergiopaniego sergiopaniego left a comment

Choose a reason for hiding this comment

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

Loved it! 😄

@burtenshaw
Copy link
Collaborator Author

@Wauplin @pcuenca @sergiopaniego Thanks for the reviews! I've responded to everything. Please could I get an approval?

@burtenshaw burtenshaw merged commit 0cb9a5c into main Jul 14, 2025
2 checks passed
@burtenshaw burtenshaw deleted the function-calling-tutorial-for-inference-providers branch July 14, 2025 11:53
@julien-c
Copy link
Member

julien-c commented Jul 14, 2025

Nice, some small assorted tweaks in #1837

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.

7 participants