did the chicken cross the road?"))    except:        print("Hit error")    Hit error# Now let's try with fallbacks to Anthropicwith patch('openai.ChatCompletion.create', side_effect=RateLimitError()):    try:         print(llm.invoke("Why did the the chicken cross the road?"))    except:        print("Hit error")    content=' I don\'t actually know why the chicken crossed the road, but here are some possible humorous answers:\n\n- To get to the other side!\n\n- It was too chicken to just stand there. \n\n- It wanted a change of scenery.\n\n- It wanted to show the possum it could be done.\n\n- It was on its way to a poultry farmers\' convention.\n\nThe joke plays on the double meaning of "the other side" - literally crossing the road to the other side, or the "other side" meaning the afterlife. So it\'s an anti-joke, with a silly or unexpected pun as the answer.' additional_kwargs={} example=FalseWe can use our "LLM with Fallbacks" as we would a normal LLM.from langchain.prompts import ChatPromptTemplateprompt = ChatPromptTemplate.from_messages(    [        ("system", "You're a nice assistant who always includes a compliment in your response"),        ("human", "Why did the {animal} cross the road"),    ])chain = prompt | llmwith patch('openai.ChatCompletion.create', side_effect=RateLimitError()):    try:         print(chain.invoke({"animal": "kangaroo"}))    except:        print("Hit error")    content=" I don't actually know why the kangaroo crossed the road, but I'm happy to take a guess! Maybe the kangaroo was trying to get to the other side to find some tasty grass to eat. Or maybe it was trying to get away from a predator or other danger. Kangaroos do need to cross roads and other open areas sometimes as part of their normal activities. Whatever the reason, I'm sure the kangaroo looked both ways before hopping across!" additional_kwargs={} example=FalseSpecifying errors to handle‚ÄãWe can also specify the errors to handle if we want to be more specific about
There are many possible points of failure in an LLM application, whether that be issues with LLM API's, poor model outputs, issues with other integrations, etc. Fallbacks help you gracefully handle and isolate these issues.
There are many possible points of failure in an LLM application, whether that be issues with LLM API's, poor model outputs, issues with other integrations, etc. Fallbacks help you gracefully handle and isolate these issues. ->: did the chicken cross the road?"))    except:        print("Hit error")    Hit error# Now let's try with fallbacks to Anthropicwith patch('openai.ChatCompletion.create', side_effect=RateLimitError()):    try:         print(llm.invoke("Why did the the chicken cross the road?"))    except:        print("Hit error")    content=' I don\'t actually know why the chicken crossed the road, but here are some possible humorous answers:\n\n- To get to the other side!\n\n- It was too chicken to just stand there. \n\n- It wanted a change of scenery.\n\n- It wanted to show the possum it could be done.\n\n- It was on its way to a poultry farmers\' convention.\n\nThe joke plays on the double meaning of "the other side" - literally crossing the road to the other side, or the "other side" meaning the afterlife. So it\'s an anti-joke, with a silly or unexpected pun as the answer.' additional_kwargs={} example=FalseWe can use our "LLM with Fallbacks" as we would a normal LLM.from langchain.prompts import ChatPromptTemplateprompt = ChatPromptTemplate.from_messages(    [        ("system", "You're a nice assistant who always includes a compliment in your response"),        ("human", "Why did the {animal} cross the road"),    ])chain = prompt | llmwith patch('openai.ChatCompletion.create', side_effect=RateLimitError()):    try:         print(chain.invoke({"animal": "kangaroo"}))    except:        print("Hit error")    content=" I don't actually know why the kangaroo crossed the road, but I'm happy to take a guess! Maybe the kangaroo was trying to get to the other side to find some tasty grass to eat. Or maybe it was trying to get away from a predator or other danger. Kangaroos do need to cross roads and other open areas sometimes as part of their normal activities. Whatever the reason, I'm sure the kangaroo looked both ways before hopping across!" additional_kwargs={} example=FalseSpecifying errors to handle‚ÄãWe can also specify the errors to handle if we want to be more specific about