Class GraalVmPythonExecutionEngine

java.lang.Object
dev.langchain4j.code.graalvm.GraalVmPythonExecutionEngine
All Implemented Interfaces:
CodeExecutionEngine

public class GraalVmPythonExecutionEngine extends Object implements CodeExecutionEngine
CodeExecutionEngine that uses GraalVM Polyglot/Truffle to execute provided Python code.

The returned string contains both what the code printed to stdout/stderr and what it evaluated to:

  • 40 + 2 evaluates to a value without printing anything, so "42" is returned
  • print('hello') only prints, so "Output:\nhello" is returned
  • print('hello')\n42 does both, so "Output:\nhello\nResult:\n42" is returned
  • x = 1 neither prints nor evaluates to a value, so an empty string is returned
When the code fails, a PolyglotException is thrown and anything printed before the failure is lost.

Attention! It might be dangerous to execute the code, see SandboxPolicy.TRUSTED and HostAccess.UNTRUSTED for more details.

  • Constructor Details

    • GraalVmPythonExecutionEngine

      public GraalVmPythonExecutionEngine()
  • Method Details