add bin
This commit is contained in:
62
bin.js
Executable file
62
bin.js
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import {DummyLlmService, ManifoldRegion, WorkflowFunctionManifold, WorkflowOperator} from "./lib.js";
|
||||||
|
|
||||||
|
async function demonstrateManifold() {
|
||||||
|
// Initialize services and manifold
|
||||||
|
const llm = new DummyLlmService();
|
||||||
|
const manifold = new WorkflowFunctionManifold(llm);
|
||||||
|
|
||||||
|
// Create operators
|
||||||
|
const dataAnalysisOp = new WorkflowOperator('analysis', async (state) => {
|
||||||
|
console.log('Performing data analysis...');
|
||||||
|
return { ...state, analyzed: true };
|
||||||
|
});
|
||||||
|
|
||||||
|
const dataProcessingOp = new WorkflowOperator('processing', async (state) => {
|
||||||
|
console.log('Processing data...');
|
||||||
|
return { ...state, processed: true };
|
||||||
|
});
|
||||||
|
|
||||||
|
const dataTransformOp = new WorkflowOperator('transformation', async (state) => {
|
||||||
|
console.log('Transforming data...');
|
||||||
|
return { ...state, transformed: true };
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create regions
|
||||||
|
const analysisRegion = new ManifoldRegion('analysis', [dataAnalysisOp]);
|
||||||
|
const processingRegion = new ManifoldRegion('processing', [dataProcessingOp]);
|
||||||
|
const transformationRegion = new ManifoldRegion('transformation', [dataTransformOp]);
|
||||||
|
|
||||||
|
// Connect regions
|
||||||
|
analysisRegion.connectTo(processingRegion);
|
||||||
|
processingRegion.connectTo(transformationRegion);
|
||||||
|
|
||||||
|
// Add regions to manifold
|
||||||
|
manifold.addRegion(analysisRegion);
|
||||||
|
manifold.addRegion(processingRegion);
|
||||||
|
manifold.addRegion(transformationRegion);
|
||||||
|
|
||||||
|
// Demonstrate workflow execution
|
||||||
|
console.log('Starting workflow demonstration...');
|
||||||
|
|
||||||
|
const prompts = [
|
||||||
|
'analyze the data',
|
||||||
|
'process the results',
|
||||||
|
'transform the output'
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const prompt of prompts) {
|
||||||
|
console.log(`\nExecuting prompt: "${prompt}"`);
|
||||||
|
await manifold.navigate(prompt);
|
||||||
|
const executed = await manifold.executeWorkflow(prompt);
|
||||||
|
console.log(`Current state:`, manifold.state);
|
||||||
|
console.log(`Current region: ${manifold.currentRegion.name}`);
|
||||||
|
console.log(`Operation executed: ${executed}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the demonstration
|
||||||
|
demonstrateManifold().catch(console.error);
|
||||||
|
|
||||||
|
export {}
|
@@ -1,5 +1,5 @@
|
|||||||
// Simulated LLM Service
|
// Simulated LLM Service
|
||||||
class DummyLlmService {
|
export class DummyLlmService {
|
||||||
async query(prompt) {
|
async query(prompt) {
|
||||||
// Simulate LLM response with basic intent matching
|
// Simulate LLM response with basic intent matching
|
||||||
const intents = {
|
const intents = {
|
||||||
@@ -16,7 +16,7 @@ class DummyLlmService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Interface for workflow operators
|
// Interface for workflow operators
|
||||||
class WorkflowOperator {
|
export class WorkflowOperator {
|
||||||
constructor(name, operation) {
|
constructor(name, operation) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
@@ -28,7 +28,7 @@ class WorkflowOperator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Interface for manifold regions
|
// Interface for manifold regions
|
||||||
class ManifoldRegion {
|
export class ManifoldRegion {
|
||||||
constructor(name, operators = []) {
|
constructor(name, operators = []) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.operators = operators;
|
this.operators = operators;
|
||||||
@@ -50,7 +50,7 @@ class ManifoldRegion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Main manifold implementation
|
// Main manifold implementation
|
||||||
class WorkflowFunctionManifold {
|
export class WorkflowFunctionManifold {
|
||||||
constructor(llmService) {
|
constructor(llmService) {
|
||||||
this.llmService = llmService;
|
this.llmService = llmService;
|
||||||
this.regions = new Map();
|
this.regions = new Map();
|
||||||
@@ -105,62 +105,4 @@ class WorkflowFunctionManifold {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Usage Example
|
|
||||||
async function demonstrateManifold() {
|
|
||||||
// Initialize services and manifold
|
|
||||||
const llm = new DummyLlmService();
|
|
||||||
const manifold = new WorkflowFunctionManifold(llm);
|
|
||||||
|
|
||||||
// Create operators
|
|
||||||
const dataAnalysisOp = new WorkflowOperator('analysis', async (state) => {
|
|
||||||
console.log('Performing data analysis...');
|
|
||||||
return { ...state, analyzed: true };
|
|
||||||
});
|
|
||||||
|
|
||||||
const dataProcessingOp = new WorkflowOperator('processing', async (state) => {
|
|
||||||
console.log('Processing data...');
|
|
||||||
return { ...state, processed: true };
|
|
||||||
});
|
|
||||||
|
|
||||||
const dataTransformOp = new WorkflowOperator('transformation', async (state) => {
|
|
||||||
console.log('Transforming data...');
|
|
||||||
return { ...state, transformed: true };
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create regions
|
|
||||||
const analysisRegion = new ManifoldRegion('analysis', [dataAnalysisOp]);
|
|
||||||
const processingRegion = new ManifoldRegion('processing', [dataProcessingOp]);
|
|
||||||
const transformationRegion = new ManifoldRegion('transformation', [dataTransformOp]);
|
|
||||||
|
|
||||||
// Connect regions
|
|
||||||
analysisRegion.connectTo(processingRegion);
|
|
||||||
processingRegion.connectTo(transformationRegion);
|
|
||||||
|
|
||||||
// Add regions to manifold
|
|
||||||
manifold.addRegion(analysisRegion);
|
|
||||||
manifold.addRegion(processingRegion);
|
|
||||||
manifold.addRegion(transformationRegion);
|
|
||||||
|
|
||||||
// Demonstrate workflow execution
|
|
||||||
console.log('Starting workflow demonstration...');
|
|
||||||
|
|
||||||
const prompts = [
|
|
||||||
'analyze the data',
|
|
||||||
'process the results',
|
|
||||||
'transform the output'
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const prompt of prompts) {
|
|
||||||
console.log(`\nExecuting prompt: "${prompt}"`);
|
|
||||||
await manifold.navigate(prompt);
|
|
||||||
const executed = await manifold.executeWorkflow(prompt);
|
|
||||||
console.log(`Current state:`, manifold.state);
|
|
||||||
console.log(`Current region: ${manifold.currentRegion.name}`);
|
|
||||||
console.log(`Operation executed: ${executed}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the demonstration
|
|
||||||
demonstrateManifold().catch(console.error);
|
|
@@ -3,6 +3,9 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "for building dynamic, LLM-driven workflows using a region-based execution model",
|
"description": "for building dynamic, LLM-driven workflows using a region-based execution model",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
"bin": {
|
||||||
|
"workflow-function-manifold": "./bin.js"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
Reference in New Issue
Block a user