langchainhuggingface

Is there a change in the langchain libraries and interfaces?


Is there a change in the langchain libraries and interfaces ?

Of late I am seeing that sample code in langchain documentation is not working. Hence my question.

For example, the below code throws an error: Reference link: https://python.langchain.com/docs/integrations/chat/huggingface/

from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint

llm = HuggingFaceEndpoint(
    repo_id="HuggingFaceH4/zephyr-7b-beta",
    task="text-generation",
    max_new_tokens=512,
    do_sample=False,
    repetition_penalty=1.03,
)

chat_model = ChatHuggingFace(llm=llm)

Error:

ImportError: cannot import name 'from_env' from 'langchain_core.utils'

Solution

  • from_env was added in langchain-core 0.2.30 (https://github.com/langchain-ai/langchain/issues/26497) What version are you using?

    from pprint import pprint
    from importlib.metadata import version
    from packaging.version import parse
    
    pprint(parse(version("langchain_core")))
    

    I get:

    <Version('0.3.35')>