test_convert_to_openai_function() — langchain Function Reference
Architecture documentation for the test_convert_to_openai_function() function in test_function_calling.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5b190abd_4f34_7ff3_d435_34242e3f9192["test_convert_to_openai_function()"] 6f1e8e6f_d3f9_e590_b17e_1dc8afafdbe0["test_function_calling.py"] 5b190abd_4f34_7ff3_d435_34242e3f9192 -->|defined in| 6f1e8e6f_d3f9_e590_b17e_1dc8afafdbe0 style 5b190abd_4f34_7ff3_d435_34242e3f9192 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/utils/test_function_calling.py lines 312–406
def test_convert_to_openai_function(
pydantic: type[BaseModel],
function: Callable,
function_docstring_annotations: Callable,
dummy_structured_tool: StructuredTool,
dummy_structured_tool_args_schema_dict: StructuredTool,
dummy_tool: BaseTool,
json_schema: dict,
anthropic_tool: dict,
bedrock_converse_tool: dict,
annotated_function: Callable,
dummy_pydantic: type[BaseModel],
runnable: Runnable,
dummy_typing_typed_dict: type,
dummy_typing_typed_dict_docstring: type,
dummy_extensions_typed_dict: type,
dummy_extensions_typed_dict_docstring: type,
) -> None:
expected = {
"name": "dummy_function",
"description": "Dummy function.",
"parameters": {
"type": "object",
"properties": {
"arg1": {"description": "foo", "type": "integer"},
"arg2": {
"description": "one of 'bar', 'baz'",
"enum": ["bar", "baz"],
"type": "string",
},
},
"required": ["arg1", "arg2"],
},
}
for fn in (
pydantic,
function,
function_docstring_annotations,
dummy_structured_tool,
dummy_structured_tool_args_schema_dict,
dummy_tool,
json_schema,
anthropic_tool,
bedrock_converse_tool,
expected,
Dummy.dummy_function,
DummyWithClassMethod.dummy_function,
annotated_function,
dummy_pydantic,
dummy_typing_typed_dict,
dummy_typing_typed_dict_docstring,
dummy_extensions_typed_dict,
dummy_extensions_typed_dict_docstring,
):
actual = convert_to_openai_function(fn)
assert actual == expected
# Test runnables
actual = convert_to_openai_function(runnable.as_tool(description="Dummy function."))
parameters = {
"type": "object",
"properties": {
"arg1": {"type": "integer"},
"arg2": {
"enum": ["bar", "baz"],
"type": "string",
},
},
"required": ["arg1", "arg2"],
}
runnable_expected = expected.copy()
runnable_expected["parameters"] = parameters
assert actual == runnable_expected
# Test simple Tool
def my_function(_: str) -> str:
return ""
tool = Tool(
name="dummy_function",
Domain
Subdomains
Source
Frequently Asked Questions
What does test_convert_to_openai_function() do?
test_convert_to_openai_function() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/utils/test_function_calling.py.
Where is test_convert_to_openai_function() defined?
test_convert_to_openai_function() is defined in libs/core/tests/unit_tests/utils/test_function_calling.py at line 312.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free