[docs]classOpenAIFunction(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."""
[docs]classOpenAIFunctionsRouter(RunnableBindingBase[BaseMessage,Any]):"""A runnable that routes to the selected function."""functions:Optional[List[OpenAIFunction]]def__init__(self,runnables:Mapping[str,Union[Runnable[dict,Any],Callable[[dict],Any],],],functions:Optional[List[OpenAIFunction]]=None,):iffunctionsisnotNone:assertlen(functions)==len(runnables)assertall(func["name"]inrunnablesforfuncinfunctions)router=(JsonOutputFunctionsParser(args_only=False)|{"key":itemgetter("name"),"input":itemgetter("arguments")}|RouterRunnable(runnables))super().__init__(bound=router,kwargs={},functions=functions)