Function calling is a powerful feature that connects large language models (LLMs) with external systems to maximize the model’s utility. It goes beyond simply relying on model’s learned knowledge and provides the possibility of utilizing real-time data and performing complex tasks.

This feature allows LLMs to interact with dynamic resources such as external APIs, databases, and the web, providing flexible responses that are not limited to fixed information. By defining functions and arguments based on JSON schemas, the model can intelligently select and call the necessary functions by analyzing the user’s intent. This enables the generation of real-time results that go beyond simple text generation.

This feature provides scalability and flexibility to adapt to various use cases, enabling the development of more powerful and practical applications.

Simple Example

Simple Example output

{
  "choices": [
    {
      "finish_reason": "tool_calls",
      "index": 0,
      "logprobs": null,
      "message": {
        "content": null,
        "role": "assistant",
        "tool_calls": [
          {
            "function": {
              "arguments": "{\"location\": \"Boston\", \"unit\": \"fahrenheit\"}",
              "name": "get_current_weather"
            },
            "id": "call_BQmcwJYNSmBz6Rn1D8aiXXJq",
            "type": "function"
          }
        ]
      }
    }
  ],
  "created": 1733982599,
  "usage": {
    "completion_tokens": 33,
    "prompt_tokens": 472,
    "total_tokens": 505
  }
}

Supported models

  • meta-llama-3.1-8b-instruct
  • meta-llama-3.1-70b-instruct
  • mixtral-8x7b-instruct-v0-1

References

Blog Series - Calendar Agent

Blog Series - Function Calling