diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-06 08:52:40 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-06 08:52:40 +0800 |
| commit | 7d5b14bca135ce521a48c00e54e2e34c7bb76773 (patch) | |
| tree | 5e55922192bb8f774d603e7cac6e453f2ee32fa6 /run/tool.py | |
| parent | bfb7d75fe47ea588495c5be8157a67b1fec67a13 (diff) | |
| download | llm-functions-docker-7d5b14bca135ce521a48c00e54e2e34c7bb76773.tar.gz | |
feat: support dotenv (#18)
Diffstat (limited to 'run/tool.py')
| -rwxr-xr-x | run/tool.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/run/tool.py b/run/tool.py index 99163d3..d986692 100755 --- a/run/tool.py +++ b/run/tool.py @@ -22,8 +22,7 @@ def parse_argv(): return func_file, func_data def load_func(func_file): - base_dir = os.path.dirname(os.path.abspath(__file__)) - func_path = os.path.join(base_dir, f"../tools/{func_file}") + func_path = os.path.join(os.environ["LLM_FUNCTIONS_DIR"], f"tools/{func_file}") if os.path.exists(func_path): spec = importlib.util.spec_from_file_location(func_file, func_path) module = importlib.util.module_from_spec(spec) @@ -33,6 +32,23 @@ def load_func(func_file): print(f"Invalid function: {func_file}") sys.exit(1) +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('=') + os.environ[key.strip()] = '='.join(value).strip() + except FileNotFoundError: + pass + +os.environ["LLM_FUNCTIONS_DIR"] = os.path.join(os.path.dirname(__file__), "..") + +load_env(os.path.join(os.environ["LLM_FUNCTIONS_DIR"], ".env")) + func_file, func_data = parse_argv() if os.getenv("LLM_FUNCTION_ACTION") == "declarate": |
