Skip to main content

tiny_fnc_engine

tiny_fnc_engine is a minimal python library (one file, 212 lines of code) that provides a flexible engine for calling functions extracted from LLM (Large Language Model) outputs in JSON format. The engine stores functions and their outputs in memory, allowing for chained function calls and parameter referencing. It also supports using Pydantic models for type safety and validation.

Features

  • Add and call functions dynamically
  • Parse function calls from JSON or string format
  • Chain multiple function calls
  • Store and reference function outputs
  • Support for Pydantic models as function parameters and return values
  • Reset session to clear stored outputs
  • Parse & call functions from OpenAI compatible "tool_calls" format

Documentation

The documentation is available at https://atakantekparmak.github.io/tiny_fnc_engine/.

Warning

Users are responsible for the functions they load in the interpreter.

Project Structure

tiny_fnc_engine/
│
├── tiny_fnc_engine/
│   ├── __init__.py
│   └── engine.py
├── tests/
│   ├── __init__.py
│   └── test_engine.py
├── main.py
├── requirements.txt
├── package_requirements.txt
├── Makefile
└── LICENSE

Requirements

  • Python 3.10 or later

Installation and Usage

1. Install from PyPI

  1. The package is available on PyPI. You can install it using pip:
pip install tiny_fnc_engine
  1. Then you can use it in your project as follows:
from tiny_fnc_engine import FunctionCallingEngine
from pydantic import BaseModel

# Define a Pydantic model (optional)
class User(BaseModel):
    name: str
    age: int

def get_user() -> User:
    return User(name="Alice", age=30)

def greet_user(user: User) -> str:
    return f"Hello, {user.name}!"

# Initialize the engine and load functions 
engine = FunctionCallingEngine()
engine.add_functions([get_user, greet_user])
# Optionally, you can load functions from a file
# engine.add_functions_from_file('path/to/functions.py')

# Parse and call functions from an example model response
example_response = """
[
    {
        "name": "get_user",
        "parameters": {},
        "returns": [{"name": "user", "type": "User"}]
    },
    {
        "name": "greet_user",
        "parameters": {"user": "user"},  
        "returns": [{"name": "greeting", "type": "str"}]
    }
]
"""
results = engine.parse_and_call_functions(example_response, verbose=True)

# Print the results
print(results)

# Reset the session if needed
engine.reset_session()

2. Just grab the code

Since all the code in the library is located in a single file, you can just download it and use it in your project as follows:

curl -o tiny_fnc_engine.py https://raw.githubusercontent.com/AtakanTekparmak/tiny_fnc_engine/main/tiny_fnc_engine/engine.py

and then use it the same way as in the PyPI installation.

3. Build from Source

  1. Clone the repository:

    git clone https://github.com/yourusername/tiny_fnc_engine.git
    cd tiny_fnc_engine
    
  2. Install dependencies:

    make install
    
  3. Run the main script:

    make run
    
  4. Run the tests:

    make run_tests
    

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for tiny-fnc-engine 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tiny-fnc-engine 0.2.1
File Size Uploaded
tiny_fnc_engine-0.2.1.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tiny-fnc-engine 0.2.1
File Interpreter ABI Platform
tiny_fnc_engine-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.7 kB

Release files / tiny_fnc_engine-0.2.1.tar.gz

Download URL tiny_fnc_engine-0.2.1.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cbfe5d5e14162a2be9a1edf4c1d221da0492dfb954c0d031afde7f47c30e1134
BLAKE2b-256 checksum
How to use checksums
45af67c3b4df9a48bb723ea8617a4a00b97865ebff696dacf2a07f5ba3e9019e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / tiny_fnc_engine-0.2.1-py3-none-any.whl

Download URL tiny_fnc_engine-0.2.1-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
caf903eb6960a2db7899c7ebb585b707c3006b06320c94ecede8ce9ef46150e6
BLAKE2b-256 checksum
How to use checksums
fec6c864bcd35128830d81887bb8185c8bc5453e2f52f27683243124cd49317a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page