Add JSON loading and serialization methods to PromptBuilder
This commit is contained in:
parent
9b50cf1575
commit
dc2e2b4ed2
@ -391,4 +391,37 @@ class PromptBuilder {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loads nodes from a JSON map
|
||||||
|
void loadFromJson(Map<String, dynamic> json) {
|
||||||
|
_nodes.clear();
|
||||||
|
_outputToNode.clear();
|
||||||
|
|
||||||
|
json.forEach((nodeId, nodeData) {
|
||||||
|
_nodes[nodeId] = nodeData;
|
||||||
|
|
||||||
|
// Register outputs of this node
|
||||||
|
final classType = nodeData["class_type"];
|
||||||
|
final defaultOutputs = _getDefaultOutputs(classType);
|
||||||
|
for (var i = 0; i < defaultOutputs.length; i++) {
|
||||||
|
final outputTag = nodeData["_meta"]?["outputTags"]
|
||||||
|
?[defaultOutputs[i]] ??
|
||||||
|
defaultOutputs[i];
|
||||||
|
_outputToNode[outputTag] = {
|
||||||
|
"nodeId": nodeId,
|
||||||
|
"outputIndex": i.toString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update the node ID counter to avoid collisions
|
||||||
|
_nodeIdCounter =
|
||||||
|
_nodes.keys.map(int.parse).fold(0, (max, id) => id > max ? id : max) +
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts the current nodes to a JSON map
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return Map<String, dynamic>.from(_nodes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user