huggingface_endpoint.py — langchain Source File
Architecture documentation for huggingface_endpoint.py, a python file in the langchain codebase. 12 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR dc421edf_ff83_8cc3_5fd8_18d9a7fbc449["huggingface_endpoint.py"] 614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> 614e7b9f_ed51_0780_749c_ff40b74963fc 2a7f66a7_8738_3d47_375b_70fcaa6ac169["logging"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> 2a7f66a7_8738_3d47_375b_70fcaa6ac169 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c["os"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> f3bc7443_c889_119d_0744_aacc3620d8d2 89934eed_a823_2184_acf2_039f48eed5f9["langchain_core.language_models.llms"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> 89934eed_a823_2184_acf2_039f48eed5f9 ac2a9b92_4484_491e_1b48_ec85e71e1d58["langchain_core.outputs"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> ac2a9b92_4484_491e_1b48_ec85e71e1d58 f4d905c6_a2b2_eb8f_be9b_7808b72f6a16["langchain_core.utils"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> f4d905c6_a2b2_eb8f_be9b_7808b72f6a16 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> 91721f45_4909_e489_8c1f_084f8bd87145 be4d43fb_de74_de45_f3c6_e9caae1c1da3["huggingface_hub"] dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 --> be4d43fb_de74_de45_f3c6_e9caae1c1da3 style dc421edf_ff83_8cc3_5fd8_18d9a7fbc449 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
import inspect
import logging
import os
from collections.abc import AsyncIterator, Iterator, Mapping
from typing import Any
from langchain_core.callbacks import (
AsyncCallbackManagerForLLMRun,
CallbackManagerForLLMRun,
)
from langchain_core.language_models.llms import LLM
from langchain_core.outputs import GenerationChunk
from langchain_core.utils import from_env, get_pydantic_field_names
from pydantic import ConfigDict, Field, model_validator
from typing_extensions import Self
logger = logging.getLogger(__name__)
VALID_TASKS = (
"text2text-generation",
"text-generation",
"summarization",
"conversational",
)
class HuggingFaceEndpoint(LLM):
"""Hugging Face Endpoint. This works with any model that supports text generation (i.e. text completion) task.
To use this class, you should have installed the `huggingface_hub` package, and
the environment variable `HUGGINGFACEHUB_API_TOKEN` set with your API token,
or given as a named parameter to the constructor.
Example:
```python
# Basic Example (no streaming)
model = HuggingFaceEndpoint(
endpoint_url="http://localhost:8010/",
max_new_tokens=512,
top_k=10,
top_p=0.95,
typical_p=0.95,
temperature=0.01,
repetition_penalty=1.03,
huggingfacehub_api_token="my-api-key",
)
print(model.invoke("What is Deep Learning?"))
# Streaming response example
from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
callbacks = [StreamingStdOutCallbackHandler()]
model = HuggingFaceEndpoint(
endpoint_url="http://localhost:8010/",
max_new_tokens=512,
top_k=10,
top_p=0.95,
typical_p=0.95,
// ... (396 more lines)
Domain
Subdomains
Classes
Dependencies
- collections.abc
- huggingface_hub
- inspect
- langchain_core.callbacks
- langchain_core.language_models.llms
- langchain_core.outputs
- langchain_core.utils
- logging
- os
- pydantic
- typing
- typing_extensions
Source
Frequently Asked Questions
What does huggingface_endpoint.py do?
huggingface_endpoint.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does huggingface_endpoint.py depend on?
huggingface_endpoint.py imports 12 module(s): collections.abc, huggingface_hub, inspect, langchain_core.callbacks, langchain_core.language_models.llms, langchain_core.outputs, langchain_core.utils, logging, and 4 more.
Where is huggingface_endpoint.py in the architecture?
huggingface_endpoint.py is located at libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/partners/huggingface/langchain_huggingface/llms).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free