Skip to main content

Extremely lightweight and minimal function calling engine

Project description

tiny_fnc_engine

tiny_fnc_engine is a minimal python library (one file, ~200 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 format
  • Chain multiple function calls
  • Store and reference function outputs
  • Support for Pydantic models as function parameters and return values

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

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)

# Print the results
print(results)

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiny_fnc_engine-0.1.6.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

tiny_fnc_engine-0.1.6-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file tiny_fnc_engine-0.1.6.tar.gz.

File metadata

  • Download URL: tiny_fnc_engine-0.1.6.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for tiny_fnc_engine-0.1.6.tar.gz
Algorithm Hash digest
SHA256 6f12ce044767c2a35dca9f4b4c214a9d628a330c9222925c03b03635111d3f90
MD5 a020633c7dd369e52367deaf8f34ae10
BLAKE2b-256 70f837b6535cbb8660a082461b49ffeacdd6b54d27e778e4e8e4ea96d7f986e1

See more details on using hashes here.

File details

Details for the file tiny_fnc_engine-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for tiny_fnc_engine-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 302e1893bafe018e72ae5d6d4f5da3d0e35ade2d75504acf8a7087d423ce4614
MD5 cc33b972b3df627b96b18136d7272228
BLAKE2b-256 f09e5caf6c6bf77deaa2ac4c8f0caa336fc2a34d3ac570281a83208decc7ee4f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page