NousResearch / Hermes-Function-Calling

MIT License
475 stars 74 forks source link

This Repo needs some refactoring for the function calling to work properly #14

Open ViperX7 opened 3 months ago

ViperX7 commented 3 months ago

Guys i think there is some issue with the way things are implemented currently in this repo biggest of which is regarding coding standard

currently you guys use convert_to_openai_tool from langchain_core.utils.function_calling in order to convert python functions to a dict representing a tool but the examples in functions.py don't follow the standard properly

the following function is used to parse things upstream inside langchain

def _parse_python_function_docstring(function: Callable) -> Tuple[str, dict]:
    """Parse the function and argument descriptions from the docstring of a function.
    Assumes the function docstring follows Google Python style guide.
    """

and if we use anything but the google python style guide the code messes up the returned dict for example

def code_interpreter(code_markdown: str) -> dict | str:
    """Execute the provided Python code string on the terminal using exec.

    The string should contain valid, executable and pure python code in markdown syntax.
    Code should also import any required python packages.

    Args:
        code_markdown: The Python code with markdown syntax to be executed.

    Returns:
        A dictionary containing variables declared and values returned by function calls.

    """
    .
    .
    .

this is proper format and when parsed with convert_to_openai_tool will return

{
    'type': 'function',
    'function': {
        'name': 'code_interpreter',
        'description': 'Execute the provided Python code string on the terminal using exec. The string should contain valid, executable and pure python code in
markdown syntax.\nCode should also import any required python packages.',
        'parameters': {
            'type': 'object',
            'properties': {'code_markdown': {'type': 'string', 'description': 'The Python code with markdown syntax to be executed.'}},
            'required': ['code_markdown']
        }
    }
}

the current version of the same function in functions.py returns

{
    'type': 'function',
    'function': {
        'name': 'code_interpreter',
        'description': '    Execute the provided Python code string on the terminal using exec.\n    The string should contain valid, executable and pure
python code in markdown syntax.\n    Code should also import any required python packages.     Parameters:\n    - code_markdown (str): The Python code with
markdown syntax to be executed.\n      for eg. ```python\n<code-string>\n```     Returns:\n    dict: A dictionary containing variables declared and values
returned by function calls.     Note: Use this function with caution, as executing arbitrary code can pose security risks.\n    ',
        'parameters': {'type': 'object', 'properties': {'code_markdown': {'type': 'string'}}, 'required': ['code_markdown']}
    }
}

you can clearly see that description messes up a lot of things in short code style for python function tools is really important and this should be mentioned in the repo

Currently using multiple tools breaks everything the reason for which is improper tool dicts so i request a total rewrite of all function descriptions in proper formats it will make examples much better

interstellarninja commented 3 months ago

we are using convert_to_openai_tool() as is without any modification, so could you point us to where the discrepancy you presented above could be stemming from?