mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-19 08:18:15 +00:00
4.2 KiB
4.2 KiB
In [5]:
chat = ChatOpenAI(temperature=0)
prompt_template = "Tell me a {adjective} joke"
llm_chain = LLMChain(llm=chat, prompt=PromptTemplate.from_template(prompt_template))
llm_chain(inputs={"adjective": "corny"})Out [5]:
{'adjective': 'corny',
'text': 'Why did the tomato turn red? Because it saw the salad dressing!'}In [6]:
llm_chain("corny", return_only_outputs=True)Out [6]:
{'text': 'Why did the tomato turn red? Because it saw the salad dressing!'}In [7]:
# llm_chain only has one output key, so we can use run
llm_chain.output_keysOut [7]:
['text']
In [8]:
llm_chain.run({"adjective": "corny"})Out [8]:
'Why did the tomato turn red? Because it saw the salad dressing!'
In [9]:
# These two are equivalent
llm_chain.run({"adjective": "corny"})
llm_chain.run("corny")
# These two are also equivalent
llm_chain("corny")
llm_chain({"adjective": "corny"})Out [9]:
{'adjective': 'corny',
'text': 'Why did the tomato turn red? Because it saw the salad dressing!'}In [ ]: