Chi*_*ain 6 python huggingface langchain huggingface-hub
from langchain import PromptTemplate, HuggingFaceHub, LLMChain
import os
os.environ['HUGGINGFACEHUB_API_TOKEN'] = 'token'
# initialize HF LLM
flan_t5 = HuggingFaceHub(
repo_id="google/flan-t5-xl",
model_kwargs={"temperature": 1e-10}
)
multi_template = """Answer the following questions one at a time.
Questions:
{questions}
Answers:
"""
long_prompt = PromptTemplate(
template=multi_template,
input_variables=["questions"]
)
llm_chain = LLMChain(
prompt=long_prompt,
llm=flan_t5
)
qs_str = (
"Which NFL team won the Super Bowl in the 2010 season?\n" +
"If I am 6 ft 4 inches, how tall am I in centimeters?\n" +
"Who was the 12th person on the moon?" +
"How many eyes does a blade of grass have?"
)
print(llm_chain.run(qs_str))
Run Code Online (Sandbox Code Playgroud)
我正在学习langchain,在运行上面的代码时,出现无限期停止并且几分钟没有响应,
谁能告诉我这是为什么吗?以及需要纠正的内容。
我预计它会给出 4 个问题的答案,但一直在无限期地等待。
小智 2
作为替代方案,您可以使用具有正温度的google/flan-t5-xxl :
# initialize HF LLM
flan_t5 = HuggingFaceHub(
repo_id="google/flan-t5-xxl",
model_kwargs={"temperature": 0.5}
)
Run Code Online (Sandbox Code Playgroud)