hypertion


Namehypertion JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/synacktraa/hypertion
SummaryStreamlined and Efficient LLM function calling.
upload_time2024-06-29 11:49:06
maintainerNone
docs_urlNone
authorHarsh Verma
requires_python<4.0,>=3.8
licenseGPL-3.0-only
keywords function-calling functionary gorilla mistral claude gpt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <img src="./assets/main.gif" alt="hypertion">
</div>

---

<p align="center">Making LLM Function-Calling Simpler.</p>


## 🚀 Installation

```sh
pip install hypertion
```

---

## Usage 🤗

#### Create a `HyperFunction` instance

```py
from hypertion import HyperFunction

hyperfunction = HyperFunction()
```

#### Use the `takeover` method to register the function

> Check [notebooks](./notebooks) directory for complex function usage.

```py
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

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

#### Register a predefined function

```python
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`

```python
hyperfunction.format(as_json=True)
# hyperfunction.format('<format>', as_json=True)
```
```json
[
    {
        "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](https://colab.research.google.com/drive/1DKkXHdebEgj7AfXqw6Ro17KQ1RUBMgco?usp=sharing) for live example.

```python
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

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

### Compose function `metadata` as function-call object

> Try [Functionary+Hypertion Colab](https://colab.research.google.com/drive/1azzJiAcYRFItlzwEfRPk6UzDUPVAZkUl?usp=sharing) for live example.

```python
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

```python
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.

```py
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.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/synacktraa/hypertion",
    "name": "hypertion",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "function-calling, functionary, gorilla, mistral, claude, gpt",
    "author": "Harsh Verma",
    "author_email": "synacktra.work@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2a/3d/305657be4b818ea91d5f59956f824675b386c40e87ee7ea408895a767b16/hypertion-2.0.0.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  <img src=\"./assets/main.gif\" alt=\"hypertion\">\n</div>\n\n---\n\n<p align=\"center\">Making LLM Function-Calling Simpler.</p>\n\n\n## \ud83d\ude80 Installation\n\n```sh\npip install hypertion\n```\n\n---\n\n## Usage \ud83e\udd17\n\n#### Create a `HyperFunction` instance\n\n```py\nfrom hypertion import HyperFunction\n\nhyperfunction = HyperFunction()\n```\n\n#### Use the `takeover` method to register the function\n\n> Check [notebooks](./notebooks) directory for complex function usage.\n\n```py\nfrom typing import Literal\nfrom typing_extensions import TypedDict\n\nclass Settings(TypedDict):\n    \"\"\"\n    Settings\n    @param unit: The unit scale to represent temperature.\n    @param forecast: If set to True, returns the forecasting.\n    \"\"\"\n    unit: Literal['celsius', 'fahrenheit']\n    forecast: bool = False\n\n@hyperfunction.takeover\ndef get_current_weather(location: str, *, settings: Settings):\n    \"\"\"\n    Get the current weather.\n    @param location: Location to search for.\n    @param settings: Settings to use for getting current weather.\n    \"\"\"\n    info = {\n        \"location\": location,\n        \"temperature\": \"72\",\n        \"unit\": settings['unit'],\n    }\n    if settings['forecast'] is True:\n        return info | {\"forecast\": [\"sunny\", \"windy\"]}\n    \n    return info\n```\n\nSupported Types: `str` | `int` | `float` | `bool` | `list` | `dict` | `pathlib.Path` | `typing.List` | `typing.Dict` | `typing.NamedTuple` | `typing_extensions.TypedDict` | `pydantic.BaseModel` | `typing.Literal` | `enum.Enum`\n\n#### List registered functions\n\n```python\nhyperfunction.registry()\n```\n```\n============================================================\nget_current_weather(\n   location: str,\n   *,\n   settings: Settings\n):\n\"\"\"Get the current weather.\"\"\"\n============================================================\n```\n\n#### Register a predefined function\n\n```python\nfrom some_module import some_function\n\nhyperfunction.takeover(\n    some_function,\n    docstring=\"<Override docstring for the function>\"\n)\n```\n\n### Use the `format` method to get function schema\n\n> LLM specific formats are available: `functionary`, `gorilla`, `mistral`, `gpt`, `claude`\n\n```python\nhyperfunction.format(as_json=True)\n# hyperfunction.format('<format>', as_json=True)\n```\n```json\n[\n    {\n        \"name\": \"get_current_weather\",\n        \"description\": \"Get the current weather.\",\n        \"parameters\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"location\": {\n                    \"type\": \"string\",\n                    \"description\": \"Location to search for.\"\n                },\n                \"settings\": {\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"unit\": {\n                            \"type\": \"string\",\n                            \"enum\": [\n                                \"celsius\",\n                                \"fahrenheit\"\n                            ],\n                            \"description\": \"The unit scale to represent temperature.\"\n                        },\n                        \"forecast\": {\n                            \"type\": \"boolean\",\n                            \"description\": \"If set to True, returns the forecasting.\"\n                        }\n                    },\n                    \"required\": [\n                        \"unit\"\n                    ],\n                    \"description\": \"Settings to use for getting current weather.\"\n                }\n            },\n            \"required\": [\n                \"location\",\n                \"settings\"\n            ]\n        }\n    }\n]\n```\n---\n\n### Compose function `signature` as function-call object\n\n> Try [Gorilla+Hypertion Colab](https://colab.research.google.com/drive/1DKkXHdebEgj7AfXqw6Ro17KQ1RUBMgco?usp=sharing) for live example.\n\n```python\nsignature =  \"\"\"\nget_current_weather(\n    location='Kolkata', settings={'unit': 'fahrenheit'}\n)\n\"\"\"\nfunction_call = hyperfunction.compose(signature)\nfunction_call\n```\n```\nget_current_weather(\n   location='Kolkata',\n   settings={'unit': 'fahrenheit', 'forecast': False}\n)\n```\n\nInvoke the `function-call` object\n\n```python\nfunction_call()\n```\n```\n{'location': 'Kolkata', 'temperature': '72', 'unit': 'fahrenheit'}\n```\n\n### Compose function `metadata` as function-call object\n\n> Try [Functionary+Hypertion Colab](https://colab.research.google.com/drive/1azzJiAcYRFItlzwEfRPk6UzDUPVAZkUl?usp=sharing) for live example.\n\n```python\nname = 'get_current_weather'\narguments = '{\"location\": \"Kolkata\", \"settings\": {\"unit\": \"fahrenheit\", \"forecast\": true}}'\nfunction_call = hyperfunction.compose(name=name, arguments=arguments) # Accepts both JsON and dictionary object\nfunction_call\n```\n```\nget_current_weather(\n   location='Kolkata',\n   settings={'unit': 'fahrenheit', 'forecast': True}\n)\n```\n\nInvoke the `function-call` object\n\n```python\nfunction_call()\n```\n```\n{'location': 'Kolkata', 'temperature': '72', 'unit': 'fahrenheit', 'forecast': ['sunny', 'windy']}\n```\n\n> 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.\n\n\n#### Combining two `HyperFunction` instance\n\n> 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.\n\n```py\nnew_hyperfunction = HyperFunction()\n\n@new_hyperfunction.takeover\ndef new_function(\n    param1: str,\n    param2: int = 100\n):\n    \"\"\"Description for the new function\"\"\"\n    ...\n\ncombined_hyperfunction = hyperfunction + new_hyperfunction\ncombined_hyperfunction.registry()\n```\n```\n============================================================\nget_current_weather(\n   location: str,\n   *,\n   settings: Settings\n):\n\"\"\"Get the current weather.\"\"\"\n============================================================\nnew_function(\n   param1: str,\n   param2: int = 100\n):\n\"\"\"Description for the new function\"\"\"\n============================================================\n```\n\n### Conclusion\n\nThe 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.",
    "bugtrack_url": null,
    "license": "GPL-3.0-only",
    "summary": "Streamlined and Efficient LLM function calling.",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/synacktraa/hypertion",
        "Repository": "https://github.com/synacktraa/hypertion"
    },
    "split_keywords": [
        "function-calling",
        " functionary",
        " gorilla",
        " mistral",
        " claude",
        " gpt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ccf31c02233956b6661a305b3254a09de9212fcc3ca2fac21637502e11b133e",
                "md5": "6c693e7af43c009704fff4559595a12a",
                "sha256": "e3f689598f67bd21b75d0d659568081555d7984c0cfd760c4eb6099d3df3d484"
            },
            "downloads": -1,
            "filename": "hypertion-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6c693e7af43c009704fff4559595a12a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 35248,
            "upload_time": "2024-06-29T11:49:04",
            "upload_time_iso_8601": "2024-06-29T11:49:04.748929Z",
            "url": "https://files.pythonhosted.org/packages/9c/cf/31c02233956b6661a305b3254a09de9212fcc3ca2fac21637502e11b133e/hypertion-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a3d305657be4b818ea91d5f59956f824675b386c40e87ee7ea408895a767b16",
                "md5": "a0b5676e925017c6f4a15525ad39e9c1",
                "sha256": "70dbe5db52f075a2448f5c5d22ed24800b9d63cc522dbdc0a5a2b99fb6348ac7"
            },
            "downloads": -1,
            "filename": "hypertion-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a0b5676e925017c6f4a15525ad39e9c1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 21199,
            "upload_time": "2024-06-29T11:49:06",
            "upload_time_iso_8601": "2024-06-29T11:49:06.221976Z",
            "url": "https://files.pythonhosted.org/packages/2a/3d/305657be4b818ea91d5f59956f824675b386c40e87ee7ea408895a767b16/hypertion-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-29 11:49:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "synacktraa",
    "github_project": "hypertion",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "hypertion"
}
        
Elapsed time: 5.04125s