graphai 0.4.3 → 0.4.4
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.
package/README.md
CHANGED
|
@@ -160,6 +160,9 @@ A *computed node* has following properties.
|
|
|
160
160
|
- *timeout*: An optional number, which specifies the maximum waittime in msec. If the associated agent function does not return the value in time, the "Timeout" error will be recorded. The returned value received after the time out will be discarded.
|
|
161
161
|
- *isResult*: An optional boolean value, which indicates that the return value of this node, should be included as a property of the return value from the run() method of the GraphUI instance.
|
|
162
162
|
- *priority*: An optional number, which specifies the priority of the execution of the associated agent (the task). Default is 0, which means "neutral". Negative numbers are allowed as well.
|
|
163
|
+
- *if*: An optional data source property. The node will be activated only if the value from the data source is truthy.
|
|
164
|
+
- *unless*: An optional data source property. The node will be activated only if the value from the data source is falty (including empty array).
|
|
165
|
+
- *graph*: An optional property for nested agents, which specifies the inner graph. This value can be a graph itself or the data souce, whose value is a graph.
|
|
163
166
|
|
|
164
167
|
### Static Node
|
|
165
168
|
|
|
@@ -319,10 +322,11 @@ flowchart LR
|
|
|
319
322
|
|
|
320
323
|
GraphAI provides mechanisms to control the flow of data based on certain conditions. This is achieved through the *if* and *anyInput* properties.
|
|
321
324
|
|
|
322
|
-
#### If Property
|
|
325
|
+
#### If/Unless Property
|
|
323
326
|
|
|
324
|
-
The *if* property allows you to specify a condition that must be met for the data to flow into a particular node. The condition is defined by a data source. If the value obtained from the specified *data source* is truthy (i.e., not null, undefined, 0, false, NaN, or an empty array/string), the node will be executed; otherwise, it will be skipped.
|
|
325
|
-
|
|
327
|
+
The *if* property allows you to specify a condition that must be met for the data to flow into a particular node. The condition is defined by a data source. If the value obtained from the specified *data source* is truthy (i.e., not null, undefined, 0, false, NaN, or an empty array/string), the node will be executed; otherwise, it will be skipped.The *unless* property is just the opporsite of the *if* property.
|
|
328
|
+
|
|
329
|
+
For example, the following node will be executed only if the *tool_calls* property of the message from the LLM contains a non-zero/non-empty value:
|
|
326
330
|
|
|
327
331
|
```typescript
|
|
328
332
|
tool_calls: {
|
|
@@ -380,4 +384,5 @@ Negative priority values are allowed, enabling you to fine-tune the execution or
|
|
|
380
384
|
## References
|
|
381
385
|
|
|
382
386
|
- [Collaboration](./Collaboration.md)
|
|
387
|
+
- [Sample Graphs](./samples/README.md)
|
|
383
388
|
- [API Document](./APIDocument.md)
|
|
@@ -3,23 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.workerAgent = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
const worker_threads_1 = require("worker_threads");
|
|
6
|
-
const
|
|
6
|
+
const vanilla_1 = require("../../experimental_agents/vanilla");
|
|
7
7
|
const utils_1 = require("../../utils/utils");
|
|
8
8
|
const vanillaAgents = {
|
|
9
|
-
totalAgent:
|
|
10
|
-
dataSumTemplateAgent:
|
|
11
|
-
propertyFilterAgent:
|
|
12
|
-
copyAgent:
|
|
13
|
-
pushAgent:
|
|
14
|
-
popAgent:
|
|
15
|
-
shiftAgent:
|
|
16
|
-
nestedAgent:
|
|
17
|
-
mapAgent:
|
|
18
|
-
dotProductAgent:
|
|
19
|
-
sortByValuesAgent:
|
|
20
|
-
stringSplitterAgent:
|
|
21
|
-
stringTemplateAgent:
|
|
22
|
-
jsonParserAgent:
|
|
9
|
+
totalAgent: vanilla_1.totalAgent,
|
|
10
|
+
dataSumTemplateAgent: vanilla_1.dataSumTemplateAgent,
|
|
11
|
+
propertyFilterAgent: vanilla_1.propertyFilterAgent,
|
|
12
|
+
copyAgent: vanilla_1.copyAgent,
|
|
13
|
+
pushAgent: vanilla_1.pushAgent,
|
|
14
|
+
popAgent: vanilla_1.popAgent,
|
|
15
|
+
shiftAgent: vanilla_1.shiftAgent,
|
|
16
|
+
nestedAgent: vanilla_1.nestedAgent,
|
|
17
|
+
mapAgent: vanilla_1.mapAgent,
|
|
18
|
+
dotProductAgent: vanilla_1.dotProductAgent,
|
|
19
|
+
sortByValuesAgent: vanilla_1.sortByValuesAgent,
|
|
20
|
+
stringSplitterAgent: vanilla_1.stringSplitterAgent,
|
|
21
|
+
stringTemplateAgent: vanilla_1.stringTemplateAgent,
|
|
22
|
+
jsonParserAgent: vanilla_1.jsonParserAgent,
|
|
23
23
|
};
|
|
24
24
|
if (!worker_threads_1.isMainThread && worker_threads_1.parentPort) {
|
|
25
25
|
const port = worker_threads_1.parentPort;
|
|
@@ -29,7 +29,8 @@ const fetchAgent = async ({ inputs, params }) => {
|
|
|
29
29
|
const response = await fetch(url.toString(), fetchOptions);
|
|
30
30
|
if (!response.ok) {
|
|
31
31
|
const status = response.status;
|
|
32
|
-
const
|
|
32
|
+
const type = params?.type ?? "json";
|
|
33
|
+
const error = type === "json" ? await response.json() : await response.text();
|
|
33
34
|
if (params?.returnErrorResult) {
|
|
34
35
|
return { status, error };
|
|
35
36
|
}
|