diff options
| author | sigoden <sigoden@gmail.com> | 2024-10-23 17:22:11 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-23 17:22:11 +0800 |
| commit | fbeaa9cb2c5b7a8e0d9114a62c270c6fe8024c31 (patch) | |
| tree | c25b91f61ec2816b4425decedfd451967a003f49 /tools | |
| parent | d499954dbbfd9e4d9911d179092385ac0d161e56 (diff) | |
| download | llm-functions-docker-fbeaa9cb2c5b7a8e0d9114a62c270c6fe8024c31.tar.gz | |
feat: improve execute js/py code and collect results (#117)
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/execute_js_code.js | 6 | ||||
| -rw-r--r-- | tools/execute_py_code.py | 2 |
2 files changed, 6 insertions, 2 deletions
diff --git a/tools/execute_js_code.js b/tools/execute_js_code.js index 853ccab..6bad67a 100644 --- a/tools/execute_js_code.js +++ b/tools/execute_js_code.js @@ -1,3 +1,5 @@ +const vm = require('vm'); + /** * Execute the javascript code in node.js. * @typedef {Object} Args @@ -5,5 +7,7 @@ * @param {Args} args */ exports.run = function run({ code }) { - return eval(code); + const context = vm.createContext({}); + const script = new vm.Script(code); + return script.runInContext(context); } diff --git a/tools/execute_py_code.py b/tools/execute_py_code.py index a774e82..3c6beb4 100644 --- a/tools/execute_py_code.py +++ b/tools/execute_py_code.py @@ -3,4 +3,4 @@ def run(code: str): Args: code: Python code to execute, such as `print("hello world")` """ - return exec(code) + return eval(code)
\ No newline at end of file |
