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
hypertionlibrary 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
HyperFunctioninstance can hold multiple functions. Creating a newHyperFunctioninstance 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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hypertion-2.0.0.tar.gz | 21.2 kB | Without provenance | Details for hypertion-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hypertion-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for hypertion-2.0.0-py3-none-any.whl |
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
|
Security for hypertion 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.