Add JSON serialization methods to PromptBuilder for improved data handling
This commit is contained in:
parent
ea0738bad6
commit
2eebe2378f
@ -1,10 +1,31 @@
|
||||
class PromptBuilder {
|
||||
final String clientId;
|
||||
String clientId;
|
||||
final Map<String, dynamic> _nodes = {};
|
||||
final Map<String, Map<String, String>> _outputToNode = {};
|
||||
final Map<String, Map<String, dynamic>> _outputToNode = {};
|
||||
int _nodeIdCounter = 1;
|
||||
|
||||
PromptBuilder({required this.clientId});
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"nodes": _nodes,
|
||||
"outputToNode": _outputToNode,
|
||||
"nodeIdCounter": _nodeIdCounter
|
||||
};
|
||||
}
|
||||
|
||||
void fromJson(Map<String, dynamic> json) {
|
||||
_nodes.clear();
|
||||
_outputToNode.clear();
|
||||
_nodeIdCounter = json["nodeIdCounter"];
|
||||
|
||||
for (var entry in json["nodes"].entries) {
|
||||
_nodes[entry.key] = entry.value;
|
||||
}
|
||||
|
||||
for (var entry in json["outputToNode"].entries) {
|
||||
_outputToNode[entry.key] = entry.value;
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a node to the workflow and returns its nodeId
|
||||
String addNode(String classType, Map<String, dynamic> inputs,
|
||||
|
Loading…
x
Reference in New Issue
Block a user