Skip to main content
IronaAI supports function calling, allowing language models to interact with external tools, APIs, or custom functions. This feature enhances the model’s capabilities by enabling actions such as retrieving real-time data, performing computations, or accessing databases.

When to use function calling

Use function calling when you need the model to:
  • Retrieve real-time or external data (e.g., weather info, stock prices)
  • Perform computations not natively supported by the model
  • Interact with APIs or databases
  • Execute custom functions in your application
This is ideal for building interactive agents, automating workflows, or integrating AI into systems. Defining tools Tools can be defined in multiple ways:
  • As dictionaries: Specify the tool’s name, description, and parameters.
  • As LangChain tools: Integrate tools from the LangChain library.

Example: Defining a tool as a dictionary

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Get the current weather in a given location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "The city, e.g., San Francisco"},
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
                },
                "required": ["location"]
            }
        }
    }
]

Example: Using a LangChain tool

from langchain_core.tools import tool

@tool
def multiply(a: int, b: int) -> int:
    """Multiply two integers."""
    return a * b

Make a function call using the client

# Bind the tool to the client
client = IronaAI()
completion_with_tools = client.bind_tools([multiply])
response = client.completion_with_tools(
    messages=[{"role": "user", "content": "What's the weather like in San Francisco?"}],
    tools=tools,
    tool_choice="auto"
)
The response includes a tool_calls attribute if the model opts to call a tool.

Considerations and limitations

  • Model Support: Verify support using client.supports_function_calling(model).
  • Tool Definitions: Ensure clarity to avoid incorrect calls.
  • Execution: Handle tool execution and errors in your code.