aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-05-19 22:43:49 +0800
committerGitHub <noreply@github.com>2024-05-19 22:43:49 +0800
commit03c4b6982293c5be31d7eda89b6dcb8c1a7a8059 (patch)
treea2d48d189dcbe242ab69b174c734db4e70d502a2 /README.md
parentbe279dcd322da7f84bb6451f10456b19a979e9ad (diff)
downloadllm-functions-docker-03c4b6982293c5be31d7eda89b6dcb8c1a7a8059.tar.gz
feat: supports functions in bash/js/python/ruby (#6)
Diffstat (limited to 'README.md')
-rw-r--r--README.md149
1 files changed, 118 insertions, 31 deletions
diff --git a/README.md b/README.md
index 93e5ad2..bdd545b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# 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.
+This project allows you to enhance large language models (LLMs) with custom functions written in Bash/Js/Python/Ruby. Imagine your LLM being able to execute system commands, access web APIs, or perform other complex tasks – all triggered by simple, natural language prompts.
## Prerequisites
@@ -18,18 +18,11 @@ Make sure you have the following tools installed:
git clone https://github.com/sigoden/llm-functions
```
-**2. Build function declarations:**
+**2. Build function declarations file and bin dir:**
-Before using the functions, you need to generate a `./functions.json` file that describes the available functions for the LLM.
-
-```sh
-argc build-declarations <function_names>...
-```
-
-Replace `<function_names>...` with the actual names of your functions. Go to the [./bin](https://github.com/sigoden/llm-functions/tree/main/bin) directory for valid function names.
-
-> 💡 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.
+First, create a `./functions.txt` file with each function name on a new line.
+Then, run `argc build` to build function declarations file `./functions.json` and bin dir `./bin/`.
**3. Configure your AIChat:**
@@ -55,22 +48,49 @@ Now you can interact with your LLM using natural language prompts that trigger y
![image](https://github.com/sigoden/llm-functions/assets/4012553/867b7b2a-25fb-4c74-9b66-3701eaabbd1f)
+## Function Types
+
+### Retrieve Type
+
+The function returns JSON data to LLM for further processing.
+
+AIChat does not ask permission to run the function or print the output.
+
+### Execute Type
+
+The function does not return data to LLM. Instead, they enable more complex actions, such as showing a progress bar or running a TUI application.
+
+AIChat will ask permission before running the function.
+
+![image](https://github.com/sigoden/aichat/assets/4012553/711067b8-dd23-443d-840a-5556697ab075)
+
+**AIChat categorizes functions starting with `may_` as `execute type` and all others as `retrieve type`.**
+
## Writing Your Own Functions
-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:
+The project supports write functions in bash/js/python.
+
+### Bash
+
+Create a new bashscript (.e.g. `may_execute_command.sh`) in the [./sh](./sh/) directory.
```sh
-# @describe Get the current weather in a given location.
-# @option --location! The city and state, e.g. San Francisco, CA
+#!/usr/bin/env bash
+set -e
+
+# @describe Executes a shell command.
+# @option --command~ Command to execute, such as `ls -la`
main() {
- curl "https://wttr.in/$(echo "$argc_location" | sed 's/ /+/g')?format=4&M"
+ eval $argc_shell_command
}
eval "$(argc --argc-eval "$0" "$@")"
```
-The relationship between flags/options and parameters in function declarations is as follows:
+`llm-functions` will automatic generate function declaration.json from [comment tags](https://github.com/sigoden/argc?tab=readme-ov-file#comment-tags).
+
+The relationship between comment tags and parameters in function declarations is as follows:
```sh
# @flag --boolean Parameter `{"type": "boolean"}`
@@ -83,25 +103,92 @@ The relationship between flags/options and parameters in function declarations i
# @option --array-required+ Use `+` to mark a array parameter as required
```
-**After creating your function, don't forget to rebuild the function declarations.**
-
-## Function Types
-
-### Retrieve Type
-
-The function returns JSON data to LLM for further processing.
-
-AIChat does not ask permission to run the function or print the output.
-
-### Execute Type
+### Javascript
+
+Create a new javascript (.e.g. `may_execute_command.js`) in the [./js](./js/) directory.
+
+```js
+exports.declarate = function declarate() {
+ return {
+ "name": "may_execute_js_code",
+ "description": "Runs the javascript code in node.js.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "string",
+ "description": "Javascript code to execute, such as `console.log(\"hello world\")`"
+ }
+ },
+ "required": [
+ "code"
+ ]
+ }
+ }
+}
-The function does not return data to LLM. Instead, they enable more complex actions, such as showing a progress bar or running a TUI application.
+exports.execute = function execute(data) {
+ eval(data.code)
+}
-AIChat will ask permission before running the function.
+```
-![image](https://github.com/sigoden/aichat/assets/4012553/711067b8-dd23-443d-840a-5556697ab075)
+### Python
+
+Create a new python script in the [./py](./py/) directory (e.g., `may_execute_py_code.py`).
+
+```py
+def declarate():
+ return {
+ "name": "may_execute_py_code",
+ "description": "Runs the python code.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "string",
+ "description": "python code to execute, such as `print(\"hello world\")`"
+ }
+ },
+ "required": [
+ "code"
+ ]
+ }
+ }
+
+
+def execute(data):
+ exec(data["code"])
+```
-**AIChat categorizes functions starting with `may_` as `execute type` and all others as `retrieve type`.**
+### Ruby
+
+Create a new ruby script in the [./rb](./rb/) directory (e.g., `may_execute_rb_code.rb`).
+
+```rb
+def declarate
+ {
+ "name": "may_execute_rb_code",
+ "description": "Runs the ruby code.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "string",
+ "description": "Ruby code to execute, such as `puts \"hello world\"`"
+ }
+ },
+ "required": [
+ "code"
+ ]
+ }
+ }
+end
+
+def execute(data)
+ eval(data["code"])
+end
+```
## License