mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-11 12:25:12 +03:00
4.5 KiB
4.5 KiB
In [1]:
# get a token: https://platform.openai.com/account/api-keys
from getpass import getpass
OPENAI_API_KEY = getpass()In [2]:
import os
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEYIn [3]:
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChainIn [4]:
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate(template=template, input_variables=["question"])In [5]:
llm = OpenAI()In [6]:
llm_chain = LLMChain(prompt=prompt, llm=llm)In [7]:
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.run(question)Out [7]:
' Justin Bieber was born in 1994, so the NFL team that won the Super Bowl in 1994 was the Dallas Cowboys.'
In [8]:
os.environ["OPENAI_PROXY"] = "http://proxy.yourcompany.com:8080"