Skip to main content

Reliable schema-based function calling for local language models.

Project description

CallForge

Reliable schema-based function calling for local language models.

CallForge selects a declared function, extracts type-safe parameters from a natural-language request, and uses constrained decoding only when a choice is ambiguous. It is designed for local models and works with any model that implements two small methods:

encode(text)
get_logits_from_input_ids(input_ids)

Installation

Install the lightweight core:

pip install callforge-ai

Install the ready-to-use Hugging Face adapter:

pip install "callforge-ai[huggingface]"

Python usage

from callforge import FunctionCaller, Function
from callforge.adapters.huggingface import HuggingFaceModel

functions = [
    Function.model_validate(
        {
            "name": "fn_add_numbers",
            "description": "Add two numbers together.",
            "parameters": {
                "a": {"type": "number"},
                "b": {"type": "number"},
            },
            "returns": {"type": "number"},
        }
    )
]

model = HuggingFaceModel("Qwen/Qwen3-0.6B", device="cpu")
caller = FunctionCaller(model=model, functions=functions)
result = caller.call("What is the sum of 2 and 3?")

print(result.model_dump())
# {'prompt': 'What is the sum of 2 and 3?',
#  'name': 'fn_add_numbers',
#  'parameters': {'a': 2.0, 'b': 3.0}}

JSON directory usage

Input directory:

data/input/
├── function_calling_tests.json
└── functions_definition.json

Run:

callforge \
  --input data/input \
  --output data/output \
  --model Qwen/Qwen3-0.6B \
  --device cpu

The result is written to:

data/output/function_calling_results.json

Use another local model

You do not need Transformers. Pass any object with the required interface:

class MyModel:
    def encode(self, text: str):
        ...

    def get_logits_from_input_ids(self, input_ids: list[int]) -> list[float]:
        ...

caller = FunctionCaller(model=MyModel(), functions=functions)

Development

python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
pytest
python -m build
python -m twine check dist/*

Security note

Only enable --trust-remote-code for model repositories you trust.

License

MIT

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

callforge_ai-0.1.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

callforge_ai-0.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file callforge_ai-0.1.0.tar.gz.

File metadata

  • Download URL: callforge_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for callforge_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5648630c6b7807052031fdcdd65a72baa43c959e324f710ad3e38146eafb76d2
MD5 02f840b03ce234aba9a119c28cd5b878
BLAKE2b-256 864250c223859fd84a3361949389de63fb50d631281954a648f15d6e1abd2068

See more details on using hashes here.

File details

Details for the file callforge_ai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: callforge_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for callforge_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 863865cf21b53fca0cff8bfaad23a88c210181e70a974559922d00b6463769e1
MD5 fadff077bdee28f74359711b39cc7702
BLAKE2b-256 83785ee2211b72da7341964fe6b844213f8793997ba43aab25fb0eb029b383fb

See more details on using hashes here.

Supported by

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