Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ViperX7 opened this issue Apr 4, 2024 · 1 comment

Comments

@ViperX7
Copy link
Contributor

ViperX7 commented Apr 4, 2024

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
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants