diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Argcfile.sh | 54 | ||||
| -rw-r--r-- | README.md | 22 |
3 files changed, 63 insertions, 16 deletions
@@ -1,4 +1,5 @@ /tmp /functions.txt /functions.json -/.env
\ No newline at end of file +/.env +*.cmd
\ No newline at end of file diff --git a/Argcfile.sh b/Argcfile.sh index e3c4d9c..21a35c7 100644 --- a/Argcfile.sh +++ b/Argcfile.sh @@ -11,11 +11,21 @@ call() { "./bin/$argc_func" "${argc_args[@]}" } +# @cmd Build all artifacts +build() { + if [[ -f functions.txt ]]; then + argc build-declarations-json + fi + if [[ "$OS" = "Windows_NT" ]]; then + argc build-win-shims + fi +} + # @cmd Build declarations for specific functions # @option --output=functions.json <FILE> Specify a file path to save the function declarations # @option --names-file=functions.txt Specify a file containing function names # @arg funcs*[`_choice_func`] The function names -build-declarations() { +build-declarations-json() { if [[ "${#argc_funcs[@]}" -gt 0 ]]; then names=("${argc_funcs[@]}" ) elif [[ -f "$argc_names_file" ]]; then @@ -29,9 +39,10 @@ build-declarations() { result+=("$(build-func-declaration "$name")") done echo "["$(IFS=,; echo "${result[*]}")"]" | jq '.' > "$argc_output" + echo "Build $argc_output" } -# @cmd +# @cmd Build declaration for a single function # @arg func![`_choice_func`] The function name build-func-declaration() { argc --argc-export bin/$1 | \ @@ -77,8 +88,45 @@ build-func-declaration() { }' } +# @cmd Build shims for the functions +# Because Windows OS can't run bash scripts directly, we need to make a shim for each function +# +# @flag --clear Clear the shims +build-win-shims() { + funcs=($(_choice_func)) + for func in "${funcs[@]}"; do + echo "Shim bin/${func}.cmd" + _win_shim > "bin/${func}.cmd" + done +} + +# @cmd Install this repo to aichat functions_dir +install() { + functions_dir="$(aichat --info | grep functions_dir | awk '{print $2}')" + if [[ ! -e "$functions_dir" ]]; then + ln -s "$(pwd)" "$functions_dir" + echo "$functions_dir symlinked" + else + echo "$functions_dir already exists" + fi +} + + +_win_shim() { + cat <<-'EOF' +@echo off +setlocal + +set "script_dir=%~dp0" +set "script_name=%~n0" +for /f "delims=" %%a in ('argc --argc-shell-path') do set "_bash_prog=%%a" + +"%_bash_prog%" --noprofile --norc "%script_dir%\%script_name%" %* +EOF +} + _choice_func() { - ls -1 bin + ls -1 bin | grep -v '\.cmd' } _choice_func_args() { @@ -1,4 +1,4 @@ -# LLM Functions: Extend LLM with functions written in Bash. +# LLM Functions This project allows you to enhance large language models (LLMs) with custom functions written in Bash. Imagine your LLM being able to execute system commands, access web APIs, or perform other complex tasks – all triggered by simple, natural language prompts. @@ -31,15 +31,17 @@ Replace `<function_names>...` with the actual names of your functions. Go to the > 💡 You can also create a `./functions.txt` file with each function name on a new line, Once done, simply run `argc build-declarations` without specifying the function names to automatically use the ones listed in. -**3. Configure your aichat application:** +**3. Configure your AIChat:** Symlink this repo directory to aichat **functions_dir**: ```sh ln -s "$(pwd)" "$(aichat --info | grep functions_dir | awk '{print $2}')" +# OR +argc install ``` -Then, add the following settings to your AIChat configuration file: +Don't forget to add the following config to your AIChat `config.yaml` file: ```yaml function_calling: true @@ -49,21 +51,17 @@ AIChat will automatically load `functions.json` and execute functions located in **4. Start using your functions:** -Now you can interact with your LLM using natural language prompts that trigger your defined functions. For example: +Now you can interact with your LLM using natural language prompts that trigger your defined functions. + + -``` -$ aichat -r "%function%" What's the weather in London? -Call Function: get_current_weather --location=London -London: ☀️ 🌡️+18°C 🌬️↑4.7m/s -``` ## Writing Your Own Functions -Create a new Bash script in the `./bin` directory with the name of your function (e.g., `get-current-weather`). Use the following structure within the script: +Create a new Bash script in the `./bin` directory with the name of your function (e.g., `get_current_weather`) Follow the structure demonstrated in existing examples. For instance: ```sh # @describe Get the current weather in a given location. -# @env TOMORROW_API_KEY! The tomorrow.io api key # @option --location! The city and state, e.g. San Francisco, CA main() { @@ -73,8 +71,8 @@ main() { eval "$(argc --argc-eval "$0" "$@")" ``` -After creating your function, don't forget to rebuild the function declarations (step 2) to include it in your LLM's capabilities. +**After creating your function, don't forget to rebuild the function declarations.** ## License |
