langchain.document_transformers.openai_functions.create_metadata_tagger¶
langchain.document_transformers.openai_functions.create_metadata_tagger(metadata_schema: Union[Dict[str, Any], Type[BaseModel]], llm: BaseLanguageModel, prompt: Optional[ChatPromptTemplate] = None, *, tagging_chain_kwargs: Optional[Dict] = None) → OpenAIMetadataTagger[source]¶
Create a DocumentTransformer that uses an OpenAI function chain to automatically
tag documents with metadata based on their content and an input schema.
Args:
metadata_schema: Either a dictionary or pydantic.BaseModel class. If a dictionaryis passed in, it’s assumed to already be a valid JsonSchema.
For best results, pydantic.BaseModels should have docstrings describing what
the schema represents and descriptions for the parameters.
llm: Language model to use, assumed to support the OpenAI function-calling API.Defaults to use “gpt-3.5-turbo-0613”
prompt: BasePromptTemplate to pass to the model.
Returns:An LLMChain that will pass the given function to the model.
Example:from langchain.chat_models import ChatOpenAI
from langchain.document_transformers import create_metadata_tagger
from langchain.schema import Document
schema = {
    "properties": {
        "movie_title": { "type": "string" },
        "critic": { "type": "string" },
        "tone": {
            "type": "string",
            "enum": ["positive", "negative"]
        },
        "rating": {
            "type": "integer",
            "description": "The number of stars the critic rated the movie"
        }
    },
    "required": ["movie_title", "critic", "tone"]
}
# Must be an OpenAI model that supports functions