I am getting this error on langchain

from langchain_community.llms import HuggingFaceHub

hf=HuggingFaceHub(
    repo_id="google/flan-t5-large",
    task="text2text-generation",  # Explicitly specify the task
    model_kwargs={"temperature":0.7,"max_length":100},
    huggingfacehub_api_token="hf_... Ue"

)
text="What is the capital of Turkey"

output=hf.invoke(text)
print(output)

ValueError: Task text2text-generation has no recommended model. Please specify a model explicitly. Visit Tasks - Hugging Face for more info.

Why I am getting this error. I just checked Api token multiple times and still give this error.

1 Like

It seems that the function has been discontinued.
https://python.langchain.com/api_reference/community/llms/langchain_community.llms.huggingface_hub.HuggingFaceHub.html

Still I used HuggingFaceEndpoin but still ı am getting same error, could you give me code example?

1 Like

try this one:

from langchain_huggingface.llms.huggingface_endpoint import HuggingFaceEndpoint
llm = HuggingFaceEndpoint(
    task='text-generation',
    model="deepseek-ai/DeepSeek-R1",
    max_new_tokens=100,
    temperature=0.7,
    huggingfacehub_api_token="your_api"
)
print(llm.invoke("What is the capital of Turkey"))
1 Like

The token has been leaked. Please invalidate the token as soon as possible.

1 Like

i had already invalidated the token …

2 Likes

bro can u give a slution for this too?? it is showing the same error
ValueError: Task text2text-generation has no recommended model. Please specify a model explicitly. Visit Tasks - Hugging Face for more info.

1 Like

If the same solution as above is okay, this should work. The error message says that you can just overwrite the task.

from langchain_huggingface.llms.huggingface_endpoint import HuggingFaceEndpoint
chain = LLMChain(
    llm = HuggingFaceEndpoint(
        task='text-generation', # overwrite task
        model="deepseek-ai/DeepSeek-R1",
        temperature=0,
        huggingfacehub_api_token="hf_*****"
    ),
    prompt=prompt
)
1 Like