Streamlined and Efficient LLM function calling.
Project description
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 newHyperFunction
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hypertion-2.0.0.tar.gz
.
File metadata
- Download URL: hypertion-2.0.0.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.11 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70dbe5db52f075a2448f5c5d22ed24800b9d63cc522dbdc0a5a2b99fb6348ac7 |
|
MD5 | a0b5676e925017c6f4a15525ad39e9c1 |
|
BLAKE2b-256 | 2a3d305657be4b818ea91d5f59956f824675b386c40e87ee7ea408895a767b16 |
File details
Details for the file hypertion-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: hypertion-2.0.0-py3-none-any.whl
- Upload date:
- Size: 35.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.11 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3f689598f67bd21b75d0d659568081555d7984c0cfd760c4eb6099d3df3d484 |
|
MD5 | 6c693e7af43c009704fff4559595a12a |
|
BLAKE2b-256 | 9ccf31c02233956b6661a305b3254a09de9212fcc3ca2fac21637502e11b133e |