Home / File/ list.py — langchain Source File

list.py — langchain Source File

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

File python OutputParsing StreamingParsers 10 imports 2 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  d28f62b7_244d_06f5_43bd_256d3f11044a["list.py"]
  f81772b4_f640_32b2_d805_1fb182882058["csv"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> f81772b4_f640_32b2_d805_1fb182882058
  67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> cccbe73e_4644_7211_4d55_e8fb133a8014
  efd68536_3a44_76e4_ec2a_0ec171774703["collections"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> efd68536_3a44_76e4_ec2a_0ec171774703
  4e334bc1_18d9_a6a4_18e5_7a3030396c51["io"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> 4e334bc1_18d9_a6a4_18e5_7a3030396c51
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> 91721f45_4909_e489_8c1f_084f8bd87145
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> d758344f_537f_649e_f467_b9d7442e86df
  5d37c56a_542f_e309_4416_d58ad5f08a28["langchain_core.output_parsers.transform"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> 5d37c56a_542f_e309_4416_d58ad5f08a28
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  d28f62b7_244d_06f5_43bd_256d3f11044a --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  style d28f62b7_244d_06f5_43bd_256d3f11044a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Parsers for list output."""

from __future__ import annotations

import csv
import re
from abc import abstractmethod
from collections import deque
from io import StringIO
from typing import TYPE_CHECKING, TypeVar

from typing_extensions import override

from langchain_core.messages import BaseMessage
from langchain_core.output_parsers.transform import BaseTransformOutputParser

if TYPE_CHECKING:
    from collections.abc import AsyncIterator, Iterator

T = TypeVar("T")


def droplastn(
    iter: Iterator[T],  # noqa: A002
    n: int,
) -> Iterator[T]:
    """Drop the last `n` elements of an iterator.

    Args:
        iter: The iterator to drop elements from.
        n: The number of elements to drop.

    Yields:
        The elements of the iterator, except the last n elements.
    """
    buffer: deque[T] = deque()
    for item in iter:
        buffer.append(item)
        if len(buffer) > n:
            yield buffer.popleft()


class ListOutputParser(BaseTransformOutputParser[list[str]]):
    """Parse the output of a model to a list."""

    @property
    def _type(self) -> str:
        return "list"

    @abstractmethod
    def parse(self, text: str) -> list[str]:
        """Parse the output of an LLM call.

        Args:
            text: The output of an LLM call.

        Returns:
            A list of strings.
        """

// ... (190 more lines)

Domain

Subdomains

Dependencies

  • abc
  • collections
  • collections.abc
  • csv
  • io
  • langchain_core.messages
  • langchain_core.output_parsers.transform
  • re
  • typing
  • typing_extensions

Frequently Asked Questions

What does list.py do?
list.py is a source file in the langchain codebase, written in python. It belongs to the OutputParsing domain, StreamingParsers subdomain.
What functions are defined in list.py?
list.py defines 2 function(s): collections, droplastn.
What does list.py depend on?
list.py imports 10 module(s): abc, collections, collections.abc, csv, io, langchain_core.messages, langchain_core.output_parsers.transform, re, and 2 more.
Where is list.py in the architecture?
list.py is located at libs/core/langchain_core/output_parsers/list.py (domain: OutputParsing, subdomain: StreamingParsers, directory: libs/core/langchain_core/output_parsers).

Analyze Your Own Codebase

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

Try Supermodel Free