convert_to_openai_function#

langchain_core.utils.function_calling.convert_to_openai_function(function: Dict[str, Any] | Type | Callable | BaseTool, *, strict: bool | None = None) β†’ Dict[str, Any][source]#

Convert a raw function/class to an OpenAI function.

Changed in version 0.2.29: strict arg added.

Parameters:
  • function (Union[Dict[str, Any], Type, Callable, BaseTool]) – A dictionary, Pydantic BaseModel class, TypedDict class, a LangChain Tool object, or a Python function. If a dictionary is passed in, it is assumed to already be a valid OpenAI function or a JSON schema with top-level β€˜title’ and β€˜description’ keys specified.

  • strict (Optional[bool]) –

    If True, model output is guaranteed to exactly match the JSON Schema provided in the function definition. If None, strict argument will not be included in function definition.

    New in version 0.2.29.

Returns:

A dict version of the passed in function which is compatible with the OpenAI function-calling API.

Raises:

ValueError – If function is not in a supported format.

Return type:

Dict[str, Any]

Examples using convert_to_openai_function