openai_functions.py — langchain Source File
Architecture documentation for openai_functions.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR af38f3fd_031e_ad79_a723_78c2b720f207["openai_functions.py"] cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] af38f3fd_031e_ad79_a723_78c2b720f207 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 7aaf52d4_ee88_411e_980e_bc4beeeb30ad["operator"] af38f3fd_031e_ad79_a723_78c2b720f207 --> 7aaf52d4_ee88_411e_980e_bc4beeeb30ad 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] af38f3fd_031e_ad79_a723_78c2b720f207 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] af38f3fd_031e_ad79_a723_78c2b720f207 --> d758344f_537f_649e_f467_b9d7442e86df 89a4ade4_215f_cae5_8190_9505303396df["langchain_core.output_parsers.openai_functions"] af38f3fd_031e_ad79_a723_78c2b720f207 --> 89a4ade4_215f_cae5_8190_9505303396df 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"] af38f3fd_031e_ad79_a723_78c2b720f207 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c c764ccae_0d75_abec_7c23_6d5d1949a7ba["langchain_core.runnables.base"] af38f3fd_031e_ad79_a723_78c2b720f207 --> c764ccae_0d75_abec_7c23_6d5d1949a7ba 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] af38f3fd_031e_ad79_a723_78c2b720f207 --> 91721f45_4909_e489_8c1f_084f8bd87145 style af38f3fd_031e_ad79_a723_78c2b720f207 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from collections.abc import Callable, Mapping
from operator import itemgetter
from typing import Any
from langchain_core.messages import BaseMessage
from langchain_core.output_parsers.openai_functions import JsonOutputFunctionsParser
from langchain_core.runnables import RouterRunnable, Runnable
from langchain_core.runnables.base import RunnableBindingBase
from typing_extensions import TypedDict
class OpenAIFunction(TypedDict):
"""A function description for `ChatOpenAI`."""
name: str
"""The name of the function."""
description: str
"""The description of the function."""
parameters: dict
"""The parameters to the function."""
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)
Domain
Subdomains
Dependencies
- collections.abc
- langchain_core.messages
- langchain_core.output_parsers.openai_functions
- langchain_core.runnables
- langchain_core.runnables.base
- operator
- typing
- typing_extensions
Source
Frequently Asked Questions
What does openai_functions.py do?
openai_functions.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What does openai_functions.py depend on?
openai_functions.py imports 8 module(s): collections.abc, langchain_core.messages, langchain_core.output_parsers.openai_functions, langchain_core.runnables, langchain_core.runnables.base, operator, typing, typing_extensions.
Where is openai_functions.py in the architecture?
openai_functions.py is located at libs/langchain/langchain_classic/runnables/openai_functions.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/langchain_classic/runnables).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free