feat: adjust the way of returning data to LLM (#69)
This commit is contained in:
+10
-5
@@ -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;
|
||||
}
|
||||
|
||||
+14
-6
@@ -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}")
|
||||
output = f"{output}\n{key}: {value}"
|
||||
|
||||
return output
|
||||
|
||||
+15
-3
@@ -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" "$@")"
|
||||
eval "$(argc --argc-eval "$0" "$@")"
|
||||
|
||||
@@ -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" "$@")"
|
||||
eval "$(argc --argc-eval "$0" "$@")"
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
* @param {Args} args
|
||||
*/
|
||||
exports.run = function run({ code }) {
|
||||
eval(code);
|
||||
return eval(code);
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ def run(code: str):
|
||||
Args:
|
||||
code: Python code to execute, such as `print("hello world")`
|
||||
"""
|
||||
exec(code)
|
||||
return exec(code)
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ set -e
|
||||
|
||||
main() {
|
||||
path="$FS_BASE_DIR/$argc_path"
|
||||
cat "$path"
|
||||
cat "$path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
eval "$(argc --argc-eval "$0" "$@")"
|
||||
|
||||
+1
-1
@@ -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" "$@")"
|
||||
|
||||
+1
-1
@@ -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" "$@")"
|
||||
|
||||
+1
-1
@@ -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" "$@")"
|
||||
|
||||
+1
-1
@@ -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" "$@")"
|
||||
|
||||
@@ -4,8 +4,7 @@ set -e
|
||||
# @describe Get the current time.
|
||||
|
||||
main() {
|
||||
date
|
||||
date >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
eval "$(argc --argc-eval "$0" "$@")"
|
||||
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
+2
-3
@@ -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" "$@")"
|
||||
|
||||
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ main() {
|
||||
echo '{
|
||||
"link": "https://en.wikipedia.org/wiki/'"$title"'",
|
||||
"summary": "'"$summary"'"
|
||||
}'
|
||||
}' >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
eval "$(argc --argc-eval "$0" "$@")"
|
||||
|
||||
@@ -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" "$@")"
|
||||
|
||||
+1
-1
@@ -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" "$@")"
|
||||
|
||||
Reference in New Issue
Block a user