$git clone https://github.com/sigoden/llm-functionsThis project empowers you to effortlessly build powerful LLM tools and agents using familiar languages like Bash, JavaScript, and Python.
| 1 | # LLM Functions |
| 2 | |
| 3 | This project empowers you to effortlessly build powerful LLM tools and agents using familiar languages like Bash, JavaScript, and Python. |
| 4 | |
| 5 | Forget complex integrations, **harness the power of [function calling](https://platform.openai.com/docs/guides/function-calling)** to connect your LLMs directly to custom code and unlock a world of possibilities. Execute system commands, process data, interact with APIs – the only limit is your imagination. |
| 6 | |
| 7 | **Tools Showcase** |
| 8 |  |
| 9 | |
| 10 | **Agents showcase** |
| 11 |  |
| 12 | |
| 13 | ## Prerequisites |
| 14 | |
| 15 | Make sure you have the following tools installed: |
| 16 | |
| 17 | - [argc](https://github.com/sigoden/argc): A bash command-line framework and command runner |
| 18 | - [jq](https://github.com/jqlang/jq): A JSON processor |
| 19 | |
| 20 | ## Getting Started with [AIChat](https://github.com/sigoden/aichat) |
| 21 | |
| 22 | **Currently, AIChat is the only CLI tool that supports `llm-functions`. We look forward to more tools supporting `llm-functions`.** |
| 23 | |
| 24 | ### 1. Clone the repository |
| 25 | |
| 26 | ```sh |
| 27 | git clone https://github.com/sigoden/llm-functions |
| 28 | cd llm-functions |
| 29 | ``` |
| 30 | |
| 31 | ### 2. Build tools and agents |
| 32 | |
| 33 | #### I. Create a `./tools.txt` file with each tool filename on a new line. |
| 34 | |
| 35 | ``` |
| 36 | get_current_weather.sh |
| 37 | execute_command.sh |
| 38 | #execute_py_code.py |
| 39 | ``` |
| 40 | |
| 41 | <details> |
| 42 | <summary>Where is the web_search tool?</summary> |
| 43 | <br> |
| 44 | |
| 45 | The `web_search` tool itself doesn't exist directly, Instead, you can choose from a variety of web search tools. |
| 46 | |
| 47 | To use one as the `web_search` tool, follow these steps: |
| 48 | |
| 49 | 1. **Choose a Tool:** Available tools include: |
| 50 | * `web_search_cohere.sh` |
| 51 | * `web_search_perplexity.sh` |
| 52 | * `web_search_tavily.sh` |
| 53 | * `web_search_vertexai.sh` |
| 54 | |
| 55 | 2. **Link Your Choice:** Use the `argc` command to link your chosen tool as `web_search`. For example, to use `web_search_perplexity.sh`: |
| 56 | |
| 57 | ```sh |
| 58 | $ argc link-web-search web_search_perplexity.sh |
| 59 | ``` |
| 60 | |
| 61 | This command creates a symbolic link, making `web_search.sh` point to your selected `web_search_perplexity.sh` tool. |
| 62 | |
| 63 | Now there is a `web_search.sh` ready to be added to your `./tools.txt`. |
| 64 | |
| 65 | </details> |
| 66 | |
| 67 | #### II. Create a `./agents.txt` file with each agent name on a new line. |
| 68 | |
| 69 | ``` |
| 70 | coder |
| 71 | todo |
| 72 | ``` |
| 73 | |
| 74 | #### III. Build `bin` and `functions.json` |
| 75 | |
| 76 | ```sh |
| 77 | argc build |
| 78 | ``` |
| 79 | |
| 80 | #### IV. Ensure that everything is ready (environment variables, Node/Python dependencies, mcp-bridge server) |
| 81 | |
| 82 | ```sh |
| 83 | argc check |
| 84 | ``` |
| 85 | |
| 86 | ### 3. Link LLM-functions and AIChat |
| 87 | |
| 88 | AIChat expects LLM-functions to be placed in AIChat's **functions_dir** so that AIChat can use the tools and agents that LLM-functions provides. |
| 89 | |
| 90 | You can symlink this repository directory to AIChat's **functions_dir** with: |
| 91 | |
| 92 | ```sh |
| 93 | ln -s "$(pwd)" "$(aichat --info | sed -n 's/^functions_dir\s\+//p')" |
| 94 | # OR |
| 95 | argc link-to-aichat |
| 96 | ``` |
| 97 | |
| 98 | Alternatively, you can tell AIChat where the LLM-functions directory is by using an environment variable: |
| 99 | |
| 100 | ```sh |
| 101 | export AICHAT_FUNCTIONS_DIR="$(pwd)" |
| 102 | ``` |
| 103 | |
| 104 | ### 4. Start using the functions |
| 105 | |
| 106 | Done! Now you can use the tools and agents with AIChat. |
| 107 | |
| 108 | ```sh |
| 109 | aichat --role %functions% what is the weather in Paris? |
| 110 | aichat --agent todo list all my todos |
| 111 | ``` |
| 112 | |
| 113 | ## Writing Your Own Tools |
| 114 | |
| 115 | Building tools for our platform is remarkably straightforward. You can leverage your existing programming knowledge, as tools are essentially just functions written in your preferred language. |
| 116 | |
| 117 | LLM Functions automatically generates the JSON declarations for the tools based on **comments**. Refer to `./tools/demo_tool.{sh,js,py}` for examples of how to use comments for autogeneration of declarations. |
| 118 | |
| 119 | ### Bash |
| 120 | |
| 121 | Create a new bashscript in the [./tools/](./tools/) directory (.e.g. `execute_command.sh`). |
| 122 | |
| 123 | ```sh |
| 124 | #!/usr/bin/env bash |
| 125 | set -e |
| 126 | |
| 127 | # @describe Execute the shell command. |
| 128 | # @option --command! The command to execute. |
| 129 | |
| 130 | main() { |
| 131 | eval "$argc_command" >> "$LLM_OUTPUT" |
| 132 | } |
| 133 | |
| 134 | eval "$(argc --argc-eval "$0" "$@") |