# Function/tool calling using Transformer models

**URL:** <https://discuss.huggingface.co/t/function-tool-calling-using-transformer-models/142403>\
**Category:** 🤗Transformers\
**Created:** [February 22, 2025, 8:32pm UTC](https://discuss.huggingface.co/t/function-tool-calling-using-transformer-models/142403 "2025-02-22T20:32:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![heeby](https://avatars.discourse-cdn.com/v4/letter/h/76d3ee/32.png) [@heeby](https://discuss.huggingface.co/u/heeby)\
**Post date:** [February 22, 2025, 8:32pm UTC](https://discuss.huggingface.co/t/function-tool-calling-using-transformer-models/142403/1 "2025-02-22T20:32:56Z")

</div>

how do i add tool/function calls to a model, or how can i interact with an hugging face model using openai api format.

I loaded the model woth auto model and auto process for chat template but I am unable to use tooks.  
When I use tokeizer.from\_chat\_template, it calls the function on first message without waiting for the condition to be met

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 23, 2025, 3:15am UTC](https://discuss.huggingface.co/t/function-tool-calling-using-transformer-models/142403/2 "2025-02-23T03:15:00Z")

</div>

There are several ways to do this. Personally, I recommend creating agents. This is not too dependent on the model’s functions.

If you want to train the model itself to be compatible with function calling, that’s a completely different story… or rather, I don’t really understand.

> **[Agents and tools](https://huggingface.co/docs/transformers/main/en/agents)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **[Function Calling](https://huggingface.co/docs/hugs/en/guides/function-calling)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **[Build an agent with tool-calling superpowers 🦸 using smolagents - Hugging...](https://huggingface.co/learn/cookbook/en/agents)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![heeby](https://avatars.discourse-cdn.com/v4/letter/h/76d3ee/32.png) [@heeby](https://discuss.huggingface.co/u/heeby)\
**Post date:** [February 24, 2025, 7:58am UTC](https://discuss.huggingface.co/t/function-tool-calling-using-transformer-models/142403/3 "2025-02-24T07:58:33Z")

</div>

I have loaded a model with auto model and auto tokenizer  
I want to use the model to collect users information like name address age etc etc.  
When all information has been collected, I want the model to send the information to an endpoint.

Also can I use Inference client on a model I am running locally

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 24, 2025, 10:24am UTC](https://discuss.huggingface.co/t/function-tool-calling-using-transformer-models/142403/4 "2025-02-24T10:24:32Z")

</div>

I think it would be difficult to use the Hugging Face InferenceClient library as it is…

It would probably be easier to load the Transformers model from each library locally.  
If you use smoalgents, you can use the TransformersModel to use the Transformers model. If you want to set up a server locally, you could use Ollama, Llamacpp or TGI.

> **[Models](https://huggingface.co/docs/smolagents/reference/models#smolagents.TransformersModel)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **[Text Generation Inference](https://huggingface.co/docs/text-generation-inference/index)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **[Use Ollama with any GGUF Model on Hugging Face Hub](https://huggingface.co/docs/hub/ollama)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![LOLMAN65](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lolman65/32/51227_2.png) [@LOLMAN65](https://discuss.huggingface.co/u/LOLMAN65)\
**Post date:** [July 17, 2025, 10:49am UTC](https://discuss.huggingface.co/t/function-tool-calling-using-transformer-models/142403/5 "2025-07-17T10:49:45Z")

</div>

hello:D i have tried using transformers model since loading the model is free compared to using the API. However, im facing this issue where it states that “Token indices sequence length is longer than the specified maximum sequence length for this model (2337 \> 2048)” and it does not give any output

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/b/9/b956d26d82fad323ce1e52d5d1ca63e965f9246d.png)

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [July 17, 2025, 1:19pm UTC](https://discuss.huggingface.co/t/function-tool-calling-using-transformer-models/142403/6 "2025-07-17T13:19:45Z")

</div>

In that case, you may be able to avoid this by setting `max_length` instead of `max_new_tokens`. Alternatively, you could change to a model that supports longer contexts.

> <https://github.com/huggingface/transformers/issues/1791>
>
> \## ❓ Questions & Help
> 
> When I use Bert, the "token indices sequence length is …longer than the specified maximum sequence length for this model (1017 \> 512)" occurs. How can I solve this error?
