langchain_experimental.graph_transformers.llm
.LLMGraphTransformer¶
- class langchain_experimental.graph_transformers.llm.LLMGraphTransformer(llm: BaseLanguageModel, allowed_nodes: List[str] = [], allowed_relationships: List[str] = [], prompt: Optional[ChatPromptTemplate] = None, strict_mode: bool = True, node_properties: Union[bool, List[str]] = False)[source]¶
将文档转换为基于图的文档,使用LLM。
它允许指定要包含在输出图中的节点和关系类型的约束条件。该类不支持提取节点或关系属性。
- 参数:
llm (BaseLanguageModel): 支持结构化输出的语言模型实例。 allowed_nodes (List[str], optional): 指定允许在图中出现的节点类型。默认为空列表,允许所有节点类型。 allowed_relationships (List[str], optional): 指定允许在图中出现的关系类型。默认为空列表,允许所有关系类型。 prompt (Optional[ChatPromptTemplate], optional): 传递给LLM的提示,带有额外的指令。 strict_mode (bool, optional): 确定转换器是否应用过滤以严格遵守`allowed_nodes`和`allowed_relationships`。默认为True。
- 示例:
Methods
__init__
(llm[, allowed_nodes, ...])aconvert_to_graph_documents
(documents)将一系列文档异步转换为图形文档。
aprocess_response
(document)异步处理单个文档,将其转换为图形文档。
convert_to_graph_documents
(documents)将一系列文档转换为图形文档。
process_response
(document)处理单个文档,使用基于模型架构和约束的LLM将其转换为图形文档。
- Parameters
llm (BaseLanguageModel) –
allowed_nodes (List[str]) –
allowed_relationships (List[str]) –
prompt (Optional[ChatPromptTemplate]) –
strict_mode (bool) –
node_properties (Union[bool, List[str]]) –
- Return type
None
- __init__(llm: BaseLanguageModel, allowed_nodes: List[str] = [], allowed_relationships: List[str] = [], prompt: Optional[ChatPromptTemplate] = None, strict_mode: bool = True, node_properties: Union[bool, List[str]] = False) None [source]¶
- Parameters
llm (BaseLanguageModel) –
allowed_nodes (List[str]) –
allowed_relationships (List[str]) –
prompt (Optional[ChatPromptTemplate]) –
strict_mode (bool) –
node_properties (Union[bool, List[str]]) –
- Return type
None
- async aconvert_to_graph_documents(documents: Sequence[Document]) List[GraphDocument] [source]¶
将一系列文档异步转换为图形文档。
- Parameters
documents (Sequence[Document]) –
- Return type
List[GraphDocument]
- async aprocess_response(document: Document) GraphDocument [source]¶
异步处理单个文档,将其转换为图形文档。
- Parameters
document (Document) –
- Return type
- convert_to_graph_documents(documents: Sequence[Document]) List[GraphDocument] [source]¶
将一系列文档转换为图形文档。
- 参数:
documents(Sequence[Document]):原始文档。 **kwargs:额外的关键字参数。
- 返回:
Sequence[GraphDocument]:转换后的文档作为图形。
- Parameters
documents (Sequence[Document]) –
- Return type
List[GraphDocument]
- process_response(document: Document) GraphDocument [source]¶
处理单个文档,使用基于模型架构和约束的LLM将其转换为图形文档。
- Parameters
document (Document) –
- Return type