diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/demo_js.js | 15 | ||||
| -rw-r--r-- | tools/demo_py.py | 20 | ||||
| -rwxr-xr-x | tools/demo_sh.sh | 18 | ||||
| -rwxr-xr-x | tools/execute_command.sh | 13 | ||||
| -rw-r--r-- | tools/execute_js_code.js | 2 | ||||
| -rw-r--r-- | tools/execute_py_code.py | 2 | ||||
| -rwxr-xr-x | tools/fs_cat.sh | 2 | ||||
| -rwxr-xr-x | tools/fs_ls.sh | 2 | ||||
| -rwxr-xr-x | tools/fs_mkdir.sh | 2 | ||||
| -rwxr-xr-x | tools/fs_rm.sh | 2 | ||||
| -rwxr-xr-x | tools/fs_write.sh | 2 | ||||
| -rwxr-xr-x | tools/get_current_time.sh | 3 | ||||
| -rwxr-xr-x | tools/get_current_weather.sh | 3 | ||||
| -rwxr-xr-x | tools/get_web_page.sh | 3 | ||||
| -rwxr-xr-x | tools/search_arxiv.sh | 2 | ||||
| -rwxr-xr-x | tools/search_bing.sh | 4 | ||||
| -rwxr-xr-x | tools/search_brave.sh | 4 | ||||
| -rwxr-xr-x | tools/search_duckduckgo.sh | 2 | ||||
| -rwxr-xr-x | tools/search_exa.sh | 5 | ||||
| -rwxr-xr-x | tools/search_google.sh | 4 | ||||
| -rwxr-xr-x | tools/search_searxng.sh | 4 | ||||
| -rwxr-xr-x | tools/search_tavily.sh | 4 | ||||
| -rwxr-xr-x | tools/search_wikipedia.sh | 2 | ||||
| -rwxr-xr-x | tools/search_wolframalpha.sh | 3 | ||||
| -rwxr-xr-x | tools/send_mail.sh | 2 |
25 files changed, 79 insertions, 46 deletions
diff --git a/tools/demo_js.js b/tools/demo_js.js index c8b7237..5693d0e 100644 --- a/tools/demo_js.js +++ b/tools/demo_js.js @@ -12,13 +12,18 @@ * @param {Args} args */ exports.run = function run(args) { - for (const [key, value] of Object.entries(args)) { - console.log(`${key}: ${JSON.stringify(value)}`); - } - + let output = `string: ${args.string} +string_enum: ${args.string_enum} +string_optional: ${args.string_optional} +boolean: ${args.boolean} +integer: ${args.integer} +number: ${args.number} +array: ${args.array} +array_optional: ${args.array_optional}`; for (const [key, value] of Object.entries(process.env)) { if (key.startsWith("LLM_")) { - console.log(`${key}: ${value}`); + output = `${output}\n${key}: ${value}`; } } + return output; } diff --git a/tools/demo_py.py b/tools/demo_py.py index d53cd0b..dd0bb1d 100644 --- a/tools/demo_py.py +++ b/tools/demo_py.py @@ -2,29 +2,37 @@ import os from typing import List, Literal, Optional def run( - boolean: bool, string: str, string_enum: Literal["foo", "bar"], + boolean: bool, integer: int, number: float, array: List[str], string_optional: Optional[str] = None, array_optional: Optional[List[str]] = None, -) -> None: +): """Demonstrate how to create a tool using Python and how to use comments. Args: - boolean: Define a required boolean property string: Define a required string property string_enum: Define a required string property with enum + boolean: Define a required boolean property integer: Define a required integer property number: Define a required number property array: Define a required string array property string_optional: Define a optional string property array_optional: Define a optional string array property """ - for key, value in locals().items(): - print(f"{key}: {value}") + output = f"""string: {string} +string_enum: {string_enum} +string_optional: {string_optional} +boolean: {boolean} +integer: {integer} +number: {number} +array: {array} +array_optional: {array_optional}""" for key, value in os.environ.items(): if key.startswith("LLM_"): - print(f"{key}: {value}")
\ No newline at end of file + output = f"{output}\n{key}: {value}" + + return output diff --git a/tools/demo_sh.sh b/tools/demo_sh.sh index da35e8f..11dc72b 100755 --- a/tools/demo_sh.sh +++ b/tools/demo_sh.sh @@ -1,3 +1,6 @@ +#!/usr/bin/env bash +set -e + # @describe Demonstrate how to create a tool using Bash and how to use comment tags. # @option --string! Define a required string property # @option --string-enum![foo|bar] Define a required string property with enum @@ -9,8 +12,17 @@ # @option --array-optional* Define a optional string array property main() { - ( set -o posix ; set ) | grep ^argc_ - printenv | grep '^LLM_' + cat <<EOF >> "$LLM_OUTPUT" +string: ${argc_string} +string_enum: ${argc_string_enum} +string_optional: ${argc_string_optional} +boolean: ${argc_boolean} +integer: ${argc_integer} +number: ${argc_number} +array: ${argc_array[@]} +array_optional: ${argc_array_optional[@]} +$(printenv | grep '^LLM_') +EOF } -eval "$(argc --argc-eval "$0" "$@")"
\ No newline at end of file +eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/execute_command.sh b/tools/execute_command.sh index 6acc021..0e04b85 100755 --- a/tools/execute_command.sh +++ b/tools/execute_command.sh @@ -1,11 +1,18 @@ #!/usr/bin/env bash set -e -# @describe Runs a shell command. +# @describe Runs the shell command. # @option --command! The command to execute. main() { - eval "$argc_command" + if [ -t 1 ]; then + read -r -p "Are you sure you want to continue? [Y/n] " ans + if [[ "$ans" == "N" || "$ans" == "n" ]]; then + echo "Aborted!" + exit 1 + fi + fi + eval "$argc_command" >> "$LLM_OUTPUT" } -eval "$(argc --argc-eval "$0" "$@")"
\ No newline at end of file +eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/execute_js_code.js b/tools/execute_js_code.js index 4706e07..bef6454 100644 --- a/tools/execute_js_code.js +++ b/tools/execute_js_code.js @@ -5,5 +5,5 @@ * @param {Args} args */ exports.run = function run({ code }) { - eval(code); + return eval(code); } diff --git a/tools/execute_py_code.py b/tools/execute_py_code.py index 5f6af2f..b4bf7b1 100644 --- a/tools/execute_py_code.py +++ b/tools/execute_py_code.py @@ -3,4 +3,4 @@ def run(code: str): Args: code: Python code to execute, such as `print("hello world")` """ - exec(code) + return exec(code) diff --git a/tools/fs_cat.sh b/tools/fs_cat.sh index e8b3722..bec9a12 100755 --- a/tools/fs_cat.sh +++ b/tools/fs_cat.sh @@ -9,7 +9,7 @@ set -e main() { path="$FS_BASE_DIR/$argc_path" - cat "$path" + cat "$path" >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/fs_ls.sh b/tools/fs_ls.sh index 876765a..f288f77 100755 --- a/tools/fs_ls.sh +++ b/tools/fs_ls.sh @@ -8,7 +8,7 @@ set -e main() { path="$FS_BASE_DIR/$argc_path" - ls -1 "$path" + ls -1 "$path" >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/fs_mkdir.sh b/tools/fs_mkdir.sh index 7a7e71f..79d853a 100755 --- a/tools/fs_mkdir.sh +++ b/tools/fs_mkdir.sh @@ -9,7 +9,7 @@ set -e main() { path="$FS_BASE_DIR/$argc_path" mkdir -p "$path" - echo "Directory created: $path" + echo "Directory created: $path" >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/fs_rm.sh b/tools/fs_rm.sh index 3d84fe8..1d40295 100755 --- a/tools/fs_rm.sh +++ b/tools/fs_rm.sh @@ -9,7 +9,7 @@ set -e main() { path="$FS_BASE_DIR/$argc_path" rm -rf "$path" - echo "Path removed: $path" + echo "Path removed: $path" >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/fs_write.sh b/tools/fs_write.sh index bc97c34..7718b8d 100755 --- a/tools/fs_write.sh +++ b/tools/fs_write.sh @@ -14,7 +14,7 @@ main() { path="$FS_BASE_DIR/$argc_path" mkdir -p "$(dirname "$path")" printf "%s" "$argc_contents" > "$path" - echo "The contents written to: $path" + echo "The contents written to: $path" >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/get_current_time.sh b/tools/get_current_time.sh index 26a25d8..70752eb 100755 --- a/tools/get_current_time.sh +++ b/tools/get_current_time.sh @@ -4,8 +4,7 @@ set -e # @describe Get the current time. main() { - date + date >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" - diff --git a/tools/get_current_weather.sh b/tools/get_current_weather.sh index 47102e0..ab3e613 100755 --- a/tools/get_current_weather.sh +++ b/tools/get_current_weather.sh @@ -5,7 +5,8 @@ set -e # @option --location! The city and optionally the state or country, e.g., "London", "San Francisco, CA". main() { - curl -fsSL "https://wttr.in/$(echo "$argc_location" | sed 's/ /+/g')?format=4&M" + curl -fsSL "https://wttr.in/$(echo "$argc_location" | sed 's/ /+/g')?format=4&M" \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/get_web_page.sh b/tools/get_web_page.sh index 119dff7..7a516bb 100755 --- a/tools/get_web_page.sh +++ b/tools/get_web_page.sh @@ -9,7 +9,8 @@ main() { # span and div tags are dropped from the HTML https://pandoc.org/MANUAL.html#raw-htmltex and sed removes any inline SVG images in image tags from the Markdown content. curl -fsSL "$argc_url" | \ pandoc -f html-native_divs-native_spans -t gfm-raw_html | \ - sed -E 's/!\[.*?\]\((data:image\/svg\+xml[^)]+)\)//g' + sed -E 's/!\[.*?\]\((data:image\/svg\+xml[^)]+)\)//g' \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/search_arxiv.sh b/tools/search_arxiv.sh index 7372c4d..6ffa8cf 100755 --- a/tools/search_arxiv.sh +++ b/tools/search_arxiv.sh @@ -9,7 +9,7 @@ set -e main() { encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')" url="http://export.arxiv.org/api/query?search_query=all:$encoded_query&max_results=$ARXIV_MAX_RESULTS" - curl -fsSL "$url" + curl -fsSL "$url" >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/search_bing.sh b/tools/search_bing.sh index 28a47dd..4ab1117 100755 --- a/tools/search_bing.sh +++ b/tools/search_bing.sh @@ -13,8 +13,8 @@ main() { url="https://api.bing.microsoft.com/v7.0/search?q=$encoded_query&mkt=en-us&textdecorations=true&textformat=raw&count=$BING_MAX_RESULTS&offset=0" curl -fsSL "$url" \ -H "Ocp-Apim-Subscription-Key: $BING_API_KEY" | \ - jq '[.webPages.value[] | {name: .name, url: .url, snippet: .snippet}]' + jq '[.webPages.value[] | {name: .name, url: .url, snippet: .snippet}]' \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" - diff --git a/tools/search_brave.sh b/tools/search_brave.sh index 553bfc7..9886944 100755 --- a/tools/search_brave.sh +++ b/tools/search_brave.sh @@ -14,8 +14,8 @@ main() { curl -fsSL "$url" \ -H "Accept: application/json" \ -H "X-Subscription-Token: $BRAVE_API_KEY" | \ - jq '[.web.results[] | {title: .title, url: .url, description: .description}]' + jq '[.web.results[] | {title: .title, url: .url, description: .description}]' \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" - diff --git a/tools/search_duckduckgo.sh b/tools/search_duckduckgo.sh index a04b1b0..ad57b50 100755 --- a/tools/search_duckduckgo.sh +++ b/tools/search_duckduckgo.sh @@ -9,7 +9,7 @@ set -e # @option --query! The query to search for. main() { - ddgr -n $DDG_MAX_RESULTS --json "$argc_query" + ddgr -n $DDG_MAX_RESULTS --json "$argc_query" >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/search_exa.sh b/tools/search_exa.sh index 33d4564..ccb14cf 100755 --- a/tools/search_exa.sh +++ b/tools/search_exa.sh @@ -23,9 +23,8 @@ main() { } } }' | \ - jq '[.results[] | {title: .title, url: .url, text: .text}]' + jq '[.results[] | {title: .title, url: .url, text: .text}]' \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" - - diff --git a/tools/search_google.sh b/tools/search_google.sh index 5d3e1f0..94a6789 100755 --- a/tools/search_google.sh +++ b/tools/search_google.sh @@ -13,8 +13,8 @@ main() { encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')" url="https://www.googleapis.com/customsearch/v1?key=$GOOGLE_API_KEY&cx=$GOOGLE_CSE_ID&q=$encoded_query" curl -fsSL "$url" | \ - jq '[.items[:'"$GOOGLE_MAX_RESULTS"'] | .[] | {title: .title, link: .link, snippet: .snippet}]' + jq '[.items[:'"$GOOGLE_MAX_RESULTS"'] | .[] | {title: .title, link: .link, snippet: .snippet}]' \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" - diff --git a/tools/search_searxng.sh b/tools/search_searxng.sh index 34345ca..e171f58 100755 --- a/tools/search_searxng.sh +++ b/tools/search_searxng.sh @@ -12,9 +12,9 @@ main() { encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')" url="$SEARXNG_API_BASE/search?q=$encoded_query&categories=general&language=en-US&format=json" curl -fsSL "$url" | \ - jq '[.results[:'"$SEARXNG_MAX_RESULTS"'] | .[] | {url: .url, title: .title, content: .content}]' + jq '[.results[:'"$SEARXNG_MAX_RESULTS"'] | .[] | {url: .url, title: .title, content: .content}]' \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" - diff --git a/tools/search_tavily.sh b/tools/search_tavily.sh index 5e99aba..13a8520 100755 --- a/tools/search_tavily.sh +++ b/tools/search_tavily.sh @@ -18,8 +18,8 @@ main() { "search_depth": "advanced", "max_results": "'"$TAVILY_MAX_RESULTS"'" }' | \ - jq '[.results[] | {title: .title, url: .url, content: .content}]' + jq '[.results[] | {title: .title, url: .url, content: .content}]' \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" - diff --git a/tools/search_wikipedia.sh b/tools/search_wikipedia.sh index 8f055a4..6e08614 100755 --- a/tools/search_wikipedia.sh +++ b/tools/search_wikipedia.sh @@ -20,7 +20,7 @@ main() { echo '{ "link": "https://en.wikipedia.org/wiki/'"$title"'", "summary": "'"$summary"'" -}' +}' >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/search_wolframalpha.sh b/tools/search_wolframalpha.sh index 20488bf..4da189e 100755 --- a/tools/search_wolframalpha.sh +++ b/tools/search_wolframalpha.sh @@ -10,7 +10,8 @@ set -e main() { encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')" url="https://api.wolframalpha.com/v2/query?appid=$WOLFRAM_API_ID&input=$encoded_query&output=json&format=plaintext" - curl -fsSL "$url" | jq '[.queryresult | .pods[] | {title:.title, values:[.subpods[].plaintext | select(. != "")]}]' + curl -fsSL "$url" | jq '[.queryresult | .pods[] | {title:.title, values:[.subpods[].plaintext | select(. != "")]}]' \ + >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/send_mail.sh b/tools/send_mail.sh index 2645552..a09ee98 100755 --- a/tools/send_mail.sh +++ b/tools/send_mail.sh @@ -23,7 +23,7 @@ $argc_body" | \ --mail-from "$EMAIL_SMTP_USER" \ --mail-rcpt "$argc_recipient" \ --upload-file - - echo "Email sent successfully" + echo "Email sent successfully" >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" |
