Home / Class/ FakeLLM Class — langchain Architecture

FakeLLM Class — langchain Architecture

Architecture documentation for the FakeLLM class in test_hyde.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a0b0d4c5_84f9_d617_2927_f2cb8543d500["FakeLLM"]
  ce4aa464_3868_179e_5d99_df48bc307c5f["BaseLLM"]
  a0b0d4c5_84f9_d617_2927_f2cb8543d500 -->|extends| ce4aa464_3868_179e_5d99_df48bc307c5f
  14c6e7c4_9f19_c161_786a_25327950593b["test_hyde.py"]
  a0b0d4c5_84f9_d617_2927_f2cb8543d500 -->|defined in| 14c6e7c4_9f19_c161_786a_25327950593b
  8fbd107c_13eb_94d2_4361_5e7a1a98ba0a["_generate()"]
  a0b0d4c5_84f9_d617_2927_f2cb8543d500 -->|method| 8fbd107c_13eb_94d2_4361_5e7a1a98ba0a
  4af9c4a6_5471_6b41_35b3_1dcaa61a9f8c["_agenerate()"]
  a0b0d4c5_84f9_d617_2927_f2cb8543d500 -->|method| 4af9c4a6_5471_6b41_35b3_1dcaa61a9f8c
  0ac758c9_dbb9_4bad_95d1_fb6caeef76ab["get_num_tokens()"]
  a0b0d4c5_84f9_d617_2927_f2cb8543d500 -->|method| 0ac758c9_dbb9_4bad_95d1_fb6caeef76ab
  c176ae74_356a_71c0_eadf_5de980e65bf4["_llm_type()"]
  a0b0d4c5_84f9_d617_2927_f2cb8543d500 -->|method| c176ae74_356a_71c0_eadf_5de980e65bf4

Relationship Graph

Source Code

libs/langchain/tests/unit_tests/chains/test_hyde.py lines 33–65

class FakeLLM(BaseLLM):
    """Fake LLM wrapper for testing purposes."""

    n: int = 1

    @override
    def _generate(
        self,
        prompts: list[str],
        stop: list[str] | None = None,
        run_manager: CallbackManagerForLLMRun | None = None,
        **kwargs: Any,
    ) -> LLMResult:
        return LLMResult(generations=[[Generation(text="foo") for _ in range(self.n)]])

    @override
    async def _agenerate(
        self,
        prompts: list[str],
        stop: list[str] | None = None,
        run_manager: AsyncCallbackManagerForLLMRun | None = None,
        **kwargs: Any,
    ) -> LLMResult:
        return LLMResult(generations=[[Generation(text="foo") for _ in range(self.n)]])

    def get_num_tokens(self, text: str) -> int:
        """Return number of tokens."""
        return len(text.split())

    @property
    def _llm_type(self) -> str:
        """Return type of llm."""
        return "fake"

Extends

Frequently Asked Questions

What is the FakeLLM class?
FakeLLM is a class in the langchain codebase, defined in libs/langchain/tests/unit_tests/chains/test_hyde.py.
Where is FakeLLM defined?
FakeLLM is defined in libs/langchain/tests/unit_tests/chains/test_hyde.py at line 33.
What does FakeLLM extend?
FakeLLM extends BaseLLM.

Analyze Your Own Codebase

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

Try Supermodel Free