Skip to content

Instantly share code, notes, and snippets.

@cosimo
Created March 5, 2023 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosimo/e3bfd217abf3eedfea151a8b8811f797 to your computer and use it in GitHub Desktop.
Save cosimo/e3bfd217abf3eedfea151a8b8811f797 to your computer and use it in GitHub Desktop.
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