Home / Function/ _convert_python_function_to_openai_function() — langchain Function Reference

_convert_python_function_to_openai_function() — langchain Function Reference

Architecture documentation for the _convert_python_function_to_openai_function() function in function_calling.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  eacd2ba7_a5e4_f7ce_ef57_cc7ef70c6e76["_convert_python_function_to_openai_function()"]
  14ab3d97_532b_bb37_6d2f_7248501f1cb8["function_calling.py"]
  eacd2ba7_a5e4_f7ce_ef57_cc7ef70c6e76 -->|defined in| 14ab3d97_532b_bb37_6d2f_7248501f1cb8
  0f5a84d8_de71_8584_be44_11eb4638cb79["convert_to_openai_function()"]
  0f5a84d8_de71_8584_be44_11eb4638cb79 -->|calls| eacd2ba7_a5e4_f7ce_ef57_cc7ef70c6e76
  864dc226_b2fd_e5e9_7698_fc933e24b7ae["_get_python_function_name()"]
  eacd2ba7_a5e4_f7ce_ef57_cc7ef70c6e76 -->|calls| 864dc226_b2fd_e5e9_7698_fc933e24b7ae
  730ff227_fb8d_905a_795b_7b8c5620289e["_convert_pydantic_to_openai_function()"]
  eacd2ba7_a5e4_f7ce_ef57_cc7ef70c6e76 -->|calls| 730ff227_fb8d_905a_795b_7b8c5620289e
  style eacd2ba7_a5e4_f7ce_ef57_cc7ef70c6e76 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/utils/function_calling.py lines 200–228

def _convert_python_function_to_openai_function(
    function: Callable,
) -> FunctionDescription:
    """Convert a Python function to an OpenAI function-calling API compatible dict.

    Assumes the Python function has type hints and a docstring with a description. If
    the docstring has Google Python style argument descriptions, these will be included
    as well.

    Args:
        function: The Python function to convert.

    Returns:
        The OpenAI function description.
    """
    func_name = _get_python_function_name(function)
    model = langchain_core.tools.base.create_schema_from_function(
        func_name,
        function,
        filter_args=(),
        parse_docstring=True,
        error_on_invalid_docstring=False,
        include_injected=False,
    )
    return _convert_pydantic_to_openai_function(
        model,
        name=func_name,
        description=model.__doc__,
    )

Domain

Subdomains

Frequently Asked Questions

What does _convert_python_function_to_openai_function() do?
_convert_python_function_to_openai_function() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/function_calling.py.
Where is _convert_python_function_to_openai_function() defined?
_convert_python_function_to_openai_function() is defined in libs/core/langchain_core/utils/function_calling.py at line 200.
What does _convert_python_function_to_openai_function() call?
_convert_python_function_to_openai_function() calls 2 function(s): _convert_pydantic_to_openai_function, _get_python_function_name.
What calls _convert_python_function_to_openai_function()?
_convert_python_function_to_openai_function() is called by 1 function(s): convert_to_openai_function.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free