🌓

Function Call Formats

tiny_fnc_engine supports multiple formats for function calls. The primary format, which allows for chaining functions and referencing previous outputs, includes a "returns" field:

Function Calls with Returns (Recommended for Chaining)

function_calls = [
    {
        "name": "function1",
        "parameters": {"param1": value1},
        "returns": [{"name": "return1", "type": "type1"}]
    },
    {
        "name": "function2",
        "parameters": {"param2": "return1"},
        "returns": [{"name": "return2", "type": "type2"}]
    }
]

This format is particularly useful when you need to chain function calls or reference outputs from previous functions. The "returns" field allows you to specify names for the function outputs, which can then be used as parameters in subsequent function calls.

For simpler use cases where chaining is not required, you can use the following formats:

1. Single Function Call (Dictionary)

function_call = {
    "name": "function_name",
    "parameters": {"param1": value1, "param2": value2}
}

2. Multiple Function Calls (List of Dictionaries)

function_calls = [
    {
        "name": "function1",
        "parameters": {"param1": value1}
    },
    {
        "name": "function2",
        "parameters": {"param2": value2}
    }
]

3. JSON String

The engine also accepts JSON strings representing either a single function call or multiple function calls:

json_string = '''
{
    "name": "function_name",
    "parameters": {"param1": "value1", "param2": 42},
    "returns": [{"name": "result", "type": "str"}]
}
'''
result = engine.parse_and_call_functions(json_string)
        

or

json_string = '''
[
    {
        "name": "function1",
        "parameters": {"param1": "value1"},
        "returns": [{"name": "result1", "type": "int"}]
    },
    {
        "name": "function2",
        "parameters": {"param2": 42},
        "returns": [{"name": "result2", "type": "str"}]
    }
]
'''
results = engine.parse_and_call_functions(json_string)
        

4. OpenAI Tool Calls Format

The engine also supports the OpenAI tool calls format:

tool_calls = [
    {
        "id": "call_123",
        "function": {
            "arguments": '{"location": "San Francisco, CA"}',
            "name": "get_weather_forecast"
        },
        "type": "function"
    }
]
results = engine.parse_and_call_functions(tool_calls)
        

This format is compatible with OpenAI's function calling API, making it easy to integrate with OpenAI-powered applications.