DoctranPropertyExtractor#

class langchain_community.document_transformers.doctran_text_extract.DoctranPropertyExtractor(properties: List[dict], openai_api_key: str | None = None, openai_api_model: str | None = None)[source]#

Extract properties from text documents using doctran.

Parameters:
  • properties (List[dict]) – A list of the properties to extract.

  • openai_api_key (str | None) – OpenAI API key. Can also be specified via environment variable OPENAI_API_KEY.

  • openai_api_model (str | None)

Example

from langchain_community.document_transformers import DoctranPropertyExtractor

properties = [
    {
        "name": "category",
        "description": "What type of email this is.",
        "type": "string",
        "enum": ["update", "action_item", "customer_feedback", "announcement", "other"],
        "required": True,
    },
    {
        "name": "mentions",
        "description": "A list of all people mentioned in this email.",
        "type": "array",
        "items": {
            "name": "full_name",
            "description": "The full name of the person mentioned.",
            "type": "string",
        },
        "required": True,
    },
    {
        "name": "eli5",
        "description": "Explain this email to me like I'm 5 years old.",
        "type": "string",
        "required": True,
    },
]

# Pass in openai_api_key or set env var OPENAI_API_KEY
property_extractor = DoctranPropertyExtractor(properties)
transformed_document = await qa_transformer.atransform_documents(documents)

Methods

__init__(properties[,Β openai_api_key,Β ...])

atransform_documents(documents,Β **kwargs)

Extracts properties from text documents using doctran.

transform_documents(documents,Β **kwargs)

Extracts properties from text documents using doctran.

__init__(properties: List[dict], openai_api_key: str | None = None, openai_api_model: str | None = None) β†’ None[source]#
Parameters:
  • properties (List[dict])

  • openai_api_key (str | None)

  • openai_api_model (str | None)

Return type:

None

async atransform_documents(documents: Sequence[Document], **kwargs: Any) β†’ Sequence[Document][source]#

Extracts properties from text documents using doctran.

Parameters:
  • documents (Sequence[Document])

  • kwargs (Any)

Return type:

Sequence[Document]

transform_documents(documents: Sequence[Document], **kwargs: Any) β†’ Sequence[Document][source]#

Extracts properties from text documents using doctran.

Parameters:
  • documents (Sequence[Document])

  • kwargs (Any)

Return type:

Sequence[Document]

Examples using DoctranPropertyExtractor