aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/cmd.py
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-06-05 18:37:52 +0800
committerGitHub <noreply@github.com>2024-06-05 18:37:52 +0800
commit005d23030dab2b7708996e779dc78dd5f8ebdb8d (patch)
tree0d05583d462a4795a4236a5006befc096047e969 /cmd/cmd.py
parent7e3f47093f2dcb36cf94a35403027ec72bf7b084 (diff)
downloadllm-functions-docker-005d23030dab2b7708996e779dc78dd5f8ebdb8d.tar.gz
feat: adjust project structure (#16)
Diffstat (limited to 'cmd/cmd.py')
-rwxr-xr-xcmd/cmd.py54
1 files changed, 0 insertions, 54 deletions
diff --git a/cmd/cmd.py b/cmd/cmd.py
deleted file mode 100755
index 4b8baca..0000000
--- a/cmd/cmd.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python
-
-import os
-import json
-import sys
-import importlib.util
-
-def parse_argv():
- func_file = sys.argv[0]
- func_data = None
-
- if func_file.endswith("cmd.py"):
- func_file = sys.argv[1] if len(sys.argv) > 1 else None
- func_data = sys.argv[2] if len(sys.argv) > 2 else None
- else:
- func_file = os.path.basename(func_file)
- func_data = sys.argv[1] if len(sys.argv) > 1 else None
-
- if not func_file.endswith(".py"):
- func_file += ".py"
-
- 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"../py/{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)
- spec.loader.exec_module(module)
- return module
- else:
- print(f"Invalid function: {func_file}")
- sys.exit(1)
-
-func_file, func_data = parse_argv()
-
-if os.getenv("LLM_FUNCTION_ACTION") == "declarate":
- module = load_func(func_file)
- print(json.dumps(module.declarate(), indent=2))
-else:
- if not func_data:
- print("No json data")
- sys.exit(1)
-
- args = None
- try:
- args = json.loads(func_data)
- except (json.JSONDecodeError, TypeError):
- print("Invalid json data")
- sys.exit(1)
-
- module = load_func(func_file)
- module.execute(args) \ No newline at end of file