Sobes.tech
Senior

What is tool/function calling in LLM?

sobes.tech AI

Answer from AI

Tool/function calling in LLM (Large Language Models) is a mechanism that allows the model not only to generate text but also to invoke external functions or tools to perform specific tasks. Instead of trying to generate a complete answer on its own, the model can request the execution of a function, such as fetching data from an API, performing calculations, or interacting with a database.

This improves accuracy and extends the capabilities of LLMs, enabling integration with real services and obtaining up-to-date information.

Example: the model receives a request "Show the weather in Moscow" and instead of generating weather text, it calls the function getWeather(city), which returns current data, and then the LLM formulates a response based on the result of the call.

In Node.js, it might look like this:

async function handleRequest(input) {
  if (input.includes('weather')) {
    const city = extractCity(input);
    const weather = await getWeather(city); // external function call
    return `Weather in ${city}: ${weather}`;
  }
  // other cases
}

Thus, tool/function calling extends the capabilities of LLMs, making them more useful and integrable.