diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-07 15:16:31 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-07 15:16:31 +0800 |
| commit | 739a832d87c00e3b5977a24bba5654fa5ea7a702 (patch) | |
| tree | 2bb4c102a3e04b9c8c1ecd61bdb6c92f84ca27cb /scripts/run-tool.sh | |
| parent | 2b07fc2c7e4e6311d35ae72c17b25e47680d61f6 (diff) | |
| download | llm-functions-docker-739a832d87c00e3b5977a24bba5654fa5ea7a702.tar.gz | |
feat: js/py generate declarations from comments (#30)
Diffstat (limited to 'scripts/run-tool.sh')
| -rwxr-xr-x | scripts/run-tool.sh | 98 |
1 files changed, 27 insertions, 71 deletions
diff --git a/scripts/run-tool.sh b/scripts/run-tool.sh index 6f5befc..bd32a49 100755 --- a/scripts/run-tool.sh +++ b/scripts/run-tool.sh @@ -27,76 +27,32 @@ if [[ "$OS" == "Windows_NT" ]]; then func_file="$(cygpath -w "$func_file")" fi -if [[ "$LLM_FUNCTION_ACTION" == "declarate" ]]; then - argc --argc-export "$func_file" | \ - $JQ -r ' - def parse_description(flag_option): - if flag_option.describe == "" then - {} - else - { "description": flag_option.describe } - end; - - def parse_enum(flag_option): - if flag_option.choice.type == "Values" then - { "enum": flag_option.choice.data } - else - {} - end; - - def parse_property(flag_option): - [ - { condition: (flag_option.flag == true), result: { type: "boolean" } }, - { condition: (flag_option.multiple_occurs == true), result: { type: "array", items: { type: "string" } } }, - { condition: (flag_option.notations[0] == "INT"), result: { type: "integer" } }, - { condition: (flag_option.notations[0] == "NUM"), result: { type: "number" } }, - { condition: true, result: { type: "string" } } ] - | map(select(.condition) | .result) | first - | (. + parse_description(flag_option)) - | (. + parse_enum(flag_option)) - ; - - - def parse_parameter(flag_options): - { - type: "object", - properties: (reduce flag_options[] as $item ({}; . + { ($item.id | sub("-"; "_"; "g")): parse_property($item) })), - required: [flag_options[] | select(.required == true) | .id], - }; +if [[ -z "$func_data" ]]; then + echo "No json data" + exit 1 +fi - { - name: (.name | sub("-"; "_"; "g")), - description: .describe, - parameters: parse_parameter([.flag_options[] | select(.id != "help" and .id != "version")]) - }' -else - if [[ -z "$func_data" ]]; then - echo "No json data" - exit 1 +data="$( + echo "$func_data" | \ + $JQ -r ' + to_entries | .[] | + (.key | split("_") | join("-")) as $key | + if .value | type == "array" then + .value | .[] | "--\($key)\n\(. | @json)" + elif .value | type == "boolean" then + if .value then "--\($key)" else "" end + else + "--\($key)\n\(.value | @json)" + end' +)" || { + echo "Invalid json data" + exit 1 +} +while IFS= read -r line; do + if [[ "$line" == '--'* ]]; then + args+=("$line") + else + args+=("$(echo "$line" | $JQ -r '.')") fi - - data="$( - echo "$func_data" | \ - $JQ -r ' - to_entries | .[] | - (.key | split("_") | join("-")) as $key | - if .value | type == "array" then - .value | .[] | "--\($key)\n\(. | @json)" - elif .value | type == "boolean" then - if .value then "--\($key)" else "" end - else - "--\($key)\n\(.value | @json)" - end' - )" || { - echo "Invalid json data" - exit 1 - } - while IFS= read -r line; do - if [[ "$line" == '--'* ]]; then - args+=("$line") - else - args+=("$(echo "$line" | $JQ -r '.')") - fi - done <<< "$data" - "$func_file" "${args[@]}" -fi
\ No newline at end of file +done <<< "$data" +"$func_file" "${args[@]}"
\ No newline at end of file |
