Home / File/ extraction.py — langchain Source File

extraction.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 9 imports 3 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  06667752_7187_1720_baa8_7d9c23d8c564["extraction.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> ba43b74d_3099_7e1c_aac3_cf594720469e
  89a4ade4_215f_cae5_8190_9505303396df["langchain_core.output_parsers.openai_functions"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> 89a4ade4_215f_cae5_8190_9505303396df
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> e6b4f61e_7b98_6666_3641_26b069517d4a
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  01158a5b_b299_f45d_92e9_2a7433a1a91a["langchain_classic.chains.base"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> 01158a5b_b299_f45d_92e9_2a7433a1a91a
  31974615_0d58_bd26_13f1_776e0a9d1413["langchain_classic.chains.llm"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> 31974615_0d58_bd26_13f1_776e0a9d1413
  adb7df42_9e8b_8138_9232_5644fd090124["langchain_classic.chains.openai_functions.utils"]
  06667752_7187_1720_baa8_7d9c23d8c564 --> adb7df42_9e8b_8138_9232_5644fd090124
  style 06667752_7187_1720_baa8_7d9c23d8c564 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Any

from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.output_parsers.openai_functions import (
    JsonKeyOutputFunctionsParser,
    PydanticAttrOutputFunctionsParser,
)
from langchain_core.prompts import BasePromptTemplate, ChatPromptTemplate
from pydantic import BaseModel

from langchain_classic.chains.base import Chain
from langchain_classic.chains.llm import LLMChain
from langchain_classic.chains.openai_functions.utils import (
    _convert_schema,
    _resolve_schema_references,
    get_llm_kwargs,
)


def _get_extraction_function(entity_schema: dict) -> dict:
    return {
        "name": "information_extraction",
        "description": "Extracts the relevant information from the passage.",
        "parameters": {
            "type": "object",
            "properties": {
                "info": {"type": "array", "items": _convert_schema(entity_schema)},
            },
            "required": ["info"],
        },
    }


_EXTRACTION_TEMPLATE = """Extract and save the relevant entities mentioned \
in the following passage together with their properties.

Only extract the properties mentioned in the 'information_extraction' function.

If a property is not present and is not required in the function parameters, do not include it in the output.

Passage:
{input}
"""  # noqa: E501


@deprecated(
    since="0.1.14",
    message=(
        "LangChain has introduced a method called `with_structured_output` that"
        "is available on ChatModels capable of tool calling."
        "You can read more about the method here: "
        "<https://docs.langchain.com/oss/python/langchain/models#structured-outputs>."
    ),
    removal="1.0",
    alternative=(
        """
            from pydantic import BaseModel, Field
            from langchain_anthropic import ChatAnthropic

// ... (131 more lines)

Subdomains

Classes

Dependencies

  • langchain_classic.chains.base
  • langchain_classic.chains.llm
  • langchain_classic.chains.openai_functions.utils
  • langchain_core._api
  • langchain_core.language_models
  • langchain_core.output_parsers.openai_functions
  • langchain_core.prompts
  • pydantic
  • typing

Frequently Asked Questions

What does extraction.py do?
extraction.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in extraction.py?
extraction.py defines 3 function(s): _get_extraction_function, create_extraction_chain, create_extraction_chain_pydantic.
What does extraction.py depend on?
extraction.py imports 9 module(s): langchain_classic.chains.base, langchain_classic.chains.llm, langchain_classic.chains.openai_functions.utils, langchain_core._api, langchain_core.language_models, langchain_core.output_parsers.openai_functions, langchain_core.prompts, pydantic, and 1 more.
Where is extraction.py in the architecture?
extraction.py is located at libs/langchain/langchain_classic/chains/openai_functions/extraction.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/langchain_classic/chains/openai_functions).

Analyze Your Own Codebase

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

Try Supermodel Free