Created
March 5, 2023 13:50
-
-
Save cosimo/e3bfd217abf3eedfea151a8b8811f797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import dotenv | |
from langchain import PromptTemplate, HuggingFaceHub, LLMChain | |
# Add your HuggingFace hub token in a `.env` file, as: | |
# | |
# ``` | |
# HUGGINGFACEHUB_API_TOKEN=hf-.... | |
# ``` | |
dotenv.load_dotenv() | |
template = """Question: {question} | |
Answer: Let's think step by step.""" | |
prompt = PromptTemplate(template=template, input_variables=["question"]) | |
model_name = "google/flan-t5-xl" | |
llm=HuggingFaceHub(repo_id=model_name, | |
model_kwargs={"temperature":0, "max_length":128}) | |
llm_chain = LLMChain(prompt=prompt, llm=llm) | |
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?" | |
# Don't even think for a second that the answer will be correct! | |
# F.ex.: Justin Bieber was born in 1994 | |
print(llm_chain.run(question)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment