Home / File/ base.py — langchain Source File

base.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  8834d865_0708_a233_a0db_9aa096d1cbf7["base.py"]
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  8834d865_0708_a233_a0db_9aa096d1cbf7 --> cccbe73e_4644_7211_4d55_e8fb133a8014
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  8834d865_0708_a233_a0db_9aa096d1cbf7 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"]
  8834d865_0708_a233_a0db_9aa096d1cbf7 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c
  style 8834d865_0708_a233_a0db_9aa096d1cbf7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Interface for selecting examples to include in prompts."""

from abc import ABC, abstractmethod
from typing import Any

from langchain_core.runnables import run_in_executor


class BaseExampleSelector(ABC):
    """Interface for selecting examples to include in prompts."""

    @abstractmethod
    def add_example(self, example: dict[str, str]) -> Any:
        """Add new example to store.

        Args:
            example: A dictionary with keys as input variables
                and values as their values.

        Returns:
            Any return value.
        """

    async def aadd_example(self, example: dict[str, str]) -> Any:
        """Async add new example to store.

        Args:
            example: A dictionary with keys as input variables
                and values as their values.

        Returns:
            Any return value.
        """
        return await run_in_executor(None, self.add_example, example)

    @abstractmethod
    def select_examples(self, input_variables: dict[str, str]) -> list[dict]:
        """Select which examples to use based on the inputs.

        Args:
            input_variables: A dictionary with keys as input variables
                and values as their values.

        Returns:
            A list of examples.
        """

    async def aselect_examples(self, input_variables: dict[str, str]) -> list[dict]:
        """Async select which examples to use based on the inputs.

        Args:
            input_variables: A dictionary with keys as input variables
                and values as their values.

        Returns:
            A list of examples.
        """
        return await run_in_executor(None, self.select_examples, input_variables)

Subdomains

Dependencies

  • abc
  • langchain_core.runnables
  • typing

Frequently Asked Questions

What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the PromptManagement domain, ExampleSelection subdomain.
What does base.py depend on?
base.py imports 3 module(s): abc, langchain_core.runnables, typing.
Where is base.py in the architecture?
base.py is located at libs/core/langchain_core/example_selectors/base.py (domain: PromptManagement, subdomain: ExampleSelection, directory: libs/core/langchain_core/example_selectors).

Analyze Your Own Codebase

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

Try Supermodel Free