diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-10 19:57:37 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-10 19:57:37 +0800 |
| commit | 7225ee331a82cf1f8d8afab8923c4f35a792e5b8 (patch) | |
| tree | 7166211462ff174b6d9701e80b2200b8f52f3e41 /bots | |
| parent | 8f3385ca9e87f6941914953cabe8ed1e325305cb (diff) | |
| download | llm-functions-docker-7225ee331a82cf1f8d8afab8923c4f35a792e5b8.tar.gz | |
refactor: improve bots/todo-* (#41)
Diffstat (limited to 'bots')
| -rw-r--r-- | bots/todo-js/tools.js | 9 | ||||
| -rw-r--r-- | bots/todo-py/tools.py | 9 | ||||
| -rw-r--r-- | bots/todo-sh/index.yaml | 2 | ||||
| -rwxr-xr-x | bots/todo-sh/tools.sh | 9 |
4 files changed, 8 insertions, 21 deletions
diff --git a/bots/todo-js/tools.js b/bots/todo-js/tools.js index ed3ed39..0c9db49 100644 --- a/bots/todo-js/tools.js +++ b/bots/todo-js/tools.js @@ -34,7 +34,7 @@ exports.del_todo = function delTodo(args) { fs.writeFileSync(todosFile, JSON.stringify(newData)); console.log(`Successfully deleted todo id=${args.id}`); } else { - _die('Empty todo list'); + console.log('Empty todo list'); } } @@ -46,7 +46,7 @@ exports.list_todos = function listTodos() { if (fs.existsSync(todosFile)) { console.log(fs.readFileSync(todosFile, "utf8")); } else { - _die('Empty todo list'); + console.log("[]"); } } @@ -66,8 +66,3 @@ function _getTodosFile() { } return path.join(cacheDir, 'todos.json'); } - -function _die(message) { - console.error(message); - process.exit(1); -}
\ No newline at end of file diff --git a/bots/todo-py/tools.py b/bots/todo-py/tools.py index 29e13ea..a531b51 100644 --- a/bots/todo-py/tools.py +++ b/bots/todo-py/tools.py @@ -32,7 +32,8 @@ def del_todo(id: int): with open(todos_file, "r") as f: data = json.load(f) except (FileNotFoundError, JSONDecodeError): - _die("Empty todo list") + print("Empty todo list") + return data = [item for item in data if item["id"] != id] with open(todos_file, "w") as f: json.dump(data, f) @@ -46,7 +47,7 @@ def list_todos(): with open(todos_file, "r") as f: print(f.read()) except FileNotFoundError: - _die("Empty todo list") + print("[]") def clear_todos(): @@ -59,7 +60,3 @@ def _get_todos_file() -> str: if not os.path.exists(cache_dir): os.makedirs(cache_dir, exist_ok=True) return os.path.join(cache_dir, "todos.json") - -def _die(msg: str): - print(msg, file=sys.stderr) - exit(1)
\ No newline at end of file diff --git a/bots/todo-sh/index.yaml b/bots/todo-sh/index.yaml index 0988e01..a3c8eb1 100644 --- a/bots/todo-sh/index.yaml +++ b/bots/todo-sh/index.yaml @@ -1,4 +1,4 @@ -name: Todo List +name: TodoBot description: Your name is TodoBot and you are a helpful chatbot that manages a todo list. instructions: | You will be provided with a list of todos. diff --git a/bots/todo-sh/tools.sh b/bots/todo-sh/tools.sh index 1b1758a..e387d75 100755 --- a/bots/todo-sh/tools.sh +++ b/bots/todo-sh/tools.sh @@ -31,7 +31,7 @@ del_todo() { > "$todos_file" echo "Successfully deleted todo id=$argc_id" else - _die "Empty todo list" + echo "Empty todo list" fi } @@ -41,7 +41,7 @@ list_todos() { if [[ -f "$todos_file" ]]; then cat "$todos_file" else - _die "Empty todo list" + echo '[]' fi } @@ -63,10 +63,5 @@ _get_todos_file() { echo "${LLM_BOT_CACHE_DIR:-/tmp}/todos.json" } -_die() { - echo "$*" >&2 - exit 1 -} - # See more details at https://github.com/sigoden/argc eval "$(argc --argc-eval "$0" "$@")" |
