@fractal-solutions/qflow 1.0.15 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +79 -8
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -589,7 +589,8 @@ import {
589
589
  UserInputNode,
590
590
  AgentNode,
591
591
  CodeInterpreterNode,
592
- MemoryNode
592
+ MemoryNode,
593
+ TransformNode
593
594
  } from '@fractal-solutions/qflow/nodes';
594
595
 
595
596
  // Ensure your DeepSeek API Key is set as an environment variable
@@ -621,6 +622,7 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
621
622
  const userInput = new UserInputNode(); // Agent can also ask for user input
622
623
  const codeInterpreter = new CodeInterpreterNode(); // Agent can execute code
623
624
  const memoryNode = new MemoryNode(); // Agent can store and retrieve memories
625
+ const transformNode = new TransformNode(); // Agent can transform data
624
626
 
625
627
  // Map tool names to their instances
626
628
  const availableTools = {
@@ -633,6 +635,7 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
633
635
  user_input: userInput,
634
636
  code_interpreter: codeInterpreter,
635
637
  memory_node: memoryNode,
638
+ transform_node: transformNode,
636
639
  // Add other tools as needed
637
640
  };
638
641
 
@@ -806,7 +809,7 @@ Storing and retrieving text-based memories for lightweight Retrieval-Augmented G
806
809
 
807
810
  ```javascript
808
811
  import { AsyncFlow } from '@fractal-solutions/qflow';
809
- import { MemoryNode, AgentDeepSeekLLMNode } from '@fractal-solutions/qflow/nodes';
812
+ import { MemoryNode, DeepSeekLLMNode } from '@fractal-solutions/qflow/nodes';
810
813
 
811
814
  const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
812
815
 
@@ -846,18 +849,18 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
846
849
  });
847
850
 
848
851
  // 4. Use an LLM to answer a question based on retrieved memories
849
- const ragLLM = new AgentDeepSeekLLMNode();
850
- ragLLM.setParams({ apiKey: DEEPSEEK_API_KEY });
851
-
852
- ragRetrieve.next(ragLLM);
853
-
852
+ const ragLLM = new DeepSeekLLMNode();
854
853
  ragLLM.preparePrompt = (shared) => {
855
854
  const retrievedContent = shared.memoryResult.map(mem => mem.content).join('\n\n');
856
855
  ragLLM.setParams({
857
- prompt: `Based on the following context, answer the question:\n\nContext:\n${retrievedContent}\n\nQuestion: What is the main role of a CPU?`
856
+ apiKey: DEEPSEEK_API_KEY,
857
+ prompt: `Based on the following context, answer the question:\n\nContext:\n${retrievedContent}\n\nQuestion: What is the main role of a CPU?`,
858
+ keyword: 'rag_llm'
858
859
  });
859
860
  };
860
861
 
862
+ ragRetrieve.next(ragLLM);
863
+
861
864
  const ragFlow = new AsyncFlow(ragRetrieve);
862
865
  try {
863
866
  const ragResult = await ragFlow.runAsync({});
@@ -871,6 +874,73 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
871
874
  })();
872
875
  ```
873
876
 
877
+ ### 16. Transform Node
878
+
879
+ Dynamically transforming data using custom JavaScript functions.
880
+
881
+ ```javascript
882
+ import { AsyncFlow } from '@fractal-solutions/qflow';
883
+ import { TransformNode } from '@fractal-solutions/qflow/nodes';
884
+
885
+ (async () => {
886
+ console.log('--- Running TransformNode Example ---');
887
+
888
+ // Example 1: Map an array of numbers
889
+ const numbers = [1, 2, 3];
890
+ const doubleNumbers = new TransformNode();
891
+ doubleNumbers.setParams({
892
+ input: numbers,
893
+ transformFunction: '(data) => data.map(x => x * 2)'
894
+ });
895
+
896
+ const flow1 = new AsyncFlow(doubleNumbers);
897
+ try {
898
+ const result = await flow1.runAsync({});
899
+ console.log('Doubled Numbers:', result); // Expected: [2, 4, 6]
900
+ } catch (error) {
901
+ console.error('Transform Flow 1 Failed:', error);
902
+ }
903
+
904
+ // Example 2: Filter an array of objects
905
+ const users = [
906
+ { name: 'Alice', active: true },
907
+ { name: 'Bob', active: false },
908
+ { name: 'Charlie', active: true }
909
+ ];
910
+ const activeUsers = new TransformNode();
911
+ activeUsers.setParams({
912
+ input: users,
913
+ transformFunction: '(data) => data.filter(user => user.active)'
914
+ });
915
+
916
+ const flow2 = new AsyncFlow(activeUsers);
917
+ try {
918
+ const result = await flow2.runAsync({});
919
+ console.log('Active Users:', result); // Expected: [{ name: 'Alice', active: true }, { name: 'Charlie', active: true }]
920
+ } catch (error) {
921
+ console.error('Transform Flow 2 Failed:', error);
922
+ }
923
+
924
+ // Example 3: Extract a specific property from an object
925
+ const product = { id: 1, name: 'Laptop', price: 1200 };
926
+ const productName = new TransformNode();
927
+ productName.setParams({
928
+ input: product,
929
+ transformFunction: '(data) => data.name'
930
+ });
931
+
932
+ const flow3 = new AsyncFlow(productName);
933
+ try {
934
+ const result = await flow3.runAsync({});
935
+ console.log('Product Name:', result); // Expected: 'Laptop'
936
+ } catch (error) {
937
+ console.error('Transform Flow 3 Failed:', error);
938
+ }
939
+
940
+ console.log('\n--- TransformNode Example Finished ---');
941
+ })();
942
+ ```
943
+
874
944
  ## Exploring More Examples
875
945
 
876
946
 
@@ -879,6 +949,7 @@ The examples above cover the core functionalities of `qflow`. For more advanced
879
949
  * **LLMs (DeepSeek, OpenAI, Gemini, Ollama):** The core of agentic behavior.
880
950
  * For agents, use specialized LLM nodes like `AgentDeepSeekLLMNode`, `AgentOpenAILLMNode`, `AgentOllamaLLMNode`.
881
951
  * **Agent:** Orchestrating tools and LLM reasoning to achieve complex goals.
952
+ * **Transform:** For dynamic data manipulation and reformatting.
882
953
  * **Memory:** For lightweight, keyword-based long-term memory and RAG.
883
954
  * **CodeInterpreter:** For executing dynamic code (e.g., Python) within the workflow.
884
955
  * **Interactive Agent:** An agent that takes a goal from user input and uses its tools to achieve it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fractal-solutions/qflow",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "A lightweight and flexible JavaScript library for creating and managing workflows and agents.",
5
5
  "main": "dist/qflow.js",
6
6
  "types": "dist/qflow.d.ts",