Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: HuggingFaceEndpoint Requires Explicit task Argument, but Documentation Omits It #29685

Closed
2 tasks done
jasminaaa20 opened this issue Feb 8, 2025 · 0 comments · Fixed by #29686
Closed
2 tasks done
Labels
🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder

Comments

@jasminaaa20
Copy link
Contributor

URL

https://python.langchain.com/docs/integrations/document_loaders/docling/

Checklist

  • I added a very descriptive title to this issue.
  • I included a link to the documentation page I am referring to (if applicable).

Issue with current documentation:

Issue Description

The current LangChain documentation does not specify that the HuggingFaceEndpoint class requires an explicit task argument when using Hugging Face models.

Running the provided documentation code results in an error due to the missing task argument, with huggingface_hub == 0.28.1.

Affected Documentation Code

from langchain.chains import create_retrieval_chain
from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain_huggingface import HuggingFaceEndpoint

retriever = vectorstore.as_retriever(search_kwargs={"k": TOP_K})
llm = HuggingFaceEndpoint(
    repo_id=GEN_MODEL_ID,
    huggingfacehub_api_token=HF_TOKEN,  # Missing task argument
)

Error Message (from Colab)

ValueError                                Traceback (most recent call last)
[<ipython-input-14-d478845450c0>](https://localhost:8080/#) in <cell line: 0>()
      1 question_answer_chain = create_stuff_documents_chain(llm, PROMPT)
      2 rag_chain = create_retrieval_chain(retriever, question_answer_chain)
----> 3 resp_dict = rag_chain.invoke({"input": QUESTION})
      4 
      5 clipped_answer = clip_text(resp_dict["answer"], threshold=350)
...
[/usr/local/lib/python3.11/dist-packages/huggingface_hub/inference/_providers/hf_inference.py](https://localhost:8080/#) in get_recommended_model(task)
     50     model = _fetch_recommended_models().get(task)
     51     if model is None:
---> 52         raise ValueError(
     53             f"Task {task} has no recommended model. Please specify a model"
     54             " explicitly. Visit https://huggingface.co/tasks for more info."

ValueError: Task unknown has no recommended model. Please specify a model explicitly. Visit https://huggingface.co/tasks for more info.

Environment Details

  • LangChain Version: latest
  • Hugging Face Hub Version: 0.28.1
  • Python Version: 3.11
  • Runtime: Google Colab

Reproduction Steps

  1. Run the documentation example in Google Colab or any Python environment with huggingface_hub == 0.28.1.
  2. Observe the deprecation warning and ValueError related to missing task.
  3. Modify the code to explicitly add task="text-generation" → The issue gets resolved.

Screenshots

Attached below is an image of the error message that comes up when I run the documentation notebook in Colab.

Image


This issue ensures better onboarding for LangChain users and prevents errors in production. 🚀

Idea or request for content:

No response

jasminaaa20 added a commit to jasminaaa20/langchain that referenced this issue Feb 8, 2025
@dosubot dosubot bot added the 🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder label Feb 8, 2025
@ccurme ccurme closed this as completed in bc5fafa Feb 8, 2025
XinyaoWa added a commit to XinyaoWa/GenAIComps that referenced this issue Feb 11, 2025
Some bugs exists when using HuggingFaceEndpoint with latest langchain and huggingface_hub version, fix version until fix
Related issue link: langchain-ai/langchain#29685, https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407/discussions/42#67a8c255bc29a95bc04e9ec2

Signed-off-by: Xinyao Wang <[email protected]>
bluearrow98 pushed a commit to bluearrow98/langchain that referenced this issue Feb 13, 2025
…nt in documentation (langchain-ai#29686)

## **Description**
This PR updates the LangChain documentation to address an issue where
the `HuggingFaceEndpoint` example **does not specify the required `task`
argument**. Without this argument, users on `huggingface_hub == 0.28.1`
encounter the following error:

```
ValueError: Task unknown has no recommended model. Please specify a model explicitly.
```

---

## **Issue**
Fixes langchain-ai#29685

---

## **Changes Made**
✅ **Updated `HuggingFaceEndpoint` documentation** to explicitly define
`task="text-generation"`:
```python
llm = HuggingFaceEndpoint(
    repo_id=GEN_MODEL_ID,
    huggingfacehub_api_token=HF_TOKEN,
    task="text-generation"  # Explicitly specify task
)
```

✅ **Added a deprecation warning note** and recommended using
`InferenceClient`:
```python
from huggingface_hub import InferenceClient
from langchain.llms.huggingface_hub import HuggingFaceHub

client = InferenceClient(model=GEN_MODEL_ID, token=HF_TOKEN)

llm = HuggingFaceHub(
    repo_id=GEN_MODEL_ID,
    huggingfacehub_api_token=HF_TOKEN,
    client=client,
)
```

---

## **Dependencies**
- No new dependencies introduced.
- Change only affects **documentation**.

---

## **Testing**
- ✅ Verified that adding `task="text-generation"` resolves the issue.
- ✅ Tested the alternative approach with `InferenceClient` in Google
Colab.

---

## **Twitter Handle (Optional)**
If this PR gets announced, a shout-out to **@AkmalJasmin** would be
great! 🚀

---

## **Reviewers**
📌 **@langchain-maintainers** Please review this PR. Let me know if
further changes are needed.

🚀 This fix improves **developer onboarding** and ensures the **LangChain
documentation remains up to date**! 🚀
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant