Skip to main content
hypertion

Making LLM Function-Calling Simpler.

🚀 Installation

pip install hypertion

Usage 🤗

Create a HyperFunction instance

from hypertion import HyperFunction

hyperfunction = HyperFunction()

Use the takeover method to register the function

Check notebooks directory for complex function usage.

from typing import Literal
from typing_extensions import TypedDict

class Settings(TypedDict):
    """
    Settings
    @param unit: The unit scale to represent temperature.
    @param forecast: If set to True, returns the forecasting.
    """
    unit: Literal['celsius', 'fahrenheit']
    forecast: bool = False

@hyperfunction.takeover
def get_current_weather(location: str, *, settings: Settings):
    """
    Get the current weather.
    @param location: Location to search for.
    @param settings: Settings to use for getting current weather.
    """
    info = {
        "location": location,
        "temperature": "72",
        "unit": settings['unit'],
    }
    if settings['forecast'] is True:
        return info | {"forecast": ["sunny", "windy"]}
    
    return info

Supported Types: str | int | float | bool | list | dict | pathlib.Path | typing.List | typing.Dict | typing.NamedTuple | typing_extensions.TypedDict | pydantic.BaseModel | typing.Literal | enum.Enum

List registered functions

hyperfunction.registry()
============================================================
get_current_weather(
   location: str,
   *,
   settings: Settings
):
"""Get the current weather."""
============================================================

Register a predefined function

from some_module import some_function

hyperfunction.takeover(
    some_function,
    docstring="<Override docstring for the function>"
)

Use the format method to get function schema

LLM specific formats are available: functionary, gorilla, mistral, gpt, claude

hyperfunction.format(as_json=True)
# hyperfunction.format('<format>', as_json=True)
[
    {
        "name": "get_current_weather",
        "description": "Get the current weather.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "Location to search for."
                },
                "settings": {
                    "type": "object",
                    "properties": {
                        "unit": {
                            "type": "string",
                            "enum": [
                                "celsius",
                                "fahrenheit"
                            ],
                            "description": "The unit scale to represent temperature."
                        },
                        "forecast": {
                            "type": "boolean",
                            "description": "If set to True, returns the forecasting."
                        }
                    },
                    "required": [
                        "unit"
                    ],
                    "description": "Settings to use for getting current weather."
                }
            },
            "required": [
                "location",
                "settings"
            ]
        }
    }
]

Compose function signature as function-call object

Try Gorilla+Hypertion Colab for live example.

signature =  """
get_current_weather(
    location='Kolkata', settings={'unit': 'fahrenheit'}
)
"""
function_call = hyperfunction.compose(signature)
function_call
get_current_weather(
   location='Kolkata',
   settings={'unit': 'fahrenheit', 'forecast': False}
)

Invoke the function-call object

function_call()
{'location': 'Kolkata', 'temperature': '72', 'unit': 'fahrenheit'}

Compose function metadata as function-call object

Try Functionary+Hypertion Colab for live example.

name = 'get_current_weather'
arguments = '{"location": "Kolkata", "settings": {"unit": "fahrenheit", "forecast": true}}'
function_call = hyperfunction.compose(name=name, arguments=arguments) # Accepts both JsON and dictionary object
function_call
get_current_weather(
   location='Kolkata',
   settings={'unit': 'fahrenheit', 'forecast': True}
)

Invoke the function-call object

function_call()
{'location': 'Kolkata', 'temperature': '72', 'unit': 'fahrenheit', 'forecast': ['sunny', 'windy']}

Important: The hypertion library lacks the capability to interact directly with LLM-specific APIs, meaning it cannot directly make request to any LLM. Its functionality is to generate schema and invoke signature/metadata generated from LLM(s). This design choice was made to provide more flexibility to developers, allowing them to integrate or adapt different tools and libraries as per their project needs.

Combining two HyperFunction instance

Note: A single HyperFunction instance can hold multiple functions. Creating a new HyperFunction instance is beneficial only if you need a distinct set of functions. This approach is especially effective when deploying Agent(s) to utilize functions designed for particular tasks.

new_hyperfunction = HyperFunction()

@new_hyperfunction.takeover
def new_function(
    param1: str,
    param2: int = 100
):
    """Description for the new function"""
    ...

combined_hyperfunction = hyperfunction + new_hyperfunction
combined_hyperfunction.registry()
============================================================
get_current_weather(
   location: str,
   *,
   settings: Settings
):
"""Get the current weather."""
============================================================
new_function(
   param1: str,
   param2: int = 100
):
"""Description for the new function"""
============================================================

Conclusion

The key strength of this approach lies in its ability to automate schema creation, sparing developers the time and complexity of manual setup. By utilizing the takeover method, the system efficiently manages multiple functions within a HyperFunction instance, a boon for deploying Agents in LLM applications. This automation not only streamlines the development process but also ensures precision and adaptability in handling task-specific functions, making it a highly effective solution for agent-driven scenarios.

Metadata

Release files for hypertion 2.0.0

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

Source distribution (sdist)

Source distribution for hypertion 2.0.0
File Size Uploaded
hypertion-2.0.0.tar.gz 21.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hypertion 2.0.0
File Interpreter ABI Platform
hypertion-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 56.4 kB

Release files / hypertion-2.0.0.tar.gz

Download URL hypertion-2.0.0.tar.gz
Size 21.2 kB
Tags Source
SHA-256 checksum
How to use checksums
70dbe5db52f075a2448f5c5d22ed24800b9d63cc522dbdc0a5a2b99fb6348ac7
BLAKE2b-256 checksum
How to use checksums
2a3d305657be4b818ea91d5f59956f824675b386c40e87ee7ea408895a767b16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.11 Windows/10

Release files / hypertion-2.0.0-py3-none-any.whl

Download URL hypertion-2.0.0-py3-none-any.whl
Size 35.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3f689598f67bd21b75d0d659568081555d7984c0cfd760c4eb6099d3df3d484
BLAKE2b-256 checksum
How to use checksums
9ccf31c02233956b6661a305b3254a09de9212fcc3ca2fac21637502e11b133e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.11 Windows/10

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.0

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