LLM-Functions:用Bash/JavaScript/Python轻松构建强大AI工具与智能体的终极指南

【免费下载链接】llm-functions Easily create LLM tools and agents using plain Bash/JavaScript/Python functions. 【免费下载链接】llm-functions 项目地址: https://gitcode.com/gh_mirrors/ll/llm-functions

LLM-Functions是一个让你能够使用熟悉的Bash、JavaScript和Python语言轻松构建强大LLM工具和智能体的开源项目。无需复杂的集成,只需利用函数调用功能,就能将你的LLM直接连接到自定义代码,解锁无限可能。

🌟 为什么选择LLM-Functions?

LLM-Functions项目的核心理念是简化AI工具开发流程,让开发者能够专注于功能实现而非复杂的框架配置。无论你是经验丰富的开发者还是AI新手,都能快速上手并创建属于自己的AI工具和智能体。

主要优势:

  • 多语言支持:使用Bash、JavaScript或Python编写工具,无需学习新语言
  • 自动生成声明:基于代码注释自动生成JSON声明,减少重复工作
  • 灵活的智能体架构:轻松构建和管理具有特定功能的AI智能体
  • 丰富的工具库:内置多种实用工具,可直接使用或作为参考

🚀 快速开始

1. 安装准备

确保你已安装以下工具:

  • Git
  • Node.js (用于JavaScript工具)
  • Python (用于Python工具)
  • AIChat (目前唯一支持llm-functions的CLI工具)

2. 获取代码

git clone https://gitcode.com/gh_mirrors/ll/llm-functions
cd llm-functions

3. 构建工具和智能体

创建工具列表文件

创建./tools.txt文件,每行包含一个工具文件名:

execute_command.sh
web_search_perplexity.sh
get_current_weather.sh
创建智能体列表文件

创建./agents.txt文件,每行包含一个智能体名称:

todo
coder
sql
构建二进制文件和函数声明
argc build@tool
argc build@agent

4. 连接LLM-Functions和AIChat

将仓库目录链接到AIChat的functions_dir:

ln -s "$(pwd)" "$(aichat --info | sed -n 's/^functions_dir\s\+//p')"

或者通过环境变量指定LLM-functions目录:

export AICHAT_FUNCTIONS_DIR="$(pwd)"

5. 开始使用

现在你可以使用AIChat调用工具和智能体了:

# 使用天气工具查询巴黎天气
aichat --role %functions% what is the weather in Paris?

# 使用todo智能体列出所有待办事项
aichat --agent todo list all my todos

🔧 构建自定义工具

构建工具非常简单,你可以利用现有的编程知识,因为工具本质上就是用你喜欢的语言编写的函数。LLM Functions会根据注释自动为工具生成JSON声明。

Bash工具示例

./tools/目录中创建一个新的bash脚本(例如execute_command.sh):

#!/usr/bin/env bash

# @describe Execute a shell command and return the output
# @option -c,--command! The command to execute
main() {
    echo "Executing command: $command"
    eval "$command"
}

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

JavaScript工具示例

./tools/目录中创建一个新的JavaScript文件(例如execute_js_code.js):

/**
 * Demonstrate how to create a tool using Javascript and how to use comments.
 * @typedef {Object} Args
 * @property {string} code - The JavaScript code to execute
 */

/**
 * @param {Args} args
 */
exports.run = function ({ code }) {
    console.log("Executing JavaScript code:\n", code);
    try {
        const result = eval(code);
        return { result };
    } catch (error) {
        return { error: error.message };
    }
};

Python工具示例

./tools/目录中创建一个新的Python脚本(例如execute_py_code.py):

from typing import Any, Dict

def run(args: Dict[str, Any]) -> Dict[str, Any]:
    """
    Demonstrate how to create a tool using Python and how to use comments.
    Args:
        args: The arguments
        args.code (str): The Python code to execute
    Returns:
        The result of the code execution
    """
    code = args.get("code", "")
    print(f"Executing Python code:\n{code}")
    try:
        result = eval(code)
        return {"result": result}
    except Exception as e:
        return {"error": str(e)}

快速创建工具

Argcfile.sh提供了create@tool工具来快速创建工具脚本:

argc create@tool _test.sh command! timeout+ verbose*

🤖 构建智能体

智能体是具有特定功能的AI助手,能够使用多种工具来完成复杂任务。

智能体目录结构

智能体具有以下文件夹结构:

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

智能体定义文件

智能体定义文件(index.yaml)定义了智能体的关键方面:

name: todo
description: An AI agent that helps you manage a todo list
version: 0.1.0
instructions: |
  You are AI agent that manage a todo list.
  Available tools:
  {{__tools__}}
variables:
  todo_file: ~/.todos.json

智能体工具

智能体可以拥有自己的工具集脚本,位于agents/<agent-name>/tools.{sh,js,py}中,可以包含多个工具函数。

以下是一个git智能体的Bash工具示例:

#!/usr/bin/env bash

# @cmd Check git status
git_status() {
    git status
}

# @cmd Show git diff
# @option -s,--staged Only show staged changes
git_diff() {
    if [[ -n "$staged" ]]; then
        git diff --staged
    else
        git diff
    fi
}

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

📚 内置智能体介绍

LLM-Functions提供了多个内置智能体,可直接使用或作为自定义智能体的参考:

Todo智能体

agents/todo/ - 帮助你管理待办事项的AI智能体。可以添加、列出、完成和删除待办事项。

Coder智能体

agents/coder/ - 协助你完成编码任务的AI智能体。支持代码生成、解释、重构等功能。

SQL智能体

agents/sql/ - 帮助你管理SQL数据库的AI智能体。可以编写查询、分析表结构、优化性能等。

JSON-Viewer智能体

agents/json-viewer/ - 查看和过滤JSON数据的AI智能体。仅将JSON模式发送给LLM,保护敏感数据同时提高处理效率。

🔄 高级功能:MCP支持

LLM-Functions通过Model Context Protocol (MCP)提供了高级网络功能:

  • mcp/server:让LLM-Functions工具/智能体通过MCP协议被使用
  • mcp/bridge:让外部MCP工具被LLM-Functions使用

这使得LLM-Functions可以与其他MCP兼容的系统无缝集成,扩展了其应用范围。

📖 学习资源

🎯 总结

LLM-Functions为开发者提供了一个简单而强大的框架,用于构建自定义AI工具和智能体。通过使用熟悉的编程语言和自动生成的声明,你可以快速将想法转化为功能丰富的AI应用。无论你是想自动化日常任务、构建专业智能助手,还是探索AI的无限可能,LLM-Functions都是一个值得尝试的优秀选择。

立即开始你的AI工具开发之旅,体验用Bash、JavaScript和Python构建强大AI工具的乐趣吧!

【免费下载链接】llm-functions Easily create LLM tools and agents using plain Bash/JavaScript/Python functions. 【免费下载链接】llm-functions 项目地址: https://gitcode.com/gh_mirrors/ll/llm-functions

更多推荐