Skip to content

Chathuggingface 422 error #24720

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

Open
5 tasks done
minmin-intel opened this issue Jul 26, 2024 · 9 comments
Open
5 tasks done

Chathuggingface 422 error #24720

minmin-intel opened this issue Jul 26, 2024 · 9 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.

Comments

@minmin-intel
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint

llm = HuggingFaceEndpoint(
    endpoint_url="http://10.165.9.23:9009",
    task="text-generation",
    max_new_tokens=10,
    do_sample=False,
    temperature=0.8,
)
res = llm.invoke("Hugging Face is")
print(res)
print('-------------------')

llm_engine_hf = ChatHuggingFace(llm=llm, model_id = "meta-llama/Meta-Llama-3-8B-Instruct")
res = llm_engine_hf.invoke("Hugging Face is")
print(res)

Error Message and Stack Trace (if applicable)

No response

Description

Using ChatHuggingFace with llm being HuggingFaceEndpoint got 422 error "Unprocessable entity" from huggingface-hub Inference client post function, when using the latest versions of langchain and huggigface-hub 0.24.3. Downgrading to the following version, I got the code to run.

The working versions of packages
huggingface_hub==0.24.0
langchain==0.2.9
langchain-core==0.2.21
langchain-huggingface==0.0.3
langchain_community==0.2.7

System Info

The following versions are what caused problems
langchain-community==0.0.38
langchain-core==0.2.19
langchain-huggingface==0.0.3
langchain-openai==0.1.16
huggingface_hub==0.24.3

@langcarl langcarl bot added the investigate Flagged for investigation. label Jul 26, 2024
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jul 26, 2024
@magallardo
Copy link

I am experiencing the same issue.

@michael-newsrx
Copy link

I'm getting:

HfHubHTTPError: 422 Client Error: Unprocessable Entity for url: https://yna78eduyn1wumb2.us-east-1.aws.endpoints.huggingface.cloud/v1/chat/completions (Request ID: lIPtPv)

using:

from langchain_core.utils.function_calling import convert_to_openai_tool

dict_schema = convert_to_openai_tool(ArticleAnalysis)
output_msg = chat_model.bind(max_tokens=8192, temperature=0.0).with_structured_output(dict_schema).invoke(chat_sequence)
chat_sequence.append(output_msg)
md_text = output_msg.content
display_markdown(md_text, raw=True)
display_markdown("**Finish Reason**: " + output_msg.response_metadata["finish_reason"], raw=True)
pprint(output_msg.response_metadata)

@MoritzLaurer
Copy link

@Jofthomas could this be linked to this issue? Not sure if the base_url argument is available in the langchain wrapper

Copy link

dosubot bot commented Nov 29, 2024

Hi, @minmin-intel. I'm Dosu, and I'm helping the LangChain team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • The issue involves a 422 "Unprocessable entity" error with ChatHuggingFace and HuggingFaceEndpoint.
  • Resolved by downgrading to older versions of LangChain and huggingface-hub.
  • Other users, including @magallardo and @michael-newsrx, reported similar errors.
  • @michael-newsrx provided a code snippet to reproduce the error.
  • @MoritzLaurer suggested a potential link to another issue on the Hugging Face Hub.

Next Steps

  • Please confirm if this issue is still relevant with the latest version of LangChain.
  • If no further updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 29, 2024
@michael-conrad
Copy link

@dosubot Downgrading is not a valid solution.

@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 30, 2024
Copy link

dosubot bot commented Nov 30, 2024

@eyurtsev, the user @michael-conrad has indicated that downgrading is not a valid solution for the 422 "Unprocessable entity" error with ChatHuggingFace and HuggingFaceEndpoint. Could you please assist them with this issue?

@fhamborg
Copy link

Is there any news on this? On the latest versions it's still not working

Copy link

dosubot bot commented Jan 22, 2025

Could you provide more details about the specific configuration or parameters you are using with the Hugging Face API? Additionally, any information about the model you are trying to use or any specific changes you made before encountering the error would be helpful.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@fhamborg
Copy link

@dosu It's exactly the same as before mentioned by other users in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.
Projects
None yet
Development

No branches or pull requests

6 participants