From 213e949fc8c2362046d197554fda98c87a7906df Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 8 Jun 2024 20:46:27 +0800 Subject: feat: support bots (#39) --- bots/todo-sh/index.yaml | 19 +++++++++++++ bots/todo-sh/tools.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 bots/todo-sh/index.yaml create mode 100755 bots/todo-sh/tools.sh (limited to 'bots/todo-sh') diff --git a/bots/todo-sh/index.yaml b/bots/todo-sh/index.yaml new file mode 100644 index 0000000..0988e01 --- /dev/null +++ b/bots/todo-sh/index.yaml @@ -0,0 +1,19 @@ +name: Todo List +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. + Users can interact with you using the following commands: + * add_todo: Add a todo to the list. + * rm_todo: Remove a todo from the list. + * list_todos: Display the current todo list. + * clear_todos: Delete the entire todo list. + Based on the interaction, ensure that you provide appropriate confirmations or errors for the requested operation. For example: + - Confirmations: "Todo item added successfully!", "Todo item removed successfully!", "All todo items deleted!" + - Errors: "Cannot add todo item, missing description.", "Todo item with id {id} not found.", "No todo items to delete." + Make sure you understand the user request properly before performing any action. If unsure, ask clarifying questions like "Do you want to remove all todos or just a specific one?" +conversation_starters: + - "Add a new todo item 'Finish report'." + - "Remove the todo item with id=2." + - "Delete all my todos." + - "What todos do I have pending?" + - "How can I remove a specific todo item?" \ No newline at end of file diff --git a/bots/todo-sh/tools.sh b/bots/todo-sh/tools.sh new file mode 100755 index 0000000..1b1758a --- /dev/null +++ b/bots/todo-sh/tools.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +set -e + +# @cmd Add a new todo item +# @option --desc! The task description +add_todo() { + todos_file="$(_get_todos_file)" + if [[ -f "$todos_file" ]]; then + num="$(cat "$todos_file" | jq '[.[].id] | max + 1')" + data="$(cat "$todos_file")" + else + num=1 + data="[]" + fi + echo "$data" | \ + jq --arg new_id $num \ + --arg new_desc "$argc_desc" \ + '. += [{"id": $new_id | tonumber, "desc": $new_desc}]' \ + > "$todos_file" + echo "Successfully added todo id=$num" +} + +# @cmd Delete an existing todo item +# @option --id! The task id +del_todo() { + todos_file="$(_get_todos_file)" + if [[ -f "$todos_file" ]]; then + data="$(cat "$todos_file")" + echo "$data" | \ + jq --arg id $argc_id '[.[] | select(.id != ($id | tonumber))]' \ + > "$todos_file" + echo "Successfully deleted todo id=$argc_id" + else + _die "Empty todo list" + fi +} + +# @cmd Display the current todo list in json format. +list_todos() { + todos_file="$(_get_todos_file)" + if [[ -f "$todos_file" ]]; then + cat "$todos_file" + else + _die "Empty todo list" + fi +} + +# @cmd Delete the entire todo list. +clear_todos() { + todos_file="$(_get_todos_file)" + if [[ -f "$todos_file" ]]; then + rm -rf "$todos_file" + fi + echo "Successfully deleted entry todo list" +} + +_argc_before() { + todos_file="$(_get_todos_file)" + mkdir -p "$(dirname "$todos_file")" +} + +_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" "$@")" -- cgit v1.2.3