diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-07 16:10:05 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-07 16:10:05 +0800 |
| commit | e1d895cc9abb0f7ffac8acc043746cbe2e5f4fe1 (patch) | |
| tree | 39e0faa590db7b2b4fdc1e6458a77566252acbd1 /scripts/build-declarations.py | |
| parent | 739a832d87c00e3b5977a24bba5654fa5ea7a702 (diff) | |
| download | llm-functions-docker-e1d895cc9abb0f7ffac8acc043746cbe2e5f4fe1.tar.gz | |
refactor: py/js entry func name (#31)
Diffstat (limited to 'scripts/build-declarations.py')
| -rw-r--r-- | scripts/build-declarations.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/scripts/build-declarations.py b/scripts/build-declarations.py index 17a27b6..2a28e43 100644 --- a/scripts/build-declarations.py +++ b/scripts/build-declarations.py @@ -7,13 +7,14 @@ import re import sys from collections import OrderedDict +TOOL_ENTRY_FUNC = "run" -def main(): +def main(is_tool = True): scriptfile = sys.argv[1] with open(scriptfile, "r", encoding="utf-8") as f: contents = f.read() - functions = extract_functions(contents) + functions = extract_functions(contents, is_tool) declarations = [] for function in functions: func_name, docstring, func_args = function @@ -22,15 +23,16 @@ def main(): build_declaration(func_name, description, params, func_args) ) - name = os.path.splitext(os.path.basename(scriptfile))[0] - if declarations: - declarations = declarations[0:1] - declarations[0]["name"] = name + if is_tool: + name = os.path.splitext(os.path.basename(scriptfile))[0] + if declarations: + declarations = declarations[0:1] + declarations[0]["name"] = name print(json.dumps(declarations, indent=2)) -def extract_functions(contents: str): +def extract_functions(contents: str, is_tool: bool): tree = ast.parse(contents) output = [] for node in ast.walk(tree): @@ -39,6 +41,8 @@ def extract_functions(contents: str): func_name = node.name if func_name.startswith("_"): continue + if is_tool and func_name != TOOL_ENTRY_FUNC: + continue docstring = ast.get_docstring(node) or "" func_args = OrderedDict() for arg in node.args.args: |
