langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
95.19k stars 15.44k forks source link

Chathuggingface 422 error #24720

Open minmin-intel opened 3 months ago

minmin-intel commented 3 months ago

Checked other resources

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

magallardo commented 3 months ago

I am experiencing the same issue.

michael-newsrx commented 3 months ago

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 commented 2 months ago

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