1.12.6 • Published 8 months ago

@aigne/example-workflow-sequential v1.12.6

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Workflow Sequential Demo

This is a demonstration of using AIGNE Framework to build a sequential workflow. The example now supports both one-shot and interactive chat modes, along with customizable model settings and pipeline input/output.

flowchart LR
in(In)
out(Out)
conceptExtractor(Concept Extractor)
writer(Writer)
formatProof(Format Proof)

in --> conceptExtractor --> writer --> formatProof --> out

classDef inputOutput fill:#f9f0ed,stroke:#debbae,stroke-width:2px,color:#b35b39,font-weight:bolder;
classDef processing fill:#F0F4EB,stroke:#C2D7A7,stroke-width:2px,color:#6B8F3C,font-weight:bolder;

class in inputOutput
class out inputOutput
class conceptExtractor processing
class writer processing
class formatProof processing

Prerequisites

  • Node.js and npm installed on your machine
  • An OpenAI API key for interacting with OpenAI's services
  • Optional dependencies (if running the example from source code):
    • Bun for running unit tests & examples
    • Pnpm for package management

Quick Start (No Installation Required)

export OPENAI_API_KEY=YOUR_OPENAI_API_KEY # Set your OpenAI API key

# Run in one-shot mode (default)
npx -y @aigne/example-workflow-sequential

# Run in interactive chat mode
npx -y @aigne/example-workflow-sequential --chat

# Use pipeline input
echo "Create marketing content for our new AI-powered fitness app" | npx -y @aigne/example-workflow-sequential

Installation

Clone the Repository

git clone https://github.com/AIGNE-io/aigne-framework

Install Dependencies

cd aigne-framework/examples/workflow-sequential

pnpm install

Setup Environment Variables

Setup your OpenAI API key in the .env.local file:

OPENAI_API_KEY="" # Set your OpenAI API key here

Run the Example

pnpm start # Run in one-shot mode (default)

# Run in interactive chat mode
pnpm start -- --chat

# Use pipeline input
echo "Create marketing content for our new AI-powered fitness app" | pnpm start

Run Options

The example supports the following command-line parameters:

ParameterDescriptionDefault
--chatRun in interactive chat modeDisabled (one-shot mode)
--model <provider[:model]>AI model to use in format 'provider:model' where model is optional. Examples: 'openai' or 'openai:gpt-4o-mini'openai
--temperature <value>Temperature for model generationProvider default
--top-p <value>Top-p sampling valueProvider default
--presence-penalty <value>Presence penalty valueProvider default
--frequency-penalty <value>Frequency penalty valueProvider default
--log-level <level>Set logging level (ERROR, WARN, INFO, DEBUG, TRACE)INFO
--input, -i <input>Specify input directlyNone

Examples

# Run in chat mode (interactive)
pnpm start -- --chat

# Set logging level
pnpm start -- --log-level DEBUG

# Use pipeline input
echo "Create marketing content for our new AI-powered fitness app" | pnpm start

Example

The following example demonstrates how to build a sequential workflow:

import assert from "node:assert";
import { AIAgent, AIGNE, TeamAgent, ProcessMode } from "@aigne/core";
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";

const { OPENAI_API_KEY } = process.env;
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");

const model = new OpenAIChatModel({
  apiKey: OPENAI_API_KEY,
});

const conceptExtractor = AIAgent.from({
  instructions: `\
You are a marketing analyst. Give a product description, identity:
- Key features
- Target audience
- Unique selling points

Product description:
{{product}}`,
  outputKey: "concept",
});

const writer = AIAgent.from({
  instructions: `\
You are a marketing copywriter. Given a block of text describing features, audience, and USPs,
compose a compelling marketing copy (like a newsletter section) that highlights these points.
Output should be short (around 150 words), output just the copy as a single text block.

Product description:
{{product}}

Below is the info about the product:
{{concept}}`,
  outputKey: "draft",
});

const formatProof = AIAgent.from({
  instructions: `\
You are an editor. Given the draft copy, correct grammar, improve clarity, ensure consistent tone,
give format and make it polished. Output the final improved copy as a single text block.

Product description:
{{product}}

Below is the info about the product:
{{concept}}

Draft copy:
{{draft}}`,
  outputKey: "content",
});

const aigne = new AIGNE({ model });

// 创建一个 TeamAgent 来处理顺序工作流
const teamAgent = TeamAgent.from({
  skills: [conceptExtractor, writer, formatProof],
  mode: ProcessMode.sequential // 默认值,可以省略
});

const result = await aigne.invoke(teamAgent, {
  product: "AIGNE is a No-code Generative AI Apps Engine",
});

console.log(result);

// Output:
// {
//   concept: "**Product Description: AIGNE - No-code Generative AI Apps Engine**\n\nAIGNE is a cutting-edge No-code Generative AI Apps Engine designed to empower users to seamlessly create ...",
//   draft: "Unlock the power of creation with AIGNE, the revolutionary No-code Generative AI Apps Engine! Whether you're a small business looking to streamline operations, an entrepreneur ...",
//   content: "Unlock the power of creation with AIGNE, the revolutionary No-Code Generative AI Apps Engine! Whether you are a small business aiming to streamline operations, an entrepreneur ...",
// }

License

This project is licensed under the MIT License.

1.12.6

8 months ago

1.12.5

8 months ago

1.12.4

8 months ago

1.12.3

8 months ago

1.12.2

8 months ago

1.12.1

8 months ago

1.12.0

8 months ago

1.11.1

8 months ago

1.11.0

8 months ago

1.10.2

9 months ago

1.10.1

9 months ago

1.10.0

9 months ago

1.9.0

9 months ago

1.8.0

9 months ago

1.7.2

10 months ago

1.7.1

10 months ago

1.6.0

10 months ago

1.5.0

10 months ago

1.4.0

10 months ago

1.3.1

10 months ago

1.3.0

10 months ago

1.2.0

11 months ago

1.1.0

11 months ago

1.1.0-beta.17

11 months ago

1.1.0-beta.16

11 months ago

1.1.0-beta.15

11 months ago

1.1.0-beta.14

11 months ago

1.1.0-beta.13

11 months ago

1.1.0-beta.12

11 months ago

1.1.0-beta.11

11 months ago