{"id":8123,"date":"2023-11-08T05:34:29","date_gmt":"2023-11-08T13:34:29","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=8123"},"modified":"2025-04-24T17:04:36","modified_gmt":"2025-04-24T17:04:36","slug":"chaining-the-future-an-in-depth-dive-into-langchain","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/","title":{"rendered":"Chaining the Future: An In-depth Dive into LangChain"},"content":{"rendered":"\n<h2 class=\"wp-block-heading pw-subtitle-paragraph tt fy tg be b tu tv tw tx ty tz ua ub uc ud ue uf ug uh ui ro dq\" id=\"f4e3\">Exploring LLMChain, RouterChain, SimpleSequentialChain, and TransformChain for Advanced Language Model Interactions<\/h2>\n\n\n\n<figure class=\"xu xv xw xx xy xz lo lp paragraph-image\">\n<div class=\"ya yb dl yc bg yd\" tabindex=\"0\" role=\"button\">\n<div class=\"lo lp xt\">\n<\/div><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image alignnone bg ye yf c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*X7eM0S-smz0UvHRu\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Photo by\u00a0<a href=\"https:\/\/unsplash.com\/@_miltiadis_?utm_source=medium&amp;utm_medium=referral\">Miltiadis Fragkidis<\/a>\u00a0on\u00a0<a href=\"http:\/\/Unsplash.com\">Unsplash<\/a><\/figcaption><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" id=\"c6ae\">LangChain introduces a revolutionary way to harness the power of language models.<\/p>\n\n\n\n<div class=\"ew tb tc td te\">\n<div class=\"ab cm\">\n<div class=\"hy bg hz ia ib ic\">\n<p id=\"27d4\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">At the heart of this system lies the concept of \u201cchains\u201d \u2014 a sequence of interconnected components designed to execute tasks in a specific order. But what exactly are these chains, and how do they elevate the capabilities of language models? In this guide, we\u2019ll delve deep into the world of LangChain, exploring its core concepts, foundational chain types, and practical applications.<\/p>\n<p id=\"dd68\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">From breaking down complex tasks into manageable steps to maintaining context across multiple calls, LangChain offers a robust framework for building sophisticated language applications.<\/p>\n<p id=\"194b\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">Whether you\u2019re a developer aiming to optimize your language model interactions or a curious enthusiast eager to understand the next big thing in language processing, this guide will provide you with a comprehensive overview of LangChain\u2019s capabilities.<\/p>\n<p id=\"f4d2\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">Let\u2019s embark on this journey and unravel the magic of chains in LangChain!<\/p>\n<h2 id=\"2ace\" class=\"zc zd tg be ze zf zg tw mj zh zi tz mo zj zk zl zm zn zo zp zq zr zs zt zu zv bj\">\u26d3\ufe0f What are Chains in LangChain?<\/h2>\n<p id=\"0af0\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\">In one sentence: A chain is an end-to-end wrapper around multiple individual components executed in a defined order.<\/strong><\/p>\n<p id=\"4a83\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">Chains are one of the core concepts of LangChain. Chains allow you to go beyond just a single API call to a language model and instead chain together multiple calls in a logical sequence.<\/p>\n<p id=\"ac56\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">They allow you to combine multiple components to create a coherent application.<\/p>\n<p id=\"2d5d\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\"><strong class=\"be fx\">Some reasons you may want to use chains:<\/strong><\/p>\n<ul class=\"\">\n<li id=\"5422\" class=\"yk yl tg be b tu ym yn yo tx yp yq yr mp abb yt yu mu abc yw yx mz abd yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">To break down a complex task into smaller steps that can be handled sequentially by different models or utilities. This allows you to leverage the different strengths of different systems.<\/li>\n<li id=\"878b\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">To add state and memory between calls. The output of one call can be fed as input to the next call to provide context and state.<\/li>\n<li id=\"9f48\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">To add additional processing, filtering or validation logic between calls.<\/li>\n<li id=\"205d\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">For easier debugging and instrumentation of a sequence of calls.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"ab cm abm abn pj hb\" role=\"separator\"><\/div>\n\n\n\n<div class=\"ew tb tc td te\">\n<div class=\"ab cm\">\n<div class=\"hy bg hz ia ib ic\">\n<blockquote class=\"abr\"><p id=\"6570\" class=\"abs abt tg be abu abv abw abx aby abz aca zb dq\" data-selectable-paragraph=\"\">Want to learn how to build modern software with LLMs using the newest tools and techniques in the field?&nbsp;<a class=\"af hd\" href=\"https:\/\/www.comet.com\/production\/site\/llm-course\/?utm_source=Heartbeat&amp;utm_medium=referral&amp;utm_content=Medium&amp;utm_campaign=Heartbeat_LangChain_Series_HS\" target=\"_blank\" rel=\"noopener ugc nofollow\">Check out this free LLMOps course<\/a>&nbsp;from industry expert Elvis Saravia of DAIR.AI.<\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"ab cm abm abn pj hb\" role=\"separator\"><\/div>\n\n\n\n<div class=\"ew tb tc td te\">\n<div class=\"ab cm\">\n<div class=\"hy bg hz ia ib ic\">\n<h2 id=\"e412\" class=\"zc zd tg be ze zf acb tw mj zh acc tz mo zj acd zl zm zn ace zp zq zr acf zt zu zv bj\">Foundational chain types in LangChain<\/h2>\n<p id=\"913d\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">The&nbsp;<code class=\"eg acg ach aci acj b\">LLMChain<\/code>,&nbsp;<code class=\"eg acg ach aci acj b\">RouterChain<\/code>,&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>, and&nbsp;<code class=\"eg acg ach aci acj b\">TransformChain<\/code>&nbsp;are considered the core foundational building blocks that many other more complex chains build on top of. They provide basic patterns like chaining LLMs, conditional logic, sequential workflows, and data transformations.<\/p>\n<p id=\"c47d\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">\u2022&nbsp;<code class=\"eg acg ach aci acj b\">LLMChain<\/code>: Chains together multiple calls to language models. Useful for breaking down complex prompts.<\/p>\n<p id=\"efe1\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">\u2022&nbsp;<code class=\"eg acg ach aci acj b\">RouterChain<\/code>: Allows conditionally routing between different chains based on logic. Enables branching logic.<\/p>\n<p id=\"b03a\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">\u2022&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>: Chains together multiple chains in sequence. Useful for linear workflows.<\/p>\n<p id=\"fac3\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">\u2022&nbsp;<code class=\"eg acg ach aci acj b\">TransformChain<\/code>: Applies a data transformation between chains. Helpful for data munging and preprocessing.<\/p>\n<p id=\"e329\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">Other key chain types like&nbsp;<code class=\"eg acg ach aci acj b\">Agents<\/code>&nbsp;and&nbsp;<code class=\"eg acg ach aci acj b\">RetrievalChain<\/code>&nbsp;build on top of these foundations to enable more advanced use cases like goal-oriented conversations and knowledge-grounded generation.<\/p>\n<p id=\"5ef3\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">However the foundational four provide the basic patterns for chain construction in LangChain.<\/p>\n<h3 id=\"4112\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">\ud83e\udd9c LLMChain<\/h3>\n<p id=\"ee6b\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">The most commonly used type of chain is an LLMChain.<\/p>\n<p id=\"2c29\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">The LLMChain consists of a PromptTemplate, a language model, and an optional output parser. For example, you can create a chain that takes user input, formats it with a PromptTemplate, and then passes the formatted response to an LLM. You can build more complex chains by combining multiple chains, or by combining chains with other components.<\/p>\n<p id=\"1f27\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">The main differences between using an LLMChain versus directly passing a prompt to an LLM are:<\/p>\n<ul class=\"\">\n<li id=\"3ce3\" class=\"yk yl tg be b tu ym yn yo tx yp yq yr mp abb yt yu mu abc yw yx mz abd yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">LLMChain allows chaining multiple prompts together, while directly passing a prompt only allows one. With LLMChain, you can break down a complex prompt into multiple more straightforward prompts and chain them together.<\/li>\n<li id=\"a740\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">LLMChain maintains state and memory between prompts. The output of one prompt can be fed as input to the following prompt to provide context. Directly passing prompts lack this memory.<\/li>\n<li id=\"6bbe\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">LLMChain makes adding preprocessing logic, validation, and instrumentation between prompts easier. This helps with debugging and quality control.<\/li>\n<li id=\"ec8f\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">LLMChain provides some convenience methods like&nbsp;<code class=\"eg acg ach aci acj b\">apply<\/code>&nbsp;and&nbsp;<code class=\"eg acg ach aci acj b\">generate<\/code>&nbsp;that make it easy to run the chain over multiple inputs.<\/li>\n<\/ul>\n<h3 id=\"718b\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">Creating an LLMChain<\/h3>\n<p id=\"d8dd\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">To create an LLMChain, you need to specify:<\/p>\n<ul class=\"\">\n<li id=\"77be\" class=\"yk yl tg be b tu ym yn yo tx yp yq yr mp abb yt yu mu abc yw yx mz abd yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">The language model to use<\/li>\n<li id=\"bbe5\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">The prompt template<\/li>\n<\/ul>\n<h3 id=\"7126\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">Code Example:<\/h3>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"5a8a\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> langchain <span class=\"hljs-keyword\">import<\/span> PromptTemplate, OpenAI, LLMChain\n\n<span class=\"hljs-comment\"># the language model<\/span>\nllm = OpenAI(temperature=<span class=\"hljs-number\">0<\/span>)\n\n<span class=\"hljs-comment\"># the prompt template<\/span>\nprompt_template = <span class=\"hljs-string\">\"Act like a comedian and write a super funny two-sentence short story about {thing}?\"<\/span>\n\nllm_chain = LLMChain(\n    llm=llm,\n    prompt=PromptTemplate.from_template(prompt_template)\n)\n\nllm_chain(<span class=\"hljs-string\">\"A toddler hiding his dad's laptop\"<\/span>)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"123d\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">{'thing': \"A toddler hiding his dad's laptop\",\n 'text': '\\n\\nThe toddler thought he was being sneaky, but little did he know his dad was watching the whole time from the other room, laughing.'}<\/span><\/pre>\n<p id=\"c15c\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">Use&nbsp;<code class=\"eg acg ach aci acj b\">apply<\/code>&nbsp;when you have a list of inputs and want to get the LLM to generate text for each one, it will run the LLMChain for every input dictionary in the list and return a list of outputs.<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"89c0\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">input_list = [\n    {<span class=\"hljs-string\">\"thing\"<\/span>: <span class=\"hljs-string\">\"a Punjabi rapper who eats too many samosas\"<\/span>},\n    {<span class=\"hljs-string\">\"thing\"<\/span>: <span class=\"hljs-string\">\"a blind eye doctor\"<\/span>},\n    {<span class=\"hljs-string\">\"thing\"<\/span>: <span class=\"hljs-string\">\"a data scientist who can't do math\"<\/span>}\n]\n\nllm_chain.apply(input_list)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"74f2\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">[{'text': \"\\n\\nThe Punjabi rapper was so famous that he was known as the 'Samosa King', but his fame was short-lived when he ate so many samosas that he had to be hospitalized for a stomachache!\"},\n {'text': \"\\n\\nA blind eye doctor was so successful that he was able to cure his own vision - but he still couldn't find his glasses.\"},\n {'text': '\\n\\nA data scientist was so bad at math that he had to hire a calculator to do his calculations for him. Unfortunately, the calculator was even worse at math than he was!'}]<\/span><\/pre>\n<p id=\"a82e\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\"><code class=\"eg acg ach aci acj b\">generate<\/code>&nbsp;is similar to apply, except it returns an LLMResult instead of a string. Use this when you want the entire LLMResult object returned, not just the generated text. This gives you access to metadata like the number of tokens used.<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"108b\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">llm_chain.generate(input_list)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"8af8\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">LLMResult(generations=[[Generation(text=\"\\n\\nThe Punjabi rapper was so famous that he was known as the 'Samosa King', but his fame was short-lived when he ate so many samosas that he had to be hospitalized for a stomachache!\", generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text=\"\\n\\nA blind eye doctor was so successful that he was able to cure his own vision - but he still couldn't find his glasses.\", generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text='\\n\\nA data scientist was so bad at math that he had to hire a calculator to do his calculations for him. Unfortunately, the calculator was even worse at math than he was!', generation_info={'finish_reason': 'stop', 'logprobs': None})]], llm_output={'token_usage': {'prompt_tokens': 75, 'total_tokens': 187, 'completion_tokens': 112}, 'model_name': 'text-davinci-003'}, run=[RunInfo(run_id=UUID('b638d2c6-77d9-4346-8494-866892e36bc5')), RunInfo(run_id=UUID('427f9e51-4848-49d3-83c1-e96131f2b34f')), RunInfo(run_id=UUID('4201eea9-1616-42e7-8cb2-a5b26128decd'))])<\/span><\/pre>\n<p id=\"acd3\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">Use&nbsp;<code class=\"eg acg ach aci acj b\">predict<\/code>&nbsp;when you want to pass inputs as keyword arguments instead of a dictionary. This can be convenient if you don&#8217;t want to construct an input dictionary.<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"a551\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\"><span class=\"hljs-comment\"># Single input example<\/span>\nllm_chain.predict(thing=<span class=\"hljs-string\">\"colorful socks\"<\/span>)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"65de\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">The socks were so colorful that when the washing machine finished its cycle, the socks had formed a rainbow in the laundry basket!<\/span><\/pre>\n<p id=\"a5c7\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">Use&nbsp;<code class=\"eg acg ach aci acj b\">LLMChain.run<\/code>&nbsp;when you want to pass the input as a dictionary and get the raw text output from the LLM.<\/p>\n<p id=\"6ee5\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\"><code class=\"eg acg ach aci acj b\">LLMChain.run<\/code>&nbsp;is convenient when your LLMChain has a single input key and a single output key.<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"56d6\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">llm_chain.run(<span class=\"hljs-string\">\"the red hot chili peppers\"<\/span>)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"a0cb\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">['1. Wear a Hawaiian shirt\\n2. Sing along to the wrong lyrics\\n3. Bring a beach ball to the concert\\n4. Try to start a mosh pit\\n5. Bring a kazoo and try to join in on the music']<\/span><\/pre>\n<h3 id=\"73a7\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">Parsing output<\/h3>\n<p id=\"743c\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">To parse the output, you simply pass an output parser directly to&nbsp;<code class=\"eg acg ach aci acj b\">LLMChain<\/code>.<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"ccda\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> langchain.output_parsers <span class=\"hljs-keyword\">import<\/span> CommaSeparatedListOutputParser\n\nllm = OpenAI(temperature=<span class=\"hljs-number\">0<\/span>)\n\n<span class=\"hljs-comment\"># the prompt template<\/span>\nprompt_template = <span class=\"hljs-string\">\"Act like a Captain Obvious and list 5 funny things to not do at {place}?\"<\/span>\n\noutput_parser=CommaSeparatedListOutputParser()\n\nllm_chain = LLMChain(\n    llm=llm,\n    prompt=PromptTemplate.from_template(prompt_template),\n    output_parser= output_parser\n)\n\nllm_chain.predict(place=<span class=\"hljs-string\">'Disneyland'<\/span>)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"e209\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">['1. Wear a costume of a Disney villain.\\n2. Bring your own food and drinks into the park.\\n3. Try to ride the roller coasters without a ticket.\\n4. Try to sneak into the VIP area.\\n5. Try to take a selfie with a Disney character without asking permission.']<\/span><\/pre>\n<h2 id=\"9286\" class=\"zc zd tg be ze zf zg tw mj zh zi tz mo zj zk zl zm zn zo zp zq zr zs zt zu zv bj\">\ud83d\ude8fRouter Chains<\/h2>\n<p id=\"66ef\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">Router chains allow routing inputs to different destination chains based on the input text. This allows the building of chatbots and assistants that can handle diverse requests.<\/p>\n<ul class=\"\">\n<li id=\"2717\" class=\"yk yl tg be b tu ym yn yo tx yp yq yr mp abb yt yu mu abc yw yx mz abd yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Router chains examine the input text and route it to the appropriate destination chain<\/li>\n<li id=\"941d\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Destination chains handle the actual execution based on the input<\/li>\n<li id=\"065d\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Router chains are powerful for building multi-purpose chatbots\/assistants<\/li>\n<\/ul>\n<p id=\"9d88\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">The following example will show routing chains used in a&nbsp;<code class=\"eg acg ach aci acj b\">MultiPromptChain<\/code>&nbsp;to create a question-answering chain that selects the prompt which is most relevant for a given question and then answers the question using that prompt.<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"1474\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> langchain.chains.router <span class=\"hljs-keyword\">import<\/span> MultiPromptChain\n<span class=\"hljs-keyword\">from<\/span> langchain.llms <span class=\"hljs-keyword\">import<\/span> OpenAI\n<span class=\"hljs-keyword\">from<\/span> langchain.chains <span class=\"hljs-keyword\">import<\/span> ConversationChain\n<span class=\"hljs-keyword\">from<\/span> langchain.chains.llm <span class=\"hljs-keyword\">import<\/span> LLMChain\n<span class=\"hljs-keyword\">from<\/span> langchain.prompts <span class=\"hljs-keyword\">import<\/span> PromptTemplate\n\nphysics_template = <span class=\"hljs-string\">\"\"\"You are a very smart physics professor. \\\nYou are great at answering questions about physics in a concise and easy to understand manner. \\\nWhen you don't know the answer to a question you admit that you don't know.\n\nHere is a question:\n{input}\"\"\"<\/span>\n\n\nmath_template = <span class=\"hljs-string\">\"\"\"You are a very good mathematician. You are great at answering math questions. \\\nYou are so good because you are able to break down hard problems into their component parts, \\\nanswer the component parts, and then put them together to answer the broader question.\n\nHere is a question:\n{input}\"\"\"<\/span>\n\nprompt_infos = [\n    {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"physics\"<\/span>,\n        <span class=\"hljs-string\">\"description\"<\/span>: <span class=\"hljs-string\">\"Good for answering questions about physics\"<\/span>,\n        <span class=\"hljs-string\">\"prompt_template\"<\/span>: physics_template,\n    },\n    {\n        <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"math\"<\/span>,\n        <span class=\"hljs-string\">\"description\"<\/span>: <span class=\"hljs-string\">\"Good for answering math questions\"<\/span>,\n        <span class=\"hljs-string\">\"prompt_template\"<\/span>: math_template,\n    },\n]\n\ndestination_chains = {}\n\n<span class=\"hljs-keyword\">for<\/span> p_info <span class=\"hljs-keyword\">in<\/span> prompt_infos:\n    name = p_info[<span class=\"hljs-string\">\"name\"<\/span>]\n    prompt_template = p_info[<span class=\"hljs-string\">\"prompt_template\"<\/span>]\n    prompt = PromptTemplate(template=prompt_template, input_variables=[<span class=\"hljs-string\">\"input\"<\/span>])\n    chain = LLMChain(llm=llm, prompt=prompt)\n    destination_chains[name] = chain\n\ndefault_chain = ConversationChain(llm=llm, output_key=<span class=\"hljs-string\">\"text\"<\/span>)\n\ndefault_chain.run(<span class=\"hljs-string\">\"What is math?\"<\/span>)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"3c99\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\"> Math is the study of numbers, shapes, and patterns. It is used to solve problems and understand the world around us. It is a fundamental part of our lives and is used in many different fields, from engineering to finance.<\/span><\/pre>\n<h2 id=\"c86a\" class=\"zc zd tg be ze zf zg tw mj zh zi tz mo zj zk zl zm zn zo zp zq zr zs zt zu zv bj\">\ud83e\uddec Sequential Chains<\/h2>\n<p id=\"1abc\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">Sometimes, you might want to make a series of calls to a language model, take the output from one call and use it as the input to another. Sequential chains allow you to connect multiple chains and compose them into pipelines executing a specific scenario.<\/p>\n<p id=\"5183\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">There are two types of sequential chains:<\/p>\n<p id=\"0dc1\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">1)&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>: The simplest form of sequential chains, where each step has a singular input\/output, and the output of one step is the input to the next.<\/p>\n<p id=\"b51e\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">2)&nbsp;<code class=\"eg acg ach aci acj b\">SequentialChain<\/code>: A more general form of sequential chains allows multiple inputs\/outputs.<\/p>\n<h3 id=\"650f\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">SimpleSequentialChain<\/h3>\n<p id=\"91f4\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">The simplest form of a sequential chain is where each step has a single input and output.<\/p>\n<p id=\"659c\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">The output of one step is passed as input to the next step in the chain. You would use&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>&nbsp;it when you have a linear pipeline where each step has a single input and output.&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>&nbsp;implicitly passes the output of one step as input to the next.<\/p>\n<p id=\"a870\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">This is great for composing a precise sequence of LLMChains where each builds directly on the previous output.<\/p>\n<h3 id=\"ec12\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">When to use:<\/h3>\n<ul class=\"\">\n<li id=\"29d5\" class=\"yk yl tg be b tu zw yn yo tx zx yq yr mp ada yt yu mu adb yw yx mz adc yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">You have a clear pipeline of steps, each with a single input and output<\/li>\n<li id=\"fabd\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Each step builds directly off the previous step\u2019s output<\/li>\n<li id=\"cc51\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Useful for simple linear pipelines with one input and output per step.<\/li>\n<li id=\"f0bc\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Create each step as an&nbsp;<code class=\"eg acg ach aci acj b\">LLMChain<\/code>.<\/li>\n<li id=\"0933\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Pass list of&nbsp;<code class=\"eg acg ach aci acj b\">LLMChains<\/code>&nbsp;to&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>.<\/li>\n<li id=\"4f68\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Call&nbsp;<code class=\"eg acg ach aci acj b\">run()<\/code>&nbsp;passing the initial input.<\/li>\n<\/ul>\n<h3 id=\"1d34\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">How to use:<\/h3>\n<p id=\"aacc\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">1) Define each step as an&nbsp;<code class=\"eg acg ach aci acj b\">LLMChain<\/code>&nbsp;with a single input and output<\/p>\n<p id=\"2310\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">2) Create a&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>&nbsp;passing a list of the LLMChain steps<\/p>\n<p id=\"5519\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">3) Call&nbsp;<code class=\"eg acg ach aci acj b\">run()<\/code>&nbsp;on the SimpleSequentialChain with the initial input<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"333d\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> langchain.llms <span class=\"hljs-keyword\">import<\/span> OpenAI\n<span class=\"hljs-keyword\">from<\/span> langchain.chains <span class=\"hljs-keyword\">import<\/span> LLMChain\n<span class=\"hljs-keyword\">from<\/span> langchain.prompts <span class=\"hljs-keyword\">import<\/span> PromptTemplate\n\n<span class=\"hljs-comment\"># This is an LLMChain to write a rap.<\/span>\nllm = OpenAI(temperature=<span class=\"hljs-number\">.7<\/span>)\n\ntemplate = <span class=\"hljs-string\">\"\"\"\n\nYou are a Punjabi Jatt rapper, like AP Dhillon or Sidhu Moosewala.\n\nGiven a topic, it is your job to spit bars on of pure heat.\n\nTopic: {topic}\n\"\"\"<\/span>\nprompt_template = PromptTemplate(input_variables=[<span class=\"hljs-string\">\"topic\"<\/span>], template=template)\n\nrap_chain = LLMChain(llm=llm, prompt=prompt_template)\n\n<span class=\"hljs-comment\"># This is an LLMChain to write a diss track<\/span>\n\nllm = OpenAI(temperature=<span class=\"hljs-number\">.7<\/span>)\n\ntemplate = <span class=\"hljs-string\">\"\"\"\n\nYou are an extremely competitive Punjabi Rapper.\n\nGiven the rap from another rapper, it's your job to write a diss track which\ntears apart the rap and shames the original rapper.\n\nRap:\n{rap}\n\"\"\"<\/span>\n\nprompt_template = PromptTemplate(input_variables=[<span class=\"hljs-string\">\"rap\"<\/span>], template=template)\n\ndiss_chain = LLMChain(llm=llm, prompt=prompt_template)\n\n<span class=\"hljs-comment\"># This is the overall chain where we run these two chains in sequence.<\/span>\n<span class=\"hljs-keyword\">from<\/span> langchain.chains <span class=\"hljs-keyword\">import<\/span> SimpleSequentialChain\n\noverall_chain = SimpleSequentialChain(chains=[rap_chain, diss_chain], verbose=<span class=\"hljs-literal\">True<\/span>)\n\nreview = overall_chain.run(<span class=\"hljs-string\">\"Drinking Crown Royal and mobbin in my red Challenger\"<\/span>)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"0bec\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">&gt; Entering new SimpleSequentialChain chain...\n\nI'm sippin' Crown Royal, straight up, no chaser\nCuz I'm a Jatt, and I'm the king of the paper\nMobbin' in my red Challenger, windows down, music loud\nI'm a G, and I'm always turnin' up the crowd\nMy style is undeniable, you can't ignore the flow\nI'm comin' through, and rollin' up, wherever I go\nMy red Challenger's the talk of the town\nAnd you know I'm poppin' up, with the Crown Royal around\n\n\nThis rapper's flow is quite mediocre,\nHis bars are plain and offer no flavor.\nHis Challenger doesn't seem too profound\nAnd his Crown Royal's just another way to clown.\nHis style is not undeniable, it's easily forgettable\nHe's just tryin' to fit in, but he ain't makin' a dent.\nHe's just another copycat, trying to be the next king\nBut he's gonna find out soon, he can't do a thing.\n\n&gt; Finished chain.<\/span><\/pre>\n<h3 id=\"4fa6\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">SequentialChain<\/h3>\n<p id=\"25c6\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">A more general form of sequential chain allows multiple inputs and outputs per step.<\/p>\n<p id=\"67dd\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">You would use&nbsp;<code class=\"eg acg ach aci acj b\">SequentialChain<\/code>&nbsp;when you have a more complex pipeline where steps might have multiple inputs and outputs.<\/p>\n<p id=\"41ec\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\"><code class=\"eg acg ach aci acj b\">SequentialChain<\/code>&nbsp;allows you to explicitly specify all the input and output variables at each step and map outputs from one step to inputs of the next. This provides more flexibility when steps might have multiple dependencies or produce multiple results to pass along.<\/p>\n<h3 id=\"c27f\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">When to use:<\/h3>\n<ul class=\"\">\n<li id=\"30f6\" class=\"yk yl tg be b tu zw yn yo tx zx yq yr mp ada yt yu mu adb yw yx mz adc yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">You have a sequence of steps but with more complex input\/output requirements<\/li>\n<li id=\"4933\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">You need to track multiple variables across steps in the chain<\/li>\n<\/ul>\n<h3 id=\"094d\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">How to use<\/h3>\n<ul class=\"\">\n<li id=\"3541\" class=\"yk yl tg be b tu zw yn yo tx zx yq yr mp ada yt yu mu adb yw yx mz adc yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Define each step as an LLMChain, specifying multiple input\/output variables<\/li>\n<li id=\"0f34\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Create a SequentialChain specifying all input\/output variables<\/li>\n<li id=\"7c21\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Map outputs from one step to inputs of the next<\/li>\n<li id=\"9371\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">Call run() passing a dict of all input variables<\/li>\n<li id=\"4f80\" class=\"yk yl tg be b tu abh yn yo tx abi yq yr mp abj yt yu mu abk yw yx mz abl yz za zb abe abf abg bj\" data-selectable-paragraph=\"\">The key difference is&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>&nbsp;handles implicit variable passing whereas SequentialChain allows explicit variable specification and mapping.<\/li>\n<\/ul>\n<h3 id=\"0de8\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">When you would use SequentialChain vs SimpleSequentialChain<\/h3>\n<p id=\"0123\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">Use&nbsp;<code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>&nbsp;for linear sequences with a single input\/output. Use&nbsp;<code class=\"eg acg ach aci acj b\">SequentialChain<\/code>&nbsp;for more complex sequences with multiple inputs\/outputs.<\/p>\n<h3 id=\"5ee4\" class=\"ack zd tg be ze mf acl mg mj mk acm ml mo mp acn mq mt mu aco mv my mz acp na nd acq bj\">The key difference<\/h3>\n<p id=\"1591\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\"><code class=\"eg acg ach aci acj b\">SimpleSequentialChain<\/code>&nbsp;is for linear pipelines with a single input\/output per step. Implicitly passes variables.<\/p>\n<p id=\"0d47\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\"><code class=\"eg acg ach aci acj b\">SequentialChain<\/code>&nbsp;handles more complex pipelines with multiple inputs\/outputs per step. Allows explicitly mapping variables.<\/p>\n<p id=\"8982\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">This uses a standard ChatOpenAI model and prompt template. You chain them together with the&nbsp;<code class=\"eg acg ach aci acj b\">|<\/code>&nbsp;operator and then call it with&nbsp;<code class=\"eg acg ach aci acj b\">chain.invoke<\/code>. We can also get async, batch, and streaming support out of the box.<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"cf3c\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">\nllm = OpenAI(temperature=<span class=\"hljs-number\">.7<\/span>)\n\ntemplate = <span class=\"hljs-string\">\"\"\"\n\nYou are a Punjabi Jatt rapper, like AP Dhillon or Sidhu Moosewala.\n\nGiven two topics, it is your job to create a rhyme of two verses and one chorus\nfor each topic.\n\nTopic: {topic1} and {topic2}\n\nRap:\n\n\"\"\"<\/span>\n\nprompt_template = PromptTemplate(input_variables=[<span class=\"hljs-string\">\"topic1\"<\/span>, <span class=\"hljs-string\">\"topic2\"<\/span>], template=template)\n\nrap_chain = LLMChain(llm=llm, prompt=prompt_template, output_key=<span class=\"hljs-string\">\"rap\"<\/span>)\n\n\ntemplate = <span class=\"hljs-string\">\"\"\"\n\nYou are a rap critic from the Rolling Stone magazine and Metacritic.\n\nGiven a, it is your job to write a review for that rap.\n\nYour review style should be scathing, critical, and no holds barred.\n\nRap:\n\n{rap}\n\nReview from the Rolling Stone magazine and Metacritic critic of the above rap:\n\n\"\"\"<\/span>\n\nprompt_template = PromptTemplate(input_variables=[<span class=\"hljs-string\">\"rap\"<\/span>], template=template)\n\nreview_chain = LLMChain(llm=llm, prompt=prompt_template, output_key=<span class=\"hljs-string\">\"review\"<\/span>)\n\n<span class=\"hljs-comment\"># This is the overall chain where we run these two chains in sequence.<\/span>\n<span class=\"hljs-keyword\">from<\/span> langchain.chains <span class=\"hljs-keyword\">import<\/span> SequentialChain\n\noverall_chain = SequentialChain(\n    chains=[rap_chain, review_chain],\n    input_variables=[<span class=\"hljs-string\">\"topic1\"<\/span>, <span class=\"hljs-string\">\"topic2\"<\/span>],\n    <span class=\"hljs-comment\"># Here we return multiple variables<\/span>\n    output_variables=[<span class=\"hljs-string\">\"rap\"<\/span>, <span class=\"hljs-string\">\"review\"<\/span>],\n    verbose=<span class=\"hljs-literal\">True<\/span>)\n\noverall_chain({<span class=\"hljs-string\">\"topic1\"<\/span>:<span class=\"hljs-string\">\"Tractors and sugar canes\"<\/span>, <span class=\"hljs-string\">\"topic2\"<\/span>: <span class=\"hljs-string\">\"Dasuya, Punjab\"<\/span>})<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"59b6\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">&gt; Entering new SequentialChain chain...\n\n&gt; Finished chain.\n{'topic1': 'Tractors and sugar canes',\n 'topic2': 'Dasuya, Punjab',\n 'rap': \"Verse 1\\nI come from a place with lots of fame\\nDasuya, Punjab, where the tractors reign\\nI'm a Jatt rapper with a game to play\\nSo I'm gonna take it up and make it my way\\n\\nChorus\\nTractors and sugar canes, that's what I'm talking about\\nTractors and sugar canes, it's all about\\nDasuya, Punjab, a place so grand\\nTractors and sugar canes, that's our jam\\n\\nVerse 2\\nFrom Punjab's beauty I derive my pride\\nMy heart belongs to the place, where the sugar canes reside\\nWhere the soil is my home, I'm never apart\\nFrom the tractors and sugar canes of Dasuya, Punjab\\n\\nChorus\\nTractors and sugar canes, that's what I'm talking about\\nTractors and sugar canes, it's all about\\nDasuya, Punjab, a place so grand\\nTractors and sugar canes, that's our jam\",\n 'review': \"\\nThis rap artist hails from the small town of Dasuya, Punjab, and takes pride in his hometown's culture and agricultural way of life. While the lyrical content of this rap is filled with references to tractors and sugar canes, unfortunately the artist's delivery falls flat and fails to capture the unique essence of his home. The basic rhyme scheme, repetitive chorus, and lack of originality make this a forgettable track. The artist's enthusiasm for his hometown is admirable, but unfortunately it is not enough to make this rap stand out from the crowd.\"}<\/span><\/pre>\n<h2 id=\"86e9\" class=\"zc zd tg be ze zf zg tw mj zh zi tz mo zj zk zl zm zn zo zp zq zr zs zt zu zv bj\">Transformation<\/h2>\n<p id=\"802c\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">Transformation Chains allows you to define custom data transformation logic as a step in your LangChain pipeline. This is useful when you must preprocess or transform data before passing it to the next step.<\/p>\n<pre class=\"xu xv xw xx xy acr acj acs bo act ba bj\"><span id=\"32f6\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> langchain.chains <span class=\"hljs-keyword\">import<\/span> TransformChain, LLMChain, SimpleSequentialChain\n<span class=\"hljs-keyword\">from<\/span> langchain.llms <span class=\"hljs-keyword\">import<\/span> OpenAI\n<span class=\"hljs-keyword\">from<\/span> langchain.prompts <span class=\"hljs-keyword\">import<\/span> PromptTemplate\n\n!wget https:\/\/www.gutenberg.org\/files\/<span class=\"hljs-number\">2680<\/span>\/<span class=\"hljs-number\">2680<\/span>-<span class=\"hljs-number\">0.<\/span>txt\n\n<span class=\"hljs-keyword\">with<\/span> <span class=\"hljs-built_in\">open<\/span>(<span class=\"hljs-string\">\"\/content\/2680-0.txt\"<\/span>) <span class=\"hljs-keyword\">as<\/span> f:\n    meditations = f.read()\n\n<span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title.function\">transform_func<\/span>(<span class=\"hljs-params\">inputs: <span class=\"hljs-built_in\">dict<\/span><\/span>) -&gt; <span class=\"hljs-built_in\">dict<\/span>:\n    <span class=\"hljs-string\">\"\"\"\n    Extracts specific sections from a given text based on newline separators.\n\n    The function assumes the input text is divided into sections or paragraphs separated\n    by one newline characters (`\\n`). It extracts the sections from index 922 to 950\n    (inclusive) and returns them in a dictionary.\n\n    Parameters:\n    - inputs (dict): A dictionary containing the key \"text\" with the input text as its value.\n\n    Returns:\n    - dict: A dictionary containing the key \"output_text\" with the extracted sections as its value.\n    \"\"\"<\/span>\n    text = inputs[<span class=\"hljs-string\">\"text\"<\/span>]\n    shortened_text = <span class=\"hljs-string\">\"\\n\"<\/span>.join(text.split(<span class=\"hljs-string\">\"\\n\"<\/span>)[<span class=\"hljs-number\">921<\/span>:<span class=\"hljs-number\">950<\/span>])\n    <span class=\"hljs-keyword\">return<\/span> {<span class=\"hljs-string\">\"output_text\"<\/span>: shortened_text}\n\ntransform_chain = TransformChain(\n    input_variables=[<span class=\"hljs-string\">\"text\"<\/span>], output_variables=[<span class=\"hljs-string\">\"output_text\"<\/span>], transform=transform_func, verbose=<span class=\"hljs-literal\">True<\/span>\n)\n\ntransform_chain.run(meditations)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"e206\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">\nII. Let it be thy earnest and incessant care as a Roman and a man to\nperform whatsoever it is that thou art about, with true and unfeigned\ngravity, natural affection, freedom and justice: and as for all other\ncares, and imaginations, how thou mayest ease thy mind of them. Which\nthou shalt do; if thou shalt go about every action as thy last action,\nfree from all vanity, all passionate and wilful aberration from reason,\nand from all hypocrisy, and self-love, and dislike of those things,\nwhich by the fates or appointment of God have happened unto thee. Thou\nseest that those things, which for a man to hold on in a prosperous\ncourse, and to live a divine life, are requisite and necessary, are not\nmany, for the gods will require no more of any man, that shall but keep\nand observe these things.\n\nIII. Do, soul, do; abuse and contemn thyself; yet a while and the time\nfor thee to respect thyself, will be at an end. Every man's happiness\ndepends from himself, but behold thy life is almost at an end, whiles\naffording thyself no respect, thou dost make thy happiness to consist in\nthe souls, and conceits of other men.\n\nIV. Why should any of these things that happen externally, so much\ndistract thee? Give thyself leisure to learn some good thing, and cease\nroving and wandering to and fro. Thou must also take heed of another\nkind of wandering, for they are idle in their actions, who toil and\nlabour in this life, and have no certain scope to which to direct all\ntheir motions, and desires. V. For not observing the state of another\nman's soul, scarce was ever any man known to be unhappy. Tell whosoever\nthey be that intend not, and guide not by reason and discretion the\nmotions of their own souls, they must of necessity be unhappy.<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"9107\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">template = <span class=\"hljs-string\">\"\"\"\n\nRephrase this text:\n\n{output_text}\n\nIn the style of a 90s gangster rapper speaking to his homies.\n\nRephrased:\"\"\"<\/span>\n\nprompt = PromptTemplate(input_variables=[<span class=\"hljs-string\">\"output_text\"<\/span>], template=template)\n\nllm_chain = LLMChain(llm=OpenAI(), prompt=prompt)\n\nsequential_chain = SimpleSequentialChain(chains=[transform_chain, llm_chain], verbose=<span class=\"hljs-literal\">True<\/span>)\n\nsequential_chain.run(meditations)<\/span><\/pre>\n<pre class=\"acz acr acj acs bo act ba bj\"><span id=\"cae8\" class=\"acu zd tg acj b bf acv acw l acx acy\" data-selectable-paragraph=\"\">&gt; Entering new SimpleSequentialChain chain...\n\n\n&gt; Entering new TransformChain chain...\n\n&gt; Finished chain.\n\nII. Let it be thy earnest and incessant care as a Roman and a man to\nperform whatsoever it is that thou art about, with true and unfeigned\ngravity, natural affection, freedom and justice: and as for all other\ncares, and imaginations, how thou mayest ease thy mind of them. Which\nthou shalt do; if thou shalt go about every action as thy last action,\nfree from all vanity, all passionate and wilful aberration from reason,\nand from all hypocrisy, and self-love, and dislike of those things,\nwhich by the fates or appointment of God have happened unto thee. Thou\nseest that those things, which for a man to hold on in a prosperous\ncourse, and to live a divine life, are requisite and necessary, are not\nmany, for the gods will require no more of any man, that shall but keep\nand observe these things.\n\nIII. Do, soul, do; abuse and contemn thyself; yet a while and the time\nfor thee to respect thyself, will be at an end. Every man's happiness\ndepends from himself, but behold thy life is almost at an end, whiles\naffording thyself no respect, thou dost make thy happiness to consist in\nthe souls, and conceits of other men.\n\nIV. Why should any of these things that happen externally, so much\ndistract thee? Give thyself leisure to learn some good thing, and cease\nroving and wandering to and fro. Thou must also take heed of another\nkind of wandering, for they are idle in their actions, who toil and\nlabour in this life, and have no certain scope to which to direct all\ntheir motions, and desires. V. For not observing the state of another\nman's soul, scarce was ever any man known to be unhappy. Tell whosoever\nthey be that intend not, and guide not by reason and discretion the\nmotions of their own souls, they must of necessity be unhappy.\n\n\nYo, listen up my homies, it's time to get serious. We gotta take care of our business and act with true gravity, natural affection, freedom, and justice. So forget all those other cares and worries, and just do every action like it's your last, stayin' away from vanity and all that phony stuff. We don't need much for true happiness. All the gods ask is that we keep it real and show some respect for ourselves. Don't let nothin' from the outside distract you. Take time to learn something good and make sure you got a goal to get to. Don't worry 'bout anybody else, 'cause if you don't look after your own soul, you gonna end up real unhappy.\n\n&gt; Finished chain.\n\\n\\nYo, listen up my homies, it's time to get serious. We gotta take care of our business and act with true gravity, natural affection, freedom, and justice. So forget all those other cares and worries, and just do every action like it's your last, stayin' away from vanity and all that phony stuff. We don't need much for true happiness. All the gods ask is that we keep it real and show some respect for ourselves. Don't let nothin' from the outside distract you. Take time to learn something good and make sure you got a goal to get to. Don't worry 'bout anybody else, 'cause if you don't look after your own soul, you gonna end up real unhappy.<\/span><\/pre>\n<h2 id=\"7f8d\" class=\"zc zd tg be ze zf zg tw mj zh zi tz mo zj zk zl zm zn zo zp zq zr zs zt zu zv bj\">Conclusion<\/h2>\n<p id=\"85f6\" class=\"pw-post-body-paragraph yk yl tg be b tu zw yn yo tx zx yq yr mp zy yt yu mu zz yw yx mz aba yz za zb ew bj\" data-selectable-paragraph=\"\">LangChain, with its innovative approach to language processing, has truly redefined the boundaries of what\u2019s possible with language models.<\/p>\n<p id=\"c476\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">The concept of \u201cchains\u201d offers a structured and efficient way to execute complex tasks, ensuring that each step is seamlessly integrated with the next. As we\u2019ve explored in this guide, the versatility of chains, from the foundational types to the more advanced ones, allows for a myriad of applications catering to diverse needs. Whether simplifying intricate prompts, maintaining context, or adding custom logic, LangChain provides the tools to elevate our interactions with language models.<\/p>\n<p id=\"6009\" class=\"pw-post-body-paragraph yk yl tg be b tu ym yn yo tx yp yq yr mp ys yt yu mu yv yw yx mz yy yz za zb ew bj\" data-selectable-paragraph=\"\">As the landscape of language processing continues to evolve, LangChain stands as a testament to the power of innovation, paving the way for a future where our communication with machines is more intuitive, dynamic, and impactful.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Exploring LLMChain, RouterChain, SimpleSequentialChain, and TransformChain for Advanced Language Model Interactions LangChain introduces a revolutionary way to harness the power of language models. At the heart of this system lies the concept of \u201cchains\u201d \u2014 a sequence of interconnected components designed to execute tasks in a specific order. But what exactly are these chains, and [&hellip;]<\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","footnotes":""},"categories":[65,6,7],"tags":[70,71,52,31,53,34],"coauthors":[166],"class_list":["post-8123","post","type-post","status-publish","format-standard","hentry","category-llmops","category-machine-learning","category-tutorials","tag-langchain","tag-language-models","tag-llm","tag-llmops","tag-mlops","tag-prompt-engineering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Chaining the Future: An In-depth Dive into LangChain - Comet<\/title>\n<meta name=\"description\" content=\"LLM chains are a sequence of interconnected components designed to execute tasks in a specific in order to maximize the output of LMs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Chaining the Future: An In-depth Dive into LangChain\" \/>\n<meta property=\"og:description\" content=\"LLM chains are a sequence of interconnected components designed to execute tasks in a specific in order to maximize the output of LMs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-08T13:34:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T17:04:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*X7eM0S-smz0UvHRu\" \/>\n<meta name=\"author\" content=\"Harpreet Sahota\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Cometml\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harpreet Sahota\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Chaining the Future: An In-depth Dive into LangChain - Comet","description":"LLM chains are a sequence of interconnected components designed to execute tasks in a specific in order to maximize the output of LMs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/","og_locale":"en_US","og_type":"article","og_title":"Chaining the Future: An In-depth Dive into LangChain","og_description":"LLM chains are a sequence of interconnected components designed to execute tasks in a specific in order to maximize the output of LMs.","og_url":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2023-11-08T13:34:29+00:00","article_modified_time":"2025-04-24T17:04:36+00:00","og_image":[{"url":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*X7eM0S-smz0UvHRu","type":"","width":"","height":""}],"author":"Harpreet Sahota","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Harpreet Sahota","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/"},"author":{"name":"Harpreet Sahota","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/46036ab474aa916e2873daece26a28d6"},"headline":"Chaining the Future: An In-depth Dive into LangChain","datePublished":"2023-11-08T13:34:29+00:00","dateModified":"2025-04-24T17:04:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/"},"wordCount":1674,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*X7eM0S-smz0UvHRu","keywords":["LangChain","Language Models","LLM","LLMOps","MLOps","Prompt Engineering"],"articleSection":["LLMOps","Machine Learning","Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/","url":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/","name":"Chaining the Future: An In-depth Dive into LangChain - Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*X7eM0S-smz0UvHRu","datePublished":"2023-11-08T13:34:29+00:00","dateModified":"2025-04-24T17:04:36+00:00","description":"LLM chains are a sequence of interconnected components designed to execute tasks in a specific in order to maximize the output of LMs.","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/#primaryimage","url":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*X7eM0S-smz0UvHRu","contentUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:1400\/0*X7eM0S-smz0UvHRu"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/chaining-the-future-an-in-depth-dive-into-langchain\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"Chaining the Future: An In-depth Dive into LangChain"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/46036ab474aa916e2873daece26a28d6","name":"Harpreet Sahota","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/2d21512be19ba7e19a71a803309e2a88","url":"https:\/\/secure.gravatar.com\/avatar\/a6ca5a533fc9f143a0a7428037ff652aa0633d66bf27e76ae89b955ae72a0f2d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a6ca5a533fc9f143a0a7428037ff652aa0633d66bf27e76ae89b955ae72a0f2d?s=96&d=mm&r=g","caption":"Harpreet Sahota"},"url":"https:\/\/www.comet.com\/site\/blog\/author\/theartistsofdatasciencegmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=8123"}],"version-history":[{"count":1,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8123\/revisions"}],"predecessor-version":[{"id":15457,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8123\/revisions\/15457"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=8123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=8123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=8123"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=8123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}