From 48cb8381eae03aa45b34fa79f4e0037f6a5c0225 Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 9 Jul 2024 21:28:35 +0800 Subject: feat: remove todo-js/todo-py and rename todo-sh to todo (#68) --- agents/todo-py/tools.py | 62 ------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 agents/todo-py/tools.py (limited to 'agents/todo-py/tools.py') diff --git a/agents/todo-py/tools.py b/agents/todo-py/tools.py deleted file mode 100644 index 0aa5f4b..0000000 --- a/agents/todo-py/tools.py +++ /dev/null @@ -1,62 +0,0 @@ -import json -import sys -import os -from json import JSONDecodeError - - -def add_todo(desc: str): - """Add a new todo item - Args: - desc: The task description - """ - todos_file = _get_todos_file() - try: - with open(todos_file, "r") as f: - data = json.load(f) - except (FileNotFoundError, JSONDecodeError): - data = [] - num = max([item["id"] for item in data] + [0]) + 1 - data.append({"id": num, "desc": desc}) - with open(todos_file, "w") as f: - json.dump(data, f) - print(f"Successfully added todo id={num}") - - -def del_todo(id: int): - """Delete an existing todo item - Args: - id: The task id - """ - todos_file = _get_todos_file() - try: - with open(todos_file, "r") as f: - data = json.load(f) - except (FileNotFoundError, JSONDecodeError): - 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) - print(f"Successfully deleted todo id={id}") - - -def list_todos(): - """Display the current todo list in json format.""" - todos_file = _get_todos_file() - try: - with open(todos_file, "r") as f: - print(f.read()) - except FileNotFoundError: - print("[]") - - -def clear_todos(): - """Delete the entire todo list.""" - os.remove(_get_todos_file()) - - -def _get_todos_file() -> str: - cache_dir=os.environ.get("LLM_AGENT_CACHE_DIR", "/tmp") - if not os.path.exists(cache_dir): - os.makedirs(cache_dir, exist_ok=True) - return os.path.join(cache_dir, "todos.json") -- cgit v1.2.3