Toggle Menu
Prev Up Next

# `langchain_community.document_transformers.doctran_text_extract`.DoctranPropertyExtractor

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

  Extract properties from text documents using doctran.

  Parameters

    - properties (List[dict]) – A list of the properties to extract.

    - openai_api_key (Optional[str]) – OpenAI API key. Can also be specified via environment variable `OPENAI_API_KEY`.

    - openai_api_model (Optional[str]) –

  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: Optional[str] = None, openai_api_model: Optional[str] = None) → None
    Parameters

      - properties (List[dict]) –

      - openai_api_key (Optional[str]) –

      - openai_api_model (Optional[str]) –

    Return type

      None

  async atransform_documents(documents: Sequence[Document], **kwargs: Any) → Sequence[Document]

    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]

    Extracts properties from text documents using doctran.

    Parameters

      - documents (Sequence[Document]) –

      - kwargs (Any) –

    Return type

      Sequence[Document]

# Examples using DoctranPropertyExtractor

- doctran_extract_properties.md