mirror of
https://gitee.com/agents-flex/agents-flex.git
synced 2024-12-01 19:37:50 +08:00
fix: fix code node can not get the parameters
This commit is contained in:
parent
8d8cbd1d32
commit
d989bde13c
@ -28,17 +28,37 @@ public class GroovyExecNode extends CodeNode {
|
||||
@Override
|
||||
protected Map<String, Object> executeCode(String code, Chain chain) {
|
||||
Binding binding = new Binding();
|
||||
Map<String, Object> all = chain.getMemory().getAll();
|
||||
if (all != null) {
|
||||
all.forEach(binding::setVariable);
|
||||
|
||||
Map<String, Object> parameters = getParameters(chain);
|
||||
if (parameters != null) {
|
||||
parameters.forEach(binding::setVariable);
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
binding.setVariable("_result", result);
|
||||
binding.setVariable("_chain", chain);
|
||||
|
||||
binding.setVariable("chain", chain);
|
||||
GroovyShell shell = new GroovyShell(binding);
|
||||
shell.evaluate(code);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GroovyExecNode{" +
|
||||
"inwardEdges=" + inwardEdges +
|
||||
", code='" + code + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", inputParameters=" + inputParameters +
|
||||
", outputKeys=" + outputKeys +
|
||||
", id='" + id + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", async=" + async +
|
||||
", outwardEdges=" + outwardEdges +
|
||||
", condition=" + condition +
|
||||
", memory=" + memory +
|
||||
", nodeStatus=" + nodeStatus +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,13 @@ public class QLExpressExecNode extends CodeNode {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
ExpressRunner runner = new ExpressRunner();
|
||||
DefaultContext<String, Object> context = new DefaultContext<>();
|
||||
context.putAll(chain.getMemory().getAll());
|
||||
context.put("chain", chain);
|
||||
|
||||
Map<String, Object> parameters = getParameters(chain);
|
||||
if (parameters != null) context.putAll(parameters);
|
||||
|
||||
context.put("_chain", chain);
|
||||
context.put("_result", result);
|
||||
|
||||
try {
|
||||
runner.execute(code, context, null, true, false);
|
||||
} catch (Exception e) {
|
||||
@ -40,4 +44,22 @@ public class QLExpressExecNode extends CodeNode {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "QLExpressExecNode{" +
|
||||
"code='" + code + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", inputParameters=" + inputParameters +
|
||||
", outputKeys=" + outputKeys +
|
||||
", id='" + id + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", async=" + async +
|
||||
", inwardEdges=" + inwardEdges +
|
||||
", outwardEdges=" + outwardEdges +
|
||||
", condition=" + condition +
|
||||
", memory=" + memory +
|
||||
", nodeStatus=" + nodeStatus +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user