Skip to content

[INFERENCE PROVIDERS] function calling tutorial#1832

Merged
burtenshaw merged 9 commits into
mainfrom
function-calling-tutorial-for-inference-providers
Jul 14, 2025
Merged

[INFERENCE PROVIDERS] function calling tutorial#1832
burtenshaw merged 9 commits into
mainfrom
function-calling-tutorial-for-inference-providers

Conversation

@burtenshaw

Copy link
Copy Markdown
Collaborator

This PR introduces a new tutorial on function calling.

@burtenshaw
burtenshaw requested a review from Wauplin July 10, 2025 09:39
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@Wauplin Wauplin left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread docs/inference-providers/guides/function-calling.md Outdated

@pcuenca pcuenca left a comment

Copy link
Copy Markdown
Member

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?

Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated

@sergiopaniego sergiopaniego left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Loved it! 😄

Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
Comment thread docs/inference-providers/guides/function-calling.md Outdated
burtenshaw and others added 3 commits July 14, 2025 12:22
Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com>
Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
@burtenshaw

Copy link
Copy Markdown
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

julien-c commented Jul 14, 2025

Copy link
Copy Markdown
Member

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.

6 participants