npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

process-builder

v0.9.1

Published

ProcessBuilder 是一个由 AI 驱动的流程构建器,为应用提供自然语言接口,自动构建并调用应用中的功能。为开发人员提供无缝的流程构建接口,只需定义好基本的节点,剩下的交给 ProcessBuilder 。

Downloads

23

Readme

ProcessBuilder

介绍

ProcessBuilder 是一个由 AI 驱动的流程构建器,旨在为应用程序提供自然语言接口,实现功能的自动构建与调用。为开发人员提供了无缝的流程构建接口,只需定义基本的节点,剩下的交给 ProcessBuilder 来处理。

  • 🤖 为应用与用户提供自然语言接口
  • 🛠️ 提供无缝的节点定义模式,便于开发
  • 🧾 可定制的流程生成策略,适配不同开发领域(暂未实现)

安装

包管理器

使用npm安装:

npm install process-builder

安装后可以使用 importrequire 引入模块。

ES 模块:

import { AgentWenxin, ProcessContainer } from "process-builder";

CommonJS 模块:

const { AgentWenxin, ProcessContainer } = require("process-builder");

例子

import { AgentWenxin, ProcessContainer } from "process-builder";
// const { AgentWenxin, ProcessContainer } = require("process-builder");  // 也可以使用ES模块


// 1. 创建 ProcessContainer 实例

// 使用默认的 IAgentApi 实现
const agent = new AgentWenxin({
    accessToken: "你的 access token",
    // 其他配置项
});
// 实例化 ProcessContainer 对象
const processContainer = new ProcessContainer({ agent });


// 2. 定义一些函数与常量

function add(a: number, b: number): number {
    return a + b;
}

function subtract(a: number, b: number): number {
    return a - b;
}

const pi = 3.14159;


// 3. 将函数与常量注册到 ProcessContainer 中

processContainer.manager.registerFunction(add, {
    name: "add",
    description: "将两数相加 a+b",
    parameters: {
        type: "object",
        properties: {
            a: {
                type: "number",
                description: "数字1"
            },
            b: {
                type: "number",
                description: "数字2"
            }
        }
    },
    responses: {
        type: "object",
        properties: {
            result: {
                type: "number",
                description: "两数相加的结果"
            }
        }
    }
});

processContainer.manager.registerFunction(subtract, {
    name: "subtract",
    description: "将两数相减 a-b",
    parameters: {
        type: "object",
        properties: {
            a: {
                type: "number",
                description: "数字1"
            },
            b: {
                type: "number",
                description: "数字2"
            }
        }
    },
    responses: {
        type: "object",
        properties: {
            result: {
                type: "number",
                description: "两数相减的结果"
            }
        }
    }
});

processContainer.manager.registerConstant(pi, {
    name: "pi",
    description: "圆周率PI",
    define: {
        type: "number"
    }
});


// 4. 根据自然语言生成并执行流程

(async () => {
    // 发送消息,使用自然语言
    const processResult1 = await processContainer.chat.send(
        "PI与自身二倍的差是多少?"
    );
    console.log(processResult1);

    // 执行流程
    const processResult2 = processContainer.manager.performProcess();
    console.log(processResult2);
})();

注意:

  1. 请替换 你的 access token 为你自己的 access token。
  2. 如果使用默认 IAgentApi 实现,请确保 CORS 已正确配置。

API

ProcessContainer

| 方法/属性 | 传入参数 | 返回值 | 描述 | | --- | --- | --- | --- | | constructor(config: IModuleConfig) | IModuleConfig 对象 | ProcessContainer 实例 | 构造函数,初始化 ProcessContainer 实例 | | manager | 无 | void | FlowManager 实例 | | chat | 无 | void | FlowChat 实例 | | getManager() | 无 | FlowManager 实例 | 获取 FlowManager 实例 | | getChat() | 无 | FlowChat 实例 | 获取 FlowChat 实例 |

IModuleConfig

| 方法/属性 | 传入参数 | 返回值 | 描述 | | --------- | -------------- | ------ | ------------------------------------------------ | | agent | IAgentApi 对象 | 无 | 配置项,指定使用的 Agent API,可以引入默认实现。 | | language | EnumLanguage | 无 | 指定语言环境,默认 EnumLanguage.ZN_CH |

FlowManager

| 方法/属性 | 传入参数 | 返回值 | 描述 | | --- | --- | --- | --- | | performProcess() | 无 | boolean(是否成功) | 从流程队列中取出流程并执行当前流程,返回是否成功 | | addProcess(processString: string | object) | 流程字符串或流程对象 | void | 添加流程字符串或流程对象 | | registerNode(target: T, define: UseNodeDefine) | 目标对象,节点定义 | void | 注册节点,包括方法和常量 | | registerFunction(target: T, describe: SubFunctionDefine) | 方法对象,方法描述对象 | void | 注册方法节点 | | registerConstant(target: T, describe: SubConstantDefine) | 常量对象,常量描述对象 | void | 注册常量节点 | | getNodeByName(name: string) | 节点 ID(字符串) | IEntNode(节点对象)或 undefine(如果未找到) | 根据 节点 获取节点 | | getAllNodes() | 无 | IEntNode[](节点对象数组) | 获取所有节点 |

FlowChat

| 方法/属性 | 传入参数 | 返回值 | 描述 | | --- | --- | --- | --- | | sessionHistory | 无 | IEntSession[](会话数组) | 会话历史记录,包含提问和回答 | | send(text: string) | 发送的消息(字符串) | Promise(响应会话)或 null | 发送消息,返回消息响应 |

开发

拉取代码:

git clone https://github.com/SWdrift/process-builder.git
cd process-builder

安装依赖:

pnpm install

运行测试:

pnpm test

TODO List

  • [x] 多语言支持
  • [ ] 完善错误处理机制
  • [x] 规范化函数描述格式
  • [ ] 可配置规则引擎

关于

协议

MIT