core[patch]: pass node name in graph.to_json()

This commit is contained in:
vbarda 2024-11-01 16:26:16 -04:00
parent 71f590de50
commit 5dc3db0a96
3 changed files with 35 additions and 0 deletions

View File

@ -294,6 +294,7 @@ class Graph:
"nodes": [ "nodes": [
{ {
"id": stable_node_ids[node.id], "id": stable_node_ids[node.id],
"name": node.name,
**node_data_json(node, with_schemas=with_schemas), **node_data_json(node, with_schemas=with_schemas),
} }
for node in self.nodes.values() for node in self.nodes.values()

View File

@ -177,6 +177,7 @@
dict({ dict({
'data': 'PromptInput', 'data': 'PromptInput',
'id': 0, 'id': 0,
'name': 'PromptInput',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -190,6 +191,7 @@
'name': 'PromptTemplate', 'name': 'PromptTemplate',
}), }),
'id': 1, 'id': 1,
'name': 'PromptTemplate',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
@ -203,16 +205,19 @@
'name': 'FakeListLLM', 'name': 'FakeListLLM',
}), }),
'id': 2, 'id': 2,
'name': 'FakeListLLM',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
'data': 'Parallel<as_list,as_str>Input', 'data': 'Parallel<as_list,as_str>Input',
'id': 3, 'id': 3,
'name': 'Parallel<as_list,as_str>Input',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
'data': 'Parallel<as_list,as_str>Output', 'data': 'Parallel<as_list,as_str>Output',
'id': 4, 'id': 4,
'name': 'Parallel<as_list,as_str>Output',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -226,16 +231,19 @@
'name': 'CommaSeparatedListOutputParser', 'name': 'CommaSeparatedListOutputParser',
}), }),
'id': 5, 'id': 5,
'name': 'CommaSeparatedListOutputParser',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
'data': 'conditional_str_parser_input', 'data': 'conditional_str_parser_input',
'id': 6, 'id': 6,
'name': 'conditional_str_parser_input',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
'data': 'conditional_str_parser_output', 'data': 'conditional_str_parser_output',
'id': 7, 'id': 7,
'name': 'conditional_str_parser_output',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -249,6 +257,7 @@
'name': 'StrOutputParser', 'name': 'StrOutputParser',
}), }),
'id': 8, 'id': 8,
'name': 'StrOutputParser',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
@ -262,6 +271,7 @@
'name': 'XMLOutputParser', 'name': 'XMLOutputParser',
}), }),
'id': 9, 'id': 9,
'name': 'XMLOutputParser',
'type': 'runnable', 'type': 'runnable',
}), }),
]), ]),
@ -331,6 +341,7 @@
'type': 'object', 'type': 'object',
}), }),
'id': 0, 'id': 0,
'name': 'PromptInput',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -344,6 +355,7 @@
'name': 'PromptTemplate', 'name': 'PromptTemplate',
}), }),
'id': 1, 'id': 1,
'name': 'PromptTemplate',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
@ -357,6 +369,7 @@
'name': 'FakeListLLM', 'name': 'FakeListLLM',
}), }),
'id': 2, 'id': 2,
'name': 'FakeListLLM',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
@ -1765,6 +1778,7 @@
'title': 'RunnableParallel<as_list,as_str>Input', 'title': 'RunnableParallel<as_list,as_str>Input',
}), }),
'id': 3, 'id': 3,
'name': 'Parallel<as_list,as_str>Input',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -1789,6 +1803,7 @@
'type': 'object', 'type': 'object',
}), }),
'id': 4, 'id': 4,
'name': 'Parallel<as_list,as_str>Output',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -1802,6 +1817,7 @@
'name': 'CommaSeparatedListOutputParser', 'name': 'CommaSeparatedListOutputParser',
}), }),
'id': 5, 'id': 5,
'name': 'CommaSeparatedListOutputParser',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
@ -1810,6 +1826,7 @@
'type': 'string', 'type': 'string',
}), }),
'id': 6, 'id': 6,
'name': 'conditional_str_parser_input',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -1817,6 +1834,7 @@
'title': 'conditional_str_parser_output', 'title': 'conditional_str_parser_output',
}), }),
'id': 7, 'id': 7,
'name': 'conditional_str_parser_output',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -1830,6 +1848,7 @@
'name': 'StrOutputParser', 'name': 'StrOutputParser',
}), }),
'id': 8, 'id': 8,
'name': 'StrOutputParser',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
@ -1843,6 +1862,7 @@
'name': 'XMLOutputParser', 'name': 'XMLOutputParser',
}), }),
'id': 9, 'id': 9,
'name': 'XMLOutputParser',
'type': 'runnable', 'type': 'runnable',
}), }),
]), ]),
@ -1986,6 +2006,7 @@
dict({ dict({
'data': '__start__', 'data': '__start__',
'id': '__start__', 'id': '__start__',
'name': '__start__',
'type': 'schema', 'type': 'schema',
}), }),
dict({ dict({
@ -1999,6 +2020,7 @@
'name': 'ask_question', 'name': 'ask_question',
}), }),
'id': 'ask_question', 'id': 'ask_question',
'name': 'ask_question',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
@ -2012,11 +2034,13 @@
'name': 'answer_question', 'name': 'answer_question',
}), }),
'id': 'answer_question', 'id': 'answer_question',
'name': 'answer_question',
'type': 'runnable', 'type': 'runnable',
}), }),
dict({ dict({
'data': '__end__', 'data': '__end__',
'id': '__end__', 'id': '__end__',
'name': '__end__',
'type': 'schema', 'type': 'schema',
}), }),
]), ]),

View File

@ -81,6 +81,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
"id": 0, "id": 0,
"type": "schema", "type": "schema",
"data": "PromptInput", "data": "PromptInput",
"name": "PromptInput"
}, },
{ {
"id": 1, "id": 1,
@ -89,6 +90,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
"id": ["langchain", "prompts", "prompt", "PromptTemplate"], "id": ["langchain", "prompts", "prompt", "PromptTemplate"],
"name": "PromptTemplate", "name": "PromptTemplate",
}, },
"name": "PromptTemplate",
}, },
{ {
"id": 2, "id": 2,
@ -97,6 +99,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
"id": ["langchain_core", "language_models", "fake", "FakeListLLM"], "id": ["langchain_core", "language_models", "fake", "FakeListLLM"],
"name": "FakeListLLM", "name": "FakeListLLM",
}, },
"name": "FakeListLLM",
"metadata": {"key": 2}, "metadata": {"key": 2},
}, },
{ {
@ -111,11 +114,13 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
], ],
"name": "CommaSeparatedListOutputParser", "name": "CommaSeparatedListOutputParser",
}, },
"name": "CommaSeparatedListOutputParser",
}, },
{ {
"id": 4, "id": 4,
"type": "schema", "type": "schema",
"data": "CommaSeparatedListOutputParserOutput", "data": "CommaSeparatedListOutputParserOutput",
"name": "CommaSeparatedListOutputParserOutput",
}, },
], ],
"edges": [ "edges": [
@ -136,6 +141,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
"properties": {"name": {"title": "Name", "type": "string"}}, "properties": {"name": {"title": "Name", "type": "string"}},
"required": ["name"], "required": ["name"],
}, },
"name": "PromptInput",
}, },
{ {
"id": 1, "id": 1,
@ -144,6 +150,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
"id": ["langchain", "prompts", "prompt", "PromptTemplate"], "id": ["langchain", "prompts", "prompt", "PromptTemplate"],
"name": "PromptTemplate", "name": "PromptTemplate",
}, },
"name": "PromptTemplate",
}, },
{ {
"id": 2, "id": 2,
@ -153,6 +160,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
"name": "FakeListLLM", "name": "FakeListLLM",
}, },
"metadata": {"key": 2}, "metadata": {"key": 2},
"name": "FakeListLLM",
}, },
{ {
"id": 3, "id": 3,
@ -166,6 +174,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
], ],
"name": "CommaSeparatedListOutputParser", "name": "CommaSeparatedListOutputParser",
}, },
"name": "CommaSeparatedListOutputParser",
}, },
{ {
"id": 4, "id": 4,
@ -175,6 +184,7 @@ def test_graph_sequence(snapshot: SnapshotAssertion) -> None:
"title": "CommaSeparatedListOutputParserOutput", "title": "CommaSeparatedListOutputParserOutput",
"type": "array", "type": "array",
}, },
"name": "CommaSeparatedListOutputParserOutput",
}, },
], ],
"edges": [ "edges": [