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, 177 lines of code) that provides a flexible engine for calling functions extracted from LLM (Large Language Model) outputs in JSON format within an isolated environment. The engine stores functions and their outputs in memory, allowing for chained function calls and parameter referencing.

Features

  • Add and call functions dynamically
  • Parse function calls from JSON format
  • Chain multiple function calls
  • Store and reference function outputs
  • Isolated execution environment

Project Structure

tiny_fnc_engine/
│
├── tiny_fnc_engine/
│   ├── __init__.py
│   └── engine.py
├── tests/
│   ├── __init__.py
│   └── test_engine.py
├── main.py
├── 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

# Initialize the engine and load functions from a python file
engine = FunctionCallingEngine()
engine.add_functions_from_file('path/to/functions.py')

# Parse and call functions from an example model response
example_response = """
[
    {
        "name": "get_random_city",
        "parameters": {},
        "returns": [{"name": "random_city", "type": "str"}]
    },
    {
        "name": "get_weather_forecast",
        "parameters": {"city": "random_city"},  
        "returns": [{"name": "forecast", "type": "dict"}]
    }
]
"""
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.3.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

tiny_fnc_engine-0.1.3-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tiny_fnc_engine-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5270a5221186b31d543fc4b925add9dfa650bcbc6d5c14a864e9b01565ac940d
MD5 6d88fefc6d37e759fbf1c3c7e4e6d6d3
BLAKE2b-256 666c4b2ce5a4f928f11ea6c67f3801b7359ce82bfdf22138dfef58ac0531fede

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiny_fnc_engine-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ce8948ac13200c859b9aea33eec35412df8a21749fbef45da8077087dca6f739
MD5 e56c551f4424b818bad2e145b8de5ea6
BLAKE2b-256 f3d2e34115f96dc41f098a0269e104c62a8dc5663bb62e3d5b4185aa26bc04f7

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