Skip to content

Commit

Permalink
chore: version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneJiang committed Sep 1, 2023
1 parent d366803 commit 527e73f
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"--loader",
"ts-node/esm",
"-r",
"ts-node/register"
"ts-node/register",
"--experimental-specifier-resolution=node"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idealeap/pipeline",
"version": "0.0.9",
"version": "1.0.0",
"description": "A lightweight, low-code Pipeline built with GPT-4.",
"main": "package/index.js",
"author": "GPT-4 && Marlene && IdeaLeap",
Expand All @@ -23,12 +23,14 @@
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs",
"lint": "eslint --ext .ts,.js ./",
"build": "ncc build package/index.ts -o dist -m"
"build": "ncc build package/index.ts -o dist -m -e ['*.test.ts']",
"publish": "cp README.md dist/ && cd dist && npm publish --access public"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"@vercel/ncc": "^0.36.1",
"dotenv": "^16.3.1",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
Expand Down
54 changes: 54 additions & 0 deletions package/__tests__/pipe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Pipeline,
SerializablePipelineOptions,
PipeRegistry,
DynamicExecutor,
} from "@idealeap/pipeline"; // 请替换成你的模块导入方式

test("Pipe", async () => {
Expand Down Expand Up @@ -39,6 +40,59 @@ test("Pipe", async () => {
});
});

test("并行执行——测测你的", async () => {
const pipe1 = new Pipe(
(input: string) => {
return input + "——————(被我测了";
},
{
id: "pipe1",
batch: true,
onBatchResult: (x: string[]) => {
return `*${x.join("\n")}*`;
},
},
);
const pipe2 = new Pipe(
async (input: string) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
return input + "\n\n你看看你测试了多少!!🤬😡";
},
{
id: "pipe2",
},
);
const pipe3 = new Pipe(
async (input: string) => {
const res = await DynamicExecutor.run({
code: `console.log(\`${input}\`);
return \`${input}\`;`,
});
console.log(res);
return input;
},
{
id: "pipe3",
},
);
const pipeline = new Pipeline([pipe1, pipe2, pipe3], {
onProgress: (completed, total) => {
console.log(`Progress: ${completed}/${total}`);
},
});

// 执行管道
const res = await pipeline.execute([
"我是甲,别测我┭┮﹏┭┮",
"我是乙,求你测我┭┮﹏┭┮",
"我是丙,来啊你以为我怕你!",
"我是丁,你敢?!滚一边去~",
]);
expect([...res.values()].at(-1)).toEqual(
`*我是甲,别测我┭┮﹏┭┮——————(被我测了\n我是乙,求你测我┭┮﹏┭┮——————(被我测了\n我是丙,来啊你以为我怕你!——————(被我测了\n我是丁,你敢?!滚一边去~——————(被我测了*\n\n你看看你测试了多少!!🤬😡`,
);
});

test("Pipeline with JSON", async () => {
// 示例
const jsonConfig: SerializablePipelineOptions = {
Expand Down
23 changes: 1 addition & 22 deletions package/batch/__tests__/batch.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { batchDecorator, BaseAgent } from "@idealeap/gwt";
import { batchDecorator } from "@idealeap/pipeline";
test("batchDecorator", async () => {
// 使用示例

Expand Down Expand Up @@ -58,24 +58,3 @@ test("onBatchResult", async () => {
console.log(res);
expect(res).toEqual(`*["_-a-_","_-b-_","_-c-_"]*`);
});

test("onBatchResult with Prompt", async () => {
const data = (await (
await fetch("https://cos.idealeap.cn/Other/agent.json")
).json()) as { agents: any[] };
const fn = async (data: Record<string, any>) => {
const agent = new BaseAgent(data.agents[0].params);
const res = await agent.call({
request: `你好,非常欢迎你来到我身边~我是xxx,我会把最美好的一面呈现给你!`,
prompts: data.agents[0].params.prompts,
struct: data.agents[0].params.struct,
});
if (!res.success) {
return res.message;
} else {
return res.data;
}
};
const res = await batchDecorator(fn, {})(Array(3).fill(data));
console.log(res);
});
2 changes: 2 additions & 0 deletions package/batch/batch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// 本代码由GPT4生成,具体可见https://pandora.idealeap.cn/share/26cf4f3d-9089-4dbc-87ef-63bc01ed5bb2

export type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
// 批处理选项
export interface BatchOptions<T, R> {
Expand Down
11 changes: 10 additions & 1 deletion package/executor/__tests__/executor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DynamicExecutor, batchDecorator } from "@idealeap/gwt";
import { DynamicExecutor, batchDecorator } from "@idealeap/pipeline";

test("DynamicExecutor", async () => {
// 使用示例
Expand Down Expand Up @@ -62,3 +62,12 @@ test("DynamicExecutor with batchDecorator", async () => {
console.log(res);
expect(res).toEqual([1, 1, 1]);
});

test("static run", async () => {
expect(
await DynamicExecutor.run({
code: `console.log("hello idealeap!")
return "hello idealeap!"`,
}),
).toEqual("hello idealeap!");
});
8 changes: 8 additions & 0 deletions package/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class DynamicExecutor {
executionError = error as Error;
this.log(`Error occurred: ${String(executionError)}`);
result = null;
throw executionError;
}

// Call the afterExecute hook if provided
Expand All @@ -88,4 +89,11 @@ export class DynamicExecutor {
this.log(`Execution result: ${String(result)}`);
return result;
}

static async run(params: { code: string; config?: ExecutorConfig }) {
const { code, config, ...rest } = params;
const executor = new DynamicExecutor(config);
const res = await executor.execute(code, ...Object.values(rest));
return res;
}
}
8 changes: 4 additions & 4 deletions package/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./batch"
export * from "./executor"
export * from "./pipe"
export * from "./utils"
export * from "./batch";
export * from "./executor";
export * from "./pipe";
export * from "./utils";
12 changes: 10 additions & 2 deletions package/pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// 本代码由GPT4生成,具体可见https://pandora.idealeap.cn/share/33072598-a95f-4188-9003-76ccc5d964cb
import { batchDecorator, BatchOptions, PipeRegistryType } from "@idealeap/pipeline";
import {
batchDecorator,
BatchOptions,
PipeRegistryType,
} from "@idealeap/pipeline";
// 类型和接口定义
export type MaybePromise<T> = T | Promise<T>;

Expand Down Expand Up @@ -322,7 +326,11 @@ export class Pipeline {
}

// 添加 Pipe 并返回 this,以支持链式调用
addPipe<T, R>(pipe: Pipe<T, R>): this {
addPipe<T, R>(pipe: Pipe<T, R> | Pipe<T, R>[]): this {
if (Array.isArray(pipe)) {
this.pipes = this.pipes.concat(pipe);
return this;
}
this.pipes.push(pipe);
return this;
}
Expand Down

0 comments on commit 527e73f

Please sign in to comment.