diff options
| author | sigoden <sigoden@gmail.com> | 2025-02-10 14:47:37 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-10 14:47:37 +0800 |
| commit | fad2c60605b67a44dc6d242cd99f6f79f1bd4b13 (patch) | |
| tree | 1e09d16e378c273ad2d3668e329c80aeaf6d741c | |
| parent | e4f85a056cdd2081374e3923af660942363f1133 (diff) | |
| download | llm-functions-docker-fad2c60605b67a44dc6d242cd99f6f79f1bd4b13.tar.gz | |
refactor: improve run-agent/run-agent scripts (#160)
| -rwxr-xr-x | scripts/run-agent.js | 7 | ||||
| -rwxr-xr-x | scripts/run-agent.py | 13 | ||||
| -rwxr-xr-x | scripts/run-tool.js | 7 | ||||
| -rwxr-xr-x | scripts/run-tool.py | 13 |
4 files changed, 12 insertions, 28 deletions
diff --git a/scripts/run-agent.js b/scripts/run-agent.js index 6a14990..48096c7 100755 --- a/scripts/run-agent.js +++ b/scripts/run-agent.js @@ -106,15 +106,10 @@ async function loadEnv(filePath) { } async function run(agentName, agentPath, agentFunc, agentData) { - let mod; if (os.platform() === "win32") { agentPath = `file://${agentPath}`; } - try { - mod = await import(agentPath); - } catch { - throw new Error(`Unable to load agent tools at '${agentPath}'`); - } + const mod = await import(agentPath); if (!mod || !mod[agentFunc]) { throw new Error(`Not module function '${agentFunc}' at '${agentPath}'`); } diff --git a/scripts/run-agent.py b/scripts/run-agent.py index 9367ea5..7458869 100755 --- a/scripts/run-agent.py +++ b/scripts/run-agent.py @@ -94,14 +94,11 @@ def load_env(file_path): def run(agent_name, agent_path, agent_func, agent_data): - try: - spec = importlib.util.spec_from_file_location( - os.path.basename(agent_path), agent_path - ) - mod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(mod) - except: - raise Exception(f"Unable to load agent tools at '{agent_path}'") + spec = importlib.util.spec_from_file_location( + os.path.basename(agent_path), agent_path + ) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) if not hasattr(mod, agent_func): raise Exception(f"Not module function '{agent_func}' at '{agent_path}'") diff --git a/scripts/run-tool.js b/scripts/run-tool.js index ea0b3a5..841fbc0 100755 --- a/scripts/run-tool.js +++ b/scripts/run-tool.js @@ -93,15 +93,10 @@ async function loadEnv(filePath) { } async function run(toolName, toolPath, toolFunc, toolData) { - let mod; if (os.platform() === "win32") { toolPath = `file://${toolPath}`; } - try { - mod = await import(toolPath); - } catch { - throw new Error(`Unable to load tool at '${toolPath}'`); - } + const mod = await import(toolPath); if (!mod || !mod[toolFunc]) { throw new Error(`Not module function '${toolFunc}' at '${toolPath}'`); } diff --git a/scripts/run-tool.py b/scripts/run-tool.py index f0f2917..590125c 100755 --- a/scripts/run-tool.py +++ b/scripts/run-tool.py @@ -89,14 +89,11 @@ def load_env(file_path): def run(tool_name, tool_path, tool_func, tool_data): - try: - spec = importlib.util.spec_from_file_location( - os.path.basename(tool_path), tool_path - ) - mod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(mod) - except: - raise Exception(f"Unable to load tool at '{tool_path}'") + spec = importlib.util.spec_from_file_location( + os.path.basename(tool_path), tool_path + ) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) if not hasattr(mod, tool_func): raise Exception(f"Not module function '{tool_func}' at '{tool_path}'") |
