Home / File/ test_huggingface_pipeline.py — langchain Source File

test_huggingface_pipeline.py — langchain Source File

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

File python LangChainCore ApiManagement 2 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  f31955a1_0524_be5f_87e5_aca998c86526["test_huggingface_pipeline.py"]
  23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"]
  f31955a1_0524_be5f_87e5_aca998c86526 --> 23cb242e_1754_041d_200a_553fcb8abe1b
  15101b31_601b_416b_11c8_2c6abc032083["langchain_huggingface"]
  f31955a1_0524_be5f_87e5_aca998c86526 --> 15101b31_601b_416b_11c8_2c6abc032083
  style f31955a1_0524_be5f_87e5_aca998c86526 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from unittest.mock import MagicMock, patch

from langchain_huggingface import HuggingFacePipeline

DEFAULT_MODEL_ID = "gpt2"


def test_initialization_default() -> None:
    """Test default initialization."""
    llm = HuggingFacePipeline()

    assert llm.model_id == DEFAULT_MODEL_ID


@patch("transformers.pipeline")
def test_initialization_with_pipeline(mock_pipeline: MagicMock) -> None:
    """Test initialization with a pipeline object."""
    mock_pipe = MagicMock()
    mock_pipe.model.name_or_path = "mock-model-id"
    mock_pipeline.return_value = mock_pipe

    llm = HuggingFacePipeline(pipeline=mock_pipe)

    assert llm.model_id == "mock-model-id"


@patch("transformers.AutoTokenizer.from_pretrained")
@patch("transformers.AutoModelForCausalLM.from_pretrained")
@patch("transformers.pipeline")
def test_initialization_with_from_model_id(
    mock_pipeline: MagicMock, mock_model: MagicMock, mock_tokenizer: MagicMock
) -> None:
    """Test initialization with the from_model_id method."""
    mock_tokenizer.return_value = MagicMock(pad_token_id=0)
    mock_model.return_value = MagicMock()

    mock_pipe = MagicMock()
    mock_pipe.task = "text-generation"
    mock_pipe.model = mock_model.return_value
    mock_pipeline.return_value = mock_pipe

    llm = HuggingFacePipeline.from_model_id(
        model_id="mock-model-id",
        task="text-generation",
    )

    assert llm.model_id == "mock-model-id"

Domain

Subdomains

Dependencies

  • langchain_huggingface
  • unittest.mock

Frequently Asked Questions

What does test_huggingface_pipeline.py do?
test_huggingface_pipeline.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in test_huggingface_pipeline.py?
test_huggingface_pipeline.py defines 3 function(s): test_initialization_default, test_initialization_with_from_model_id, test_initialization_with_pipeline.
What does test_huggingface_pipeline.py depend on?
test_huggingface_pipeline.py imports 2 module(s): langchain_huggingface, unittest.mock.
Where is test_huggingface_pipeline.py in the architecture?
test_huggingface_pipeline.py is located at libs/partners/huggingface/tests/unit_tests/test_huggingface_pipeline.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/partners/huggingface/tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free