Skip to content

Instantly share code, notes, and snippets.

@hwchase17
Created August 17, 2023 18:08
Show Gist options
  • Save hwchase17/26eca9f20031c349bd72fdc669c05a1f to your computer and use it in GitHub Desktop.
Save hwchase17/26eca9f20031c349bd72fdc669c05a1f to your computer and use it in GitHub Desktop.
from langchain import PromptTemplate, OpenAI, LLMChain
prompt_template = "What is a good name for a company that makes {product}?"
llm1 = OpenAI(model="foo", temperature=0)
llm_chain1 = LLMChain(
llm=llm1,
prompt=PromptTemplate.from_template(prompt_template)
)
llm2 = OpenAI(temperature=0)
llm_chain2 = LLMChain(
llm=llm2,
prompt=PromptTemplate.from_template(prompt_template)
)
llm_chain = llm_chain1.with_fallbacks([llm_chain2])
llm_chain.invoke({"product": "hi"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment