@ai.ntellect/core 0.6.0 → 0.6.2

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 (37) hide show
  1. package/create-llm-to-select-multiple-graph copy.ts +243 -0
  2. package/create-llm-to-select-multiple-graph.ts +148 -0
  3. package/dist/create-llm-to-select-multiple-graph copy.js +201 -0
  4. package/dist/create-llm-to-select-multiple-graph.js +142 -0
  5. package/dist/graph/controller.js +6 -6
  6. package/dist/graph/engine.js +198 -135
  7. package/dist/index copy.js +76 -0
  8. package/dist/utils/setup-graphs.js +28 -0
  9. package/dist/utils/stringifiy-zod-schema.js +41 -0
  10. package/graph/controller.ts +11 -9
  11. package/graph/engine.ts +244 -166
  12. package/index copy.ts +81 -0
  13. package/index.ts +1 -1
  14. package/package.json +1 -1
  15. package/test/graph/engine.test.ts +27 -44
  16. package/tsconfig.json +1 -1
  17. package/types/index.ts +11 -3
  18. package/utils/setup-graphs.ts +45 -0
  19. package/utils/stringifiy-zod-schema.ts +45 -0
  20. package/dist/test/graph/controller.test.js +0 -170
  21. package/dist/test/graph/engine.test.js +0 -465
  22. package/dist/test/memory/adapters/meilisearch.test.js +0 -250
  23. package/dist/test/memory/adapters/redis.test.js +0 -143
  24. package/dist/test/memory/base.test.js +0 -209
  25. package/dist/test/services/agenda.test.js +0 -230
  26. package/dist/test/services/queue.test.js +0 -258
  27. package/dist/utils/schema-generator.js +0 -46
  28. package/dist/utils/state-manager.js +0 -20
  29. package/utils/generate-object.js +0 -111
  30. package/utils/header-builder.js +0 -34
  31. package/utils/inject-actions.js +0 -16
  32. package/utils/queue-item-transformer.js +0 -24
  33. package/utils/sanitize-results.js +0 -60
  34. package/utils/schema-generator.js +0 -46
  35. package/utils/schema-generator.ts +0 -73
  36. package/utils/state-manager.js +0 -20
  37. package/utils/state-manager.ts +0 -30
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ const openai_1 = require("@ai-sdk/openai");
20
+ const ai_1 = require("ai");
21
+ const zod_1 = require("zod");
22
+ const engine_1 = require("./graph/engine");
23
+ const setup_graphs_1 = require("./utils/setup-graphs");
24
+ const stringifiy_zod_schema_1 = require("./utils/stringifiy-zod-schema");
25
+ // // 2. Define the graph
26
+ // ---- II. Create an LLM to select the
27
+ // 2. Define the graph with a name
28
+ const graphDefinitionA = {
29
+ name: "get-news", // Assign a name to match the workflow
30
+ entryNode: "get-news",
31
+ nodes: {
32
+ "get-news": {
33
+ name: "get-news",
34
+ description: "Get news",
35
+ schema: zod_1.z.object({
36
+ query: zod_1.z.string(),
37
+ }),
38
+ execute: () => __awaiter(void 0, void 0, void 0, function* () {
39
+ return { messages: "Hello, world!" };
40
+ }),
41
+ relationships: [{ name: "end" }],
42
+ },
43
+ end: {
44
+ name: "end",
45
+ description: "End the graph",
46
+ execute: () => __awaiter(void 0, void 0, void 0, function* () {
47
+ return { messages: "Goodbye, world!" };
48
+ }),
49
+ },
50
+ },
51
+ };
52
+ const graphDefinitionB = {
53
+ name: "security-analysis",
54
+ entryNode: "security-analysis",
55
+ nodes: {
56
+ "security-analysis": {
57
+ name: "security-analysis",
58
+ description: "Get news",
59
+ execute: () => __awaiter(void 0, void 0, void 0, function* () {
60
+ return { messages: "Hello, world!" };
61
+ }),
62
+ relationships: [{ name: "end" }],
63
+ },
64
+ end: {
65
+ name: "end",
66
+ description: "End the graph",
67
+ execute: () => __awaiter(void 0, void 0, void 0, function* () {
68
+ return { messages: "Goodbye, world!" };
69
+ }),
70
+ },
71
+ },
72
+ };
73
+ // 3. Define the initial state
74
+ const initialState = {
75
+ messages: "",
76
+ };
77
+ // 3. Define the initial state
78
+ const initialStateB = {
79
+ messages: "",
80
+ };
81
+ const graphMaps = [graphDefinitionA, graphDefinitionB];
82
+ // ---- II. Create a node with LLM
83
+ (() => __awaiter(void 0, void 0, void 0, function* () {
84
+ var _a, e_1, _b, _c;
85
+ const prompt = "Salut quelles sont les news sur bitcoin ? et fais une analyse de sécurité";
86
+ // Dynamically extract start nodes from each graph definition in graphMaps
87
+ const startNodesSchema = graphMaps.map((graphDefinition) => graphDefinition.nodes[graphDefinition.entryNode]);
88
+ // Pass the start nodes into stringifyZodSchema
89
+ const system = `You can select multiple workflows.
90
+ Here the available workflows and parameters:
91
+ workflows:${(0, stringifiy_zod_schema_1.stringifyZodSchema)(startNodesSchema)}`;
92
+ console.log(system);
93
+ const llm = yield (0, ai_1.streamObject)({
94
+ model: (0, openai_1.openai)("gpt-4o"),
95
+ prompt,
96
+ schema: zod_1.z.object({
97
+ actions: zod_1.z.array(zod_1.z.object({
98
+ name: zod_1.z.string(),
99
+ parameters: zod_1.z.array(zod_1.z.object({
100
+ name: zod_1.z.string(),
101
+ value: zod_1.z.any(),
102
+ })),
103
+ })),
104
+ response: zod_1.z.string(),
105
+ }),
106
+ system,
107
+ });
108
+ try {
109
+ for (var _d = true, _e = __asyncValues(llm.partialObjectStream), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
110
+ _c = _f.value;
111
+ _d = false;
112
+ const chunk = _c;
113
+ if (chunk.response) {
114
+ console.log(chunk.response);
115
+ }
116
+ }
117
+ }
118
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
119
+ finally {
120
+ try {
121
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
122
+ }
123
+ finally { if (e_1) throw e_1.error; }
124
+ }
125
+ const actions = (yield llm.object).actions;
126
+ console.log(actions);
127
+ const selectedWorkflows = (yield llm.object).actions;
128
+ console.dir(llm.object, { depth: null });
129
+ // Define the base states
130
+ const baseStateMapping = {
131
+ "get-news": initialState,
132
+ "security-analysis": initialStateB,
133
+ // Add other workflows and their base states as needed
134
+ };
135
+ const { initialStates, graphs: selectedGraphs, startNodes, } = (0, setup_graphs_1.setupGraphsWithActions)(selectedWorkflows, baseStateMapping, graphMaps);
136
+ // Execute graphs with dynamically determined initial states
137
+ engine_1.GraphEngine.executeGraphsInParallel(selectedGraphs, startNodes, initialStates, (graph) => {
138
+ console.log(`Graph ${graph.name} updated`, graph.getState());
139
+ }, (error, nodeName, state) => {
140
+ console.error(`Erreur dans ${nodeName}`, error, state);
141
+ });
142
+ }))();
@@ -41,13 +41,13 @@ class GraphController {
41
41
  schema: graphDefinition.schema,
42
42
  autoDetectCycles: true,
43
43
  });
44
+ console.log("graph", graph);
44
45
  // Construct the initial state from action parameters.
45
- const initialState = {
46
- context: action.parameters.reduce((acc, param) => {
47
- acc[param.name] = param.value;
48
- return acc;
49
- }, {}),
50
- };
46
+ const initialState = action.parameters.reduce((acc, param) => {
47
+ acc[param.name] = param.value;
48
+ return acc;
49
+ }, {});
50
+ console.log("initialState", initialState);
51
51
  // Execute the graph starting from the defined entry node.
52
52
  yield graph.execute(initialState, graphDefinition.entryNode);
53
53
  // Retrieve the final state after execution.