Files
llm-functions/README.md
2024-08-09 02:21:03 +00:00

4.3 KiB

LLM Functions

This project helps you easily create LLM tools and agents based on Bash, JavaScript, and Python. Additionally, it offers a comprehensive collection of pre-built tools and agents for your convenience.

Tools Showcase llm-function-tool

Agents showcase llm-function-agent

Prerequisites

Make sure you have the following tools installed:

  • argc: A bash command-line framewrok and command runner
  • jq: A JSON processor

Getting Started with AIChat

1. Clone the repository:

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

Set up the web_search tool

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

image

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 functions_dir:

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

4. Start using the functions:

Done! You can experience the magic of llm-functions in AIChat.

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/ directory (.e.g. execute_command.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/ directory (.e.g. execute_js_code.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/ directory (e.g. execute_py_code.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) + Knowndge (RAG). It's also known as OpenAI's GPTs.

The agent has the following folder structure:

└── agents
    └── myagent
        ├── functions.json                  # Function JSON declarations (Auto-generated)
        ├── index.yaml                      # Agent definition
        ├── tools.txt                       # Shared tools from ./tools
        └── tools.{sh,js,py}                # Agent tools 

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

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 for examples of how to implement a agent.

License

The project is under the MIT License, Refer to the LICENSE file for detailed information.