Files
2023-03-26 19:49:46 -07:00

2.2 KiB

OpenAI

This example goes over how to use LangChain to interact with OpenAI models

In [1]:
from langchain.llms import OpenAI
from langchain import PromptTemplate, LLMChain
In [2]:
template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])
In [3]:
llm = OpenAI()
In [4]:
llm_chain = LLMChain(prompt=prompt, llm=llm)
In [5]:
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.run(question)
Out [5]:
' Justin Bieber was born in 1994, so the NFL team that won the Super Bowl in that year was the Dallas Cowboys.'