},          "punchline": {            "type": "string",            "description": "The punchline for the joke"          }        },        "required": ["setup", "punchline"]      }    }  ]chain = prompt | model.bind(function_call= {"name": "joke"}, functions= functions)chain.invoke({"foo": "bears"}, config={})    AIMessage(content='', additional_kwargs={'function_call': {'name': 'joke', 'arguments': '{\n  "setup": "Why don\'t bears wear shoes?",\n  "punchline": "Because they have bear feet!"\n}'}}, example=False)PromptTemplate + LLM + OutputParser‚ÄãWe can also add in an output parser to easily transform the raw LLM/ChatModel output into a more workable formatfrom langchain.schema.output_parser import StrOutputParserchain = prompt | model | StrOutputParser()Notice that this now returns a string - a much more workable format for downstream taskschain.invoke({"foo": "bears"})    "Why don't bears wear shoes?\n\nBecause they have bear feet!"Functions Output Parser‚ÄãWhen you specify the function to return, you may just want to parse that directlyfrom langchain.output_parsers.openai_functions import JsonOutputFunctionsParserchain = (    prompt     | model.bind(function_call= {"name": "joke"}, functions= functions)     | JsonOutputFunctionsParser())chain.invoke({"foo": "bears"})    {'setup': "Why don't bears like fast food?",     'punchline': "Because they can't catch it!"}from langchain.output_parsers.openai_functions import JsonKeyOutputFunctionsParserchain = (    prompt     | model.bind(function_call= {"name": "joke"}, functions= functions)     | JsonKeyOutputFunctionsParser(key_name="setup"))chain.invoke({"foo": "bears"})    "Why don't bears wear shoes?"Simplifying input‚ÄãTo make invocation even simpler, we can add a RunnableMap to take care of creating the prompt input dict for us:from langchain.schema.runnable import RunnableMap, RunnablePassthroughmap_ = RunnableMap(foo=RunnablePassthrough())chain = (    map_     | prompt    | model.bind(function_call=
The most common and valuable composition is taking:
The most common and valuable composition is taking: ->: },          "punchline": {            "type": "string",            "description": "The punchline for the joke"          }        },        "required": ["setup", "punchline"]      }    }  ]chain = prompt | model.bind(function_call= {"name": "joke"}, functions= functions)chain.invoke({"foo": "bears"}, config={})    AIMessage(content='', additional_kwargs={'function_call': {'name': 'joke', 'arguments': '{\n  "setup": "Why don\'t bears wear shoes?",\n  "punchline": "Because they have bear feet!"\n}'}}, example=False)PromptTemplate + LLM + OutputParser‚ÄãWe can also add in an output parser to easily transform the raw LLM/ChatModel output into a more workable formatfrom langchain.schema.output_parser import StrOutputParserchain = prompt | model | StrOutputParser()Notice that this now returns a string - a much more workable format for downstream taskschain.invoke({"foo": "bears"})    "Why don't bears wear shoes?\n\nBecause they have bear feet!"Functions Output Parser‚ÄãWhen you specify the function to return, you may just want to parse that directlyfrom langchain.output_parsers.openai_functions import JsonOutputFunctionsParserchain = (    prompt     | model.bind(function_call= {"name": "joke"}, functions= functions)     | JsonOutputFunctionsParser())chain.invoke({"foo": "bears"})    {'setup': "Why don't bears like fast food?",     'punchline': "Because they can't catch it!"}from langchain.output_parsers.openai_functions import JsonKeyOutputFunctionsParserchain = (    prompt     | model.bind(function_call= {"name": "joke"}, functions= functions)     | JsonKeyOutputFunctionsParser(key_name="setup"))chain.invoke({"foo": "bears"})    "Why don't bears wear shoes?"Simplifying input‚ÄãTo make invocation even simpler, we can add a RunnableMap to take care of creating the prompt input dict for us:from langchain.schema.runnable import RunnableMap, RunnablePassthroughmap_ = RunnableMap(foo=RunnablePassthrough())chain = (    map_     | prompt    | model.bind(function_call=