aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/run-agent.py
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-10-18 20:19:10 +0800
committerGitHub <noreply@github.com>2024-10-18 20:19:10 +0800
commite098f7f43a7e8e4e85149bc5d24aa854a98cec66 (patch)
treef098d86776a00494a1fba85ab2461b4f04f62d3f /scripts/run-agent.py
parent615aa25266cf024027aca178f16f75bd115a9901 (diff)
downloadllm-functions-docker-e098f7f43a7e8e4e85149bc5d24aa854a98cec66.tar.gz
fix: js/py dotenv unable to parse quoted value or duplicated (#114)
Diffstat (limited to 'scripts/run-agent.py')
-rwxr-xr-xscripts/run-agent.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/scripts/run-agent.py b/scripts/run-agent.py
index 5c925ba..58595e4 100755
--- a/scripts/run-agent.py
+++ b/scripts/run-agent.py
@@ -61,17 +61,29 @@ def setup_env(root_dir, agent_name, agent_func):
def load_env(file_path):
try:
with open(file_path, "r") as f:
- for line in f:
- line = line.strip()
- if line.startswith("#") or line == "":
- continue
-
- key, *value = line.split("=")
- env_name = key.strip()
- if env_name not in os.environ:
- os.environ[env_name] = "=".join(value).strip()
- except FileNotFoundError:
- pass
+ lines = f.readlines()
+ except:
+ return
+
+ env_vars = {}
+
+ for line in lines:
+ line = line.strip()
+ if line.startswith("#") or not line:
+ continue
+
+ key, *value_parts = line.split("=")
+ env_name = key.strip()
+
+ if env_name not in os.environ:
+ env_value = "=".join(value_parts).strip()
+ if env_value.startswith('"') and env_value.endswith('"'):
+ env_value = env_value[1:-1]
+ elif env_value.startswith("'") and env_value.endswith("'"):
+ env_value = env_value[1:-1]
+ env_vars[env_name] = env_value
+
+ os.environ.update(env_vars)
def run(agent_path, agent_func, agent_data):