# core


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

OpenAI function calling spec:
https://platform.openai.com/docs/guides/function-calling#defining-functions

We’re extracting the following information directly from a Python
function:

``` json
{
    "type": "function",
    "name": "get_weather",
    "description": "Retrieves current weather for the given location.",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "City and country e.g. Bogotá, Colombia"
            },
            "units": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"],
                "description": "Units the temperature will be returned in."
            }
        },
        "required": ["location", "units"],
        "additionalProperties": false
    },
    "strict": true
}
```

``` python
def _test_get_weather(
    city: str  # City name
) -> str:  # Returns the weather in a city, e.g. "rainy"
    """Get the current weather for a city"""

    if city.lower() == "tokyo": weather = "sunny"
    elif city.lower() == "amsterdam": weather = "cloudy"
    else: weather = "rainy"

    return weather
```

### docments test

``` python
docments(_test_get_weather, full=True)
```

``` python
{ 'city': { 'anno': <class 'str'>,
            'default': <class 'inspect._empty'>,
            'docment': 'City name'},
  'return': { 'anno': <class 'str'>,
              'default': <class 'inspect._empty'>,
              'docment': 'Returns the weather in a city, e.g. "rainy"'}}
```

------------------------------------------------------------------------

<a
href="https://github.com/NumesSanguis/func2llmtool/blob/main/func2llmtool/core.py#L17"
target="_blank" style="float:right; font-size:smaller">source</a>

### FuncInfoPropsParam

``` python

def FuncInfoPropsParam(
    type:str, description:str
)->None:

```

*Info related to argument, including automatic conversion*

------------------------------------------------------------------------

<a
href="https://github.com/NumesSanguis/func2llmtool/blob/main/func2llmtool/core.py#L30"
target="_blank" style="float:right; font-size:smaller">source</a>

### FuncInfo

``` python

def FuncInfo(
    func_name:str, description:str, properties:dict, required:list, additional_properties:bool=False,
    strict:bool=True
)->None:

```

*Class that stores all data to outputing a OpenAI / LiteLLM tool
description and necessary conversion functions.*

``` python
fi = FuncInfo.from_func(_test_get_weather)
fi
```

    {
        "type": "function",
        "function": {
            "name": "_test_get_weather",
            "description": "Get the current weather for a city Return type: string (Returns the weather in a city, e.g. \"rainy\")",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {
                        "type": "string",
                        "description": "City name"
                    }
                },
                "required": [
                    "city"
                ],
                "additionalProperties": false
            }
        }
    }

``` python
fi.to_tool_dict(format="openai")
```

    {'type': 'function',
     'name': '_test_get_weather',
     'description': 'Get the current weather for a city Return type: string (Returns the weather in a city, e.g. "rainy")',
     'parameters': {'type': 'object',
      'properties': {'city': {'type': 'string', 'description': 'City name'}},
      'required': ['city'],
      'additionalProperties': False},
     'strict': True}

``` python
fi()
```

    {'type': 'function',
     'function': {'name': '_test_get_weather',
      'description': 'Get the current weather for a city Return type: string (Returns the weather in a city, e.g. "rainy")',
      'parameters': {'type': 'object',
       'properties': {'city': {'type': 'string', 'description': 'City name'}},
       'required': ['city'],
       'additionalProperties': False}}}

``` python
print(fi)
```

    {
        "type": "function",
        "function": {
            "name": "_test_get_weather",
            "description": "Get the current weather for a city Return type: string (Returns the weather in a city, e.g. \"rainy\")",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {
                        "type": "string",
                        "description": "City name"
                    }
                },
                "required": [
                    "city"
                ],
                "additionalProperties": false
            }
        }
    }

``` python
FuncInfo.from_func('_test_get_weather')()
```

    {'type': 'function',
     'function': {'name': '_test_get_weather',
      'description': 'Get the current weather for a city Return type: string (Returns the weather in a city, e.g. "rainy")',
      'parameters': {'type': 'object',
       'properties': {'city': {'type': 'string', 'description': 'City name'}},
       'required': ['city'],
       'additionalProperties': False}}}

## Numpy style docstring parsing

Proper docstring extraction from `_test_get_weather_numpy_style`.

``` python
# define our tool function with numpy-style docstring
def _test_get_weather_numpy_style(city: str) -> str:
    """
    Get the current weather for a city.

    Parameters
    ----------
    city : str
        City name

    Returns
    -------
    str
        The weather in a city, e.g. "rainy"
    """

    if city.lower() == "tokyo": weather = "sunny"
    elif city.lower() == "amsterdam": weather = "cloudy"
    else: weather = "rainy"

    return weather
```

``` python
parsed = parse_docstring(_test_get_weather_numpy_style.__doc__)
parsed
```

``` python
{ 'Also': '',
  'Attributes': '',
  'Examples': '',
  'Extended': '',
  'Methods': '',
  'Notes': '',
  'Other': '',
  'Parameters': { 'city': Parameter(name='city', type='str', desc=['City name'])},
  'Raises': '',
  'Receives': '',
  'References': '',
  'Returns': Parameter(name='', type='str', desc=['The weather in a city, e.g. "rainy"']),
  'See': '',
  'Summary': 'Get the current weather for a city.',
  'Warnings': '',
  'Warns': '',
  'Yields': ''}
```

``` python
desc = parsed.get('Summary', _test_get_weather_numpy_style.__doc__).strip() if parsed else f.__doc__
desc
```

    'Get the current weather for a city.'

``` python
FuncInfo.from_func('_test_get_weather_numpy_style')()
```

    {'type': 'function',
     'function': {'name': '_test_get_weather_numpy_style',
      'description': 'Get the current weather for a city. Return type: string (The weather in a city, e.g. "rainy")',
      'parameters': {'type': 'object',
       'properties': {'city': {'type': 'string', 'description': 'City name'}},
       'required': ['city'],
       'additionalProperties': False}}}
