OpenAIFunctionsRouter Class — langchain Architecture
Architecture documentation for the OpenAIFunctionsRouter class in openai_functions.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5868cd0c_95e8_cfc9_0f2f_dd87c0c8c58c["OpenAIFunctionsRouter"] 7d2fab00_7717_5a90_b625_00b2f4edd6b0["openai_functions.py"] 5868cd0c_95e8_cfc9_0f2f_dd87c0c8c58c -->|defined in| 7d2fab00_7717_5a90_b625_00b2f4edd6b0 cebb4bc5_17a4_cf9c_fff4_64f33107eb34["__init__()"] 5868cd0c_95e8_cfc9_0f2f_dd87c0c8c58c -->|method| cebb4bc5_17a4_cf9c_fff4_64f33107eb34
Relationship Graph
Source Code
libs/langchain/langchain_classic/runnables/openai_functions.py lines 23–54
class OpenAIFunctionsRouter(RunnableBindingBase[BaseMessage, Any]): # type: ignore[no-redef]
"""A runnable that routes to the selected function."""
functions: list[OpenAIFunction] | None
def __init__(
self,
runnables: Mapping[
str,
Runnable[dict, Any] | Callable[[dict], Any],
],
functions: list[OpenAIFunction] | None = None,
):
"""Initialize the `OpenAIFunctionsRouter`.
Args:
runnables: A mapping of function names to runnables.
functions: Optional list of functions to check against the runnables.
"""
if functions is not None:
if len(functions) != len(runnables):
msg = "The number of functions does not match the number of runnables."
raise ValueError(msg)
if not all(func["name"] in runnables for func in functions):
msg = "One or more function names are not found in runnables."
raise ValueError(msg)
router = (
JsonOutputFunctionsParser(args_only=False)
| {"key": itemgetter("name"), "input": itemgetter("arguments")}
| RouterRunnable(runnables)
)
super().__init__(bound=router, kwargs={}, functions=functions)
Source
Frequently Asked Questions
What is the OpenAIFunctionsRouter class?
OpenAIFunctionsRouter is a class in the langchain codebase, defined in libs/langchain/langchain_classic/runnables/openai_functions.py.
Where is OpenAIFunctionsRouter defined?
OpenAIFunctionsRouter is defined in libs/langchain/langchain_classic/runnables/openai_functions.py at line 23.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free