From 2ba8393182ec25c672476925753ed2071e65799b Mon Sep 17 00:00:00 2001 From: WU LIFU Date: Mon, 29 Jul 2024 19:00:56 +0800 Subject: [PATCH] =?UTF-8?q?graph=5Ftransformers:=20bug=20fix=20for=20creat?= =?UTF-8?q?e=5Fsimple=5Fmodel=20not=20passing=20in=20ll=E2=80=A6=20(#24643?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue: #24615 descriptions: The _Graph pydantic model generated from create_simple_model (which LLMGraphTransformer uses when allowed nodes and relationships are provided) does not constrain the relationships (source and target types, relationship type), and the node and relationship properties with enums when using ChatOpenAI. The issue is that when calling optional_enum_field throughout create_simple_model the llm_type parameter is not passed in except for when creating node type. Passing it into each call fixes the issue. Co-authored-by: Lifu Wu --- .../langchain_experimental/graph_transformers/llm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/experimental/langchain_experimental/graph_transformers/llm.py b/libs/experimental/langchain_experimental/graph_transformers/llm.py index f55cb81feb..5b432a94bf 100644 --- a/libs/experimental/langchain_experimental/graph_transformers/llm.py +++ b/libs/experimental/langchain_experimental/graph_transformers/llm.py @@ -332,6 +332,7 @@ def create_simple_model( ), ), } + if node_properties: if isinstance(node_properties, list) and "id" in node_properties: raise ValueError("The node property 'id' is reserved and cannot be used.") @@ -347,6 +348,7 @@ def create_simple_model( node_properties_mapped, description="Property key.", input_type="property", + llm_type=llm_type, ) value: str = Field(..., description="value") @@ -370,6 +372,7 @@ def create_simple_model( node_labels, description="The type or label of the source node.", input_type="node", + llm_type=llm_type, ), ), "target_node_id": ( @@ -385,6 +388,7 @@ def create_simple_model( node_labels, description="The type or label of the target node.", input_type="node", + llm_type=llm_type, ), ), "type": ( @@ -393,6 +397,7 @@ def create_simple_model( rel_types, description="The type of the relationship.", input_type="relationship", + llm_type=llm_type, ), ), } @@ -416,6 +421,7 @@ def create_simple_model( relationship_properties_mapped, description="Property key.", input_type="property", + llm_type=llm_type, ) value: str = Field(..., description="value")