aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 7abcb8ba6571a2c838962a02540b97db332a8541 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# LLM Functions

This project helps you easily create LLM tools and agents using Bash/JavaScript/Python, and provides a library of commonly used LLM tools and agents.

**Tools Showcase**
![llm-function-tool](https://github.com/user-attachments/assets/40c77413-30ba-4f0f-a2c7-19b042a1b507)

**Agents showcase**
![llm-function-agent](https://github.com/user-attachments/assets/6e380069-8211-4a16-8592-096e909b921d)

## Prerequisites

Make sure you have the following tools installed:

- [argc](https://github.com/sigoden/argc): A bash command-line framewrok and command runner
- [jq](https://github.com/jqlang/jq): A JSON processor

## Getting Started with [AIChat](https://github.com/sigoden/aichat)

**Currently, AIChat is the only CLI tool that supports `llm-functions`. We look forward to more tools supporting `llm-functions`.**

### 1. Clone the repository

```sh
git clone https://github.com/sigoden/llm-functions
```

### 2. Build tools and agents

**I. Create a `./tools.txt` file with each tool filename on a new line.**

```
get_current_weather.sh
execute_command.sh
#execute_py_code.py
``` 

<details>
<summary>Where is the web_search tool?</summary>

The normal `web_search` tool does not exist. Please run `argc link-web-search <web-search-tool>` to link to one of the available `web_search_*` tools.

```
$ argc link-web-search web_search_<tab>
web_search_cohere.sh    web_search_perplexity.sh    web_search_tavily.sh    web_search_vertexai.sh     
```

</details>

**II. Create a `./agents.txt` file with each agent name on a new line.**

```
coder
todo
```

**III. Run `argc build` to build tools and agents.**

### 3. Install to AIChat

Symlink this repo directory to AIChat's **functions_dir**:

```sh
ln -s "$(pwd)" "$(aichat --info | grep -w functions_dir | awk '{print $2}')"
# OR
argc install
```

### 4. Start using the functions

Done! Now you can use the tools and agents with AIChat.

```sh
aichat --role %functions% what is the weather in Paris?
aichat --agent todo list all my todos
```

## Writing Your Own Tools

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.

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.

### Bash

Create a new bashscript in the [./tools/](./tools/) directory (.e.g. `execute_command.sh`).

```sh
#!/usr/bin/env bash
set -e

# @describe Execute the shell command.
# @option --command! The command to execute.

main() {
    eval "$argc_command" >> "$LLM_OUTPUT"
}

eval "$(argc --argc-eval "$0" "$@")"
```

### Javascript

Create a new javascript in the [./tools/](./tools/) directory (.e.g. `execute_js_code.js`).

```js
/**
 * Execute the javascript code in node.js.
 * @typedef {Object} Args
 * @property {string} code - Javascript code to execute, such as `console.log("hello world")`
 * @param {Args} args
 */
exports.main = function main({ code }) {
  return eval(code);
}

```

### Python

Create a new python script in the [./tools/](./tools/) directory (e.g. `execute_py_code.py`).

```py
def main(code: str):
    """Execute the python code.
    Args:
        code: Python code to execute, such as `print("hello world")`
    """
    return exec(code)

```

## Writing Your Own Agents

Agent = Prompt + Tools (Function Callings) + Documents (RAG), which is equivalent to OpenAI's GPTs.

The agent has the following folder structure:
```
└── agents
    └── myagent
        ├── functions.json                  # JSON declarations for functions (Auto-generated)
        ├── index.yaml                      # Agent definition
        ├── tools.txt                       # Shared tools
        └── tools.{sh,js,py}                # Agent tools 
```

The agent definition file (`index.yaml`) defines crucial aspects of your agent:

```yaml
name: TestAgent                             
description: This is test agent
version: 0.1.0
instructions: You are a test ai agent to ... 
conversation_starters:
  - What can you do?
variables:
  - name: foo
    description: This is a foo
documents:
  - local-file.txt
  - local-dir/
  - https://example.com/remote-file.txt
```

Refer to [./agents/demo](https://github.com/sigoden/llm-functions/tree/main/agents/demo) for examples of how to implement a agent.

## License

The project is under the MIT License, Refer to the [LICENSE](https://github.com/sigoden/llm-functions/blob/main/LICENSE) file for detailed information.