Giter Site home page Giter Site logo

llm-functions's Introduction

LLM Functions

This project allows you to enhance large language models (LLMs) with custom functions written in bash/js/python. 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

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

  • Create a ./tools.txt file with each tool filename on a new line.
get_current_weather.sh
may_execute_py_code.py
  • Create a ./bots.txt file with each bot name on a new line.
todo-sh
hackernews
  • Run argc build to build functions declarations files (functions.json) and binaries (./bin) for tools and bots.

3. Configure your AIChat:

Symlink this repo directory to aichat functions_dir:

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

Don't forget to add the following config to your AIChat config.yaml file:

function_calling: true

AIChat will automatically load functions.json and execute commands located in the ./bin directory based on your prompts.

4. Start using your functions:

Now you can interact with your LLM using natural language prompts that trigger your defined functions.

AIChat Showcases

retrieve-type-showcase

execute-type-showcase

bot-showcase

Writing Your Own Tools

Writing tools is super easy, you only need to write functions with comments.

llm-functions will automatically generate binaries, function declarations, and so on

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. may_execute_command.sh).

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

# @describe Runs a shell command.
# @option --command! The command to execute.

main() {
    eval "$argc_command"
}

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

Javascript

Create a new javascript in the ./tools/ directory (.e.g. may_execute_js_code.js).

/**
 * Runs 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 }) {
  eval(code);
}

Python

Create a new python script in the ./tools/ directory (e.g., may_execute_py_code.py).

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

Writing Bots

Bot = Prompt + Tools (Function Callings) + Knowndge (RAG). It's also known as OpenAI's GPTs.

The bot has the following folder structure:

└── bots
    └── mybot
        ├── embeddings/                     # Contains RAG files for knownledge
        ├── functions.json                  # Function declarations file (Auto-generated)
        ├── index.yaml                      # Bot definition file
        └── tools.{sh,js,py}                # Bot tools script

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

name: TestBot                             
description: This is test bot
version: v0.1.0
instructions: You are a test bot to ... 
conversation_starters:
  - What can you do?

Refer to ./bots/todo-{sh,js,py} for examples of how to implement a bot.

License

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

llm-functions's People

Contributors

sigoden avatar david-else avatar gilcu3 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.