convert_to_openai_tool#

langchain_core.utils.function_calling.convert_to_openai_tool(tool: dict[str, Any] | type[BaseModel] | Callable | BaseTool, *, strict: bool | None = None) โ†’ dict[str, Any][source]#

Convert a raw function/class to an OpenAI tool.

Changed in version 0.2.29: strict arg added.

Parameters:
  • tool (Union[dict[str, Any], type[BaseModel], Callable, BaseTool]) โ€“ Either a dictionary, a pydantic.BaseModel class, Python function, or BaseTool. If a dictionary is passed in, it is assumed to already be a valid OpenAI tool, 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 tool definition.

    Added in version 0.2.29.

Returns:

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

Return type:

dict[str, Any]

Examples using convert_to_openai_tool