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.Added 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