Home / File/ huggingface.py — langchain Source File

huggingface.py — langchain Source File

Architecture documentation for huggingface.py, a python file in the langchain codebase. 27 imports, 0 dependents.

File python LangChainCore LanguageModelBase 27 imports 11 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  d84d1503_7d4c_e393_0d48_409c5faa5e2d["huggingface.py"]
  be45a0bb_0276_f8f1_f985_55cddb92c224["contextlib"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> be45a0bb_0276_f8f1_f985_55cddb92c224
  9d14ea65_8b2e_6721_a947_acc89905651f["json"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> 9d14ea65_8b2e_6721_a947_acc89905651f
  2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> 2bf6d401_816d_d011_3b05_a6114f55ff58
  cd5f8820_9b2e_4495_abb7_d76026ac826c["dataclasses"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> cd5f8820_9b2e_4495_abb7_d76026ac826c
  ba56ae45_39a0_5895_3909_d9469cd3e893["operator"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> ba56ae45_39a0_5895_3909_d9469cd3e893
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> feec1ec4_6917_867b_d228_b134d0ff8099
  ba6be343_76b4_fcf9_1394_792ace09428d["langchain_huggingface.llms.huggingface_endpoint"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> ba6be343_76b4_fcf9_1394_792ace09428d
  381ab133_5f0b_9545_0121_45c6853bd8ff["langchain_huggingface.llms.huggingface_pipeline"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> 381ab133_5f0b_9545_0121_45c6853bd8ff
  e61aa479_9dc0_09a0_8864_cbf23b8b506c["langchain_core.callbacks.manager"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> e61aa479_9dc0_09a0_8864_cbf23b8b506c
  e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> e929cf21_6ab8_6ff3_3765_0d35a099a053
  f77bacd6_1087_c145_d5d5_68e6f3937f9d["langchain_core.language_models.chat_models"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> f77bacd6_1087_c145_d5d5_68e6f3937f9d
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  4314bbaf_e703_b502_e912_6f6a39f2ab89["langchain_core.messages.tool"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> 4314bbaf_e703_b502_e912_6f6a39f2ab89
  628cbc5d_711f_ac0c_2f53_db992d48d7da["langchain_core.output_parsers"]
  d84d1503_7d4c_e393_0d48_409c5faa5e2d --> 628cbc5d_711f_ac0c_2f53_db992d48d7da
  style d84d1503_7d4c_e393_0d48_409c5faa5e2d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Hugging Face Chat Wrapper."""

from __future__ import annotations

import contextlib
import json
from collections.abc import AsyncIterator, Callable, Iterator, Mapping, Sequence
from dataclasses import dataclass
from operator import itemgetter
from typing import TYPE_CHECKING, Any, Literal, cast

if TYPE_CHECKING:
    from langchain_huggingface.llms.huggingface_endpoint import HuggingFaceEndpoint
    from langchain_huggingface.llms.huggingface_pipeline import HuggingFacePipeline

from langchain_core.callbacks.manager import (
    AsyncCallbackManagerForLLMRun,
    CallbackManagerForLLMRun,
)
from langchain_core.language_models import (
    LanguageModelInput,
    ModelProfile,
    ModelProfileRegistry,
)
from langchain_core.language_models.chat_models import (
    BaseChatModel,
    agenerate_from_stream,
    generate_from_stream,
)
from langchain_core.messages import (
    AIMessage,
    AIMessageChunk,
    BaseMessage,
    BaseMessageChunk,
    ChatMessage,
    ChatMessageChunk,
    FunctionMessage,
    FunctionMessageChunk,
    HumanMessage,
    HumanMessageChunk,
    InvalidToolCall,
    SystemMessage,
    SystemMessageChunk,
    ToolCall,
    ToolMessage,
    ToolMessageChunk,
)
from langchain_core.messages.tool import ToolCallChunk
from langchain_core.messages.tool import tool_call_chunk as create_tool_call_chunk
from langchain_core.output_parsers import JsonOutputParser
from langchain_core.output_parsers.openai_tools import (
    JsonOutputKeyToolsParser,
    make_invalid_tool_call,
    parse_tool_call,
)
from langchain_core.outputs import (
    ChatGeneration,
    ChatGenerationChunk,
    ChatResult,
    LLMResult,
// ... (1188 more lines)

Domain

Subdomains

Dependencies

  • collections.abc
  • contextlib
  • dataclasses
  • huggingface_hub
  • json
  • langchain_community.llms.huggingface_hub
  • langchain_community.llms.huggingface_text_gen_inference
  • langchain_core.callbacks.manager
  • langchain_core.language_models
  • langchain_core.language_models.chat_models
  • langchain_core.messages
  • langchain_core.messages.tool
  • langchain_core.output_parsers
  • langchain_core.output_parsers.openai_tools
  • langchain_core.outputs
  • langchain_core.runnables
  • langchain_core.tools
  • langchain_core.utils.function_calling
  • langchain_core.utils.pydantic
  • langchain_huggingface.data._profiles
  • langchain_huggingface.llms.huggingface_endpoint
  • langchain_huggingface.llms.huggingface_pipeline
  • operator
  • pydantic
  • transformers
  • typing
  • typing_extensions

Frequently Asked Questions

What does huggingface.py do?
huggingface.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, LanguageModelBase subdomain.
What functions are defined in huggingface.py?
huggingface.py defines 11 function(s): _convert_chunk_to_message_chunk, _convert_dict_to_message, _convert_message_to_dict, _get_default_model_profile, _is_huggingface_endpoint, _is_huggingface_hub, _is_huggingface_pipeline, _is_huggingface_textgen_inference, _lc_invalid_tool_call_to_hf_tool_call, _lc_tool_call_to_hf_tool_call, and 1 more.
What does huggingface.py depend on?
huggingface.py imports 27 module(s): collections.abc, contextlib, dataclasses, huggingface_hub, json, langchain_community.llms.huggingface_hub, langchain_community.llms.huggingface_text_gen_inference, langchain_core.callbacks.manager, and 19 more.
Where is huggingface.py in the architecture?
huggingface.py is located at libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/partners/huggingface/langchain_huggingface/chat_models).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free