From c0aef565cdd4bb292bf7554a52d0e95478089803 Mon Sep 17 00:00:00 2001 From: Geoff Seemueller Date: Sat, 9 Nov 2024 11:18:38 -0500 Subject: [PATCH] add bin --- bin.js | 62 ++++++++++++++++++++++++++++++++++++++++++ index.js => lib.js | 68 ++++------------------------------------------ package.json | 3 ++ 3 files changed, 70 insertions(+), 63 deletions(-) create mode 100755 bin.js rename index.js => lib.js (59%) diff --git a/bin.js b/bin.js new file mode 100755 index 0000000..ef6f048 --- /dev/null +++ b/bin.js @@ -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 {} \ No newline at end of file diff --git a/index.js b/lib.js similarity index 59% rename from index.js rename to lib.js index 3b86dfb..acaac36 100644 --- a/index.js +++ b/lib.js @@ -1,5 +1,5 @@ // Simulated LLM Service -class DummyLlmService { +export class DummyLlmService { async query(prompt) { // Simulate LLM response with basic intent matching const intents = { @@ -16,7 +16,7 @@ class DummyLlmService { } // Interface for workflow operators -class WorkflowOperator { +export class WorkflowOperator { constructor(name, operation) { this.name = name; this.operation = operation; @@ -28,7 +28,7 @@ class WorkflowOperator { } // Interface for manifold regions -class ManifoldRegion { +export class ManifoldRegion { constructor(name, operators = []) { this.name = name; this.operators = operators; @@ -50,7 +50,7 @@ class ManifoldRegion { } // Main manifold implementation -class WorkflowFunctionManifold { +export class WorkflowFunctionManifold { constructor(llmService) { this.llmService = llmService; this.regions = new Map(); @@ -105,62 +105,4 @@ class WorkflowFunctionManifold { 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); \ No newline at end of file +} \ No newline at end of file diff --git a/package.json b/package.json index 4187a3a..fa01dcc 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "1.0.0", "description": "for building dynamic, LLM-driven workflows using a region-based execution model", "main": "index.js", + "bin": { + "workflow-function-manifold": "./bin.js" + }, "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1"