@ai.ntellect/core 0.6.10 → 0.6.12

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 (44) hide show
  1. package/app/README.md +36 -0
  2. package/app/app/favicon.ico +0 -0
  3. package/app/app/globals.css +21 -0
  4. package/app/app/gun.ts +0 -0
  5. package/app/app/layout.tsx +18 -0
  6. package/app/app/page.tsx +321 -0
  7. package/app/eslint.config.mjs +16 -0
  8. package/app/next.config.ts +7 -0
  9. package/app/package-lock.json +5912 -0
  10. package/app/package.json +31 -0
  11. package/app/pnpm-lock.yaml +4031 -0
  12. package/app/postcss.config.mjs +8 -0
  13. package/app/public/file.svg +1 -0
  14. package/app/public/globe.svg +1 -0
  15. package/app/public/next.svg +1 -0
  16. package/app/public/vercel.svg +1 -0
  17. package/app/public/window.svg +1 -0
  18. package/app/tailwind.config.ts +18 -0
  19. package/app/tsconfig.json +27 -0
  20. package/dist/graph/controller.js +30 -41
  21. package/dist/graph/graph.js +167 -0
  22. package/dist/index.js +1 -2
  23. package/dist/memory/adapters/meilisearch/index.js +39 -63
  24. package/dist/utils/experimental-graph-rag.js +152 -0
  25. package/dist/utils/stringifiy-zod-schema.js +7 -6
  26. package/graph/controller.ts +57 -52
  27. package/graph/graph.ts +198 -0
  28. package/index.ts +1 -2
  29. package/memory/adapters/meilisearch/index.ts +41 -76
  30. package/package.json +2 -2
  31. package/tsconfig.json +1 -1
  32. package/types/index.ts +35 -38
  33. package/utils/experimental-graph-rag.ts +170 -0
  34. package/utils/stringifiy-zod-schema.ts +6 -6
  35. package/create-llm-to-select-multiple-graph copy.ts +0 -237
  36. package/create-llm-to-select-multiple-graph.ts +0 -148
  37. package/dist/create-llm-to-select-multiple-graph copy.js +0 -171
  38. package/dist/create-llm-to-select-multiple-graph.js +0 -142
  39. package/dist/graph/engine.js +0 -634
  40. package/dist/index copy.js +0 -76
  41. package/dist/utils/setup-graphs.js +0 -28
  42. package/graph/engine.ts +0 -793
  43. package/index copy.ts +0 -81
  44. package/utils/setup-graphs.ts +0 -45
@@ -1,237 +0,0 @@
1
- import { openai } from "@ai-sdk/openai";
2
- import { generateObject } from "ai";
3
- import { parseEther } from "ethers";
4
- import { z } from "zod";
5
- import { GraphEngine } from "./graph/engine";
6
- import { networkConfigs } from "./index copy";
7
- import { Action, GraphDefinition, SharedState } from "./types";
8
- import { setupGraphsWithActions } from "./utils/setup-graphs";
9
- import { stringifyZodSchema } from "./utils/stringifiy-zod-schema";
10
- // ---- I. Create a simple workflow ----
11
- // 1. Define the context
12
- type MainContext = {
13
- results?: Record<string, CombinedContext>[];
14
- actions?: Action[];
15
- };
16
-
17
- type ContextA = {
18
- to: string;
19
- value: string;
20
- chain: {
21
- id: number;
22
- rpc: string;
23
- };
24
- type: string;
25
- };
26
-
27
- type ContextB = {};
28
-
29
- // // 2. Define the graph
30
-
31
- // ---- II. Create an LLM to select the
32
-
33
- // 2. Define the graph with a name
34
- const graphDefinitionA: GraphDefinition<ContextA> = {
35
- name: "prepare-evm-transaction", // Assign a name to match the workflow
36
- entryNode: "prepare-evm-transaction",
37
- nodes: {
38
- "prepare-evm-transaction": {
39
- name: "prepare-evm-transaction",
40
- description: "Prepare a transaction for the user to sign.",
41
- schema: z.object({
42
- to: z.string(),
43
- value: z
44
- .string()
45
- .describe("Ask the user for the amount to send, if not specified"),
46
- chain: z
47
- .string()
48
- .describe(
49
- "Examples networks: ethereum, arbitrum, base. IMPORTANT: You must respect the network name."
50
- ),
51
- }),
52
- execute: async (state) => {
53
- console.log("💰 Prepare transaction", { state });
54
- const networkConfig =
55
- networkConfigs[(state.chain as any).toLowerCase()];
56
-
57
- if (!networkConfig) {
58
- throw new Error(`Network ${state.chain} not found`);
59
- }
60
-
61
- return {
62
- to: state.to,
63
- value: parseEther(state.value).toString(),
64
- chain: {
65
- id: networkConfig.id || 0,
66
- rpc: networkConfig.rpc,
67
- },
68
- type: "transfer",
69
- };
70
- },
71
- },
72
- },
73
- };
74
-
75
- const graphDefinitionB: GraphDefinition<ContextB> = {
76
- name: "security-analysis",
77
- entryNode: "security-analysis",
78
- nodes: {
79
- "security-analysis": {
80
- name: "security-analysis",
81
- description: "Get news",
82
- execute: async () => {
83
- return { messages: "Hello, world!" };
84
- },
85
- relationships: [{ name: "end" }],
86
- },
87
- end: {
88
- name: "end",
89
- description: "End the graph",
90
- execute: async () => {
91
- return {
92
- messages:
93
- "Here the security analysis of Bitcoin: Bitcoin is a good investment",
94
- };
95
- },
96
- },
97
- },
98
- };
99
- // 3. Define the initial state
100
- const initialState: SharedState<MainContext> = {};
101
- type CombinedContext = ContextA | ContextB;
102
-
103
- const graphMaps: GraphDefinition<CombinedContext>[] = [
104
- graphDefinitionA as GraphDefinition<CombinedContext>,
105
- graphDefinitionB as GraphDefinition<CombinedContext>,
106
- // Add other graphs
107
- ];
108
-
109
- // ---- II. Create a node with LLM
110
- (async () => {
111
- const prompt = "je veux envoyer 0.0001 eth à 0x123 sur ethereum";
112
- // Dynamically extract start nodes from each graph definition in graphMaps
113
-
114
- const reasoningGraphDefinition: GraphDefinition<MainContext> = {
115
- name: "reasoning",
116
- entryNode: "reasoning",
117
- nodes: {
118
- reasoning: {
119
- name: "reasoning",
120
- description: "Reasoning",
121
- execute: async (state) => {
122
- console.log("Reasoning", { state });
123
- const startNodesSchema = graphMaps.map(
124
- (graphDefinition) =>
125
- graphDefinition.nodes[graphDefinition.entryNode]
126
- );
127
-
128
- // Pass the start nodes into stringifyZodSchema
129
-
130
- const system = `You are a wallet assistant. Don't reuse the same workflow multiple times.
131
- Here the available workflows and parameters:
132
- workflows:${stringifyZodSchema(startNodesSchema)}`;
133
- console.log(system);
134
-
135
- const llm = await generateObject({
136
- model: openai("gpt-4o"),
137
- prompt,
138
- schema: z.object({
139
- actions: z.array(
140
- z.object({
141
- name: z.string(),
142
- parameters: z.array(
143
- z.object({
144
- name: z.string(),
145
- value: z.any(),
146
- })
147
- ),
148
- })
149
- ),
150
- response: z.string(),
151
- }),
152
- system,
153
- });
154
- console.dir(llm.object, { depth: null });
155
-
156
- const actions = (await llm.object).actions;
157
- console.log({ actions });
158
-
159
- const selectedWorkflows = (await llm.object).actions as Action[];
160
- return {
161
- messages: "Hello, world!",
162
- actions: selectedWorkflows,
163
- };
164
- },
165
- relationships: [{ name: "actions" }],
166
- },
167
- actions: {
168
- name: "actions",
169
- description: "Actions",
170
- execute: async (state) => {
171
- if (!state.actions) {
172
- throw new Error("No actions found");
173
- }
174
- const baseStateMapping: Record<
175
- string,
176
- SharedState<CombinedContext>
177
- > = {
178
- "prepare-evm-transaction": initialState,
179
- // Add other workflows and their base states as needed
180
- };
181
-
182
- const {
183
- initialStates,
184
- graphs: selectedGraphs,
185
- startNodes,
186
- } = setupGraphsWithActions(
187
- state.actions,
188
- baseStateMapping,
189
- graphMaps
190
- );
191
-
192
- // Execute graphs with dynamically determined initial states
193
- const results =
194
- await GraphEngine.executeGraphsInSequence<CombinedContext>(
195
- selectedGraphs,
196
- startNodes,
197
- initialStates,
198
- state.actions,
199
- (graph) => {
200
- console.log(`Graph ${graph.name} updated`, graph.getState());
201
- },
202
- (
203
- error: Error,
204
- nodeName: string,
205
- state: SharedState<CombinedContext>
206
- ) => {
207
- console.error(`Erreur dans ${nodeName}`, error, state);
208
- }
209
- );
210
-
211
- return {
212
- actions: results,
213
- };
214
- },
215
- condition: (state) => {
216
- if (state.actions && state.actions.length > 0) {
217
- return true;
218
- }
219
- return false;
220
- },
221
- },
222
- },
223
- };
224
-
225
- const reasoningGraph = new GraphEngine(reasoningGraphDefinition);
226
- await reasoningGraph.execute(
227
- initialState,
228
- "reasoning",
229
- (graph) => {
230
- console.log("Main graph updated", graph.name);
231
- console.dir(graph.getState(), { depth: null });
232
- },
233
- (error, nodeName, state) => {
234
- console.error(`Erreur dans ${nodeName}`, error, state);
235
- }
236
- );
237
- })();
@@ -1,148 +0,0 @@
1
- import { openai } from "@ai-sdk/openai";
2
- import { streamObject } from "ai";
3
- import { z } from "zod";
4
- import { GraphEngine } from "./graph/engine";
5
- import { Action, GraphDefinition, Node, SharedState } from "./types";
6
- import { setupGraphsWithActions } from "./utils/setup-graphs";
7
- import { stringifyZodSchema } from "./utils/stringifiy-zod-schema";
8
-
9
- // ---- I. Create a simple workflow ----
10
- // 1. Define the context
11
- type Context = {
12
- messages: string;
13
- };
14
-
15
- // // 2. Define the graph
16
-
17
- // ---- II. Create an LLM to select the
18
-
19
- // 2. Define the graph with a name
20
- const graphDefinitionA: GraphDefinition<Context> = {
21
- name: "get-news", // Assign a name to match the workflow
22
- entryNode: "get-news",
23
- nodes: {
24
- "get-news": {
25
- name: "get-news",
26
- description: "Get news",
27
- schema: z.object({
28
- query: z.string(),
29
- }),
30
- execute: async () => {
31
- return { messages: "Hello, world!" };
32
- },
33
- relationships: [{ name: "end" }],
34
- },
35
- end: {
36
- name: "end",
37
- description: "End the graph",
38
- execute: async () => {
39
- return { messages: "Goodbye, world!" };
40
- },
41
- },
42
- },
43
- };
44
-
45
- const graphDefinitionB: GraphDefinition<Context> = {
46
- name: "security-analysis",
47
- entryNode: "security-analysis",
48
- nodes: {
49
- "security-analysis": {
50
- name: "security-analysis",
51
- description: "Get news",
52
- execute: async () => {
53
- return { messages: "Hello, world!" };
54
- },
55
- relationships: [{ name: "end" }],
56
- },
57
- end: {
58
- name: "end",
59
- description: "End the graph",
60
- execute: async () => {
61
- return { messages: "Goodbye, world!" };
62
- },
63
- },
64
- },
65
- };
66
- // 3. Define the initial state
67
- const initialState: SharedState<Context> = {
68
- messages: "",
69
- };
70
-
71
- // 3. Define the initial state
72
- const initialStateB: SharedState<Context> = {
73
- messages: "",
74
- };
75
- const graphMaps = [graphDefinitionA, graphDefinitionB];
76
-
77
- // ---- II. Create a node with LLM
78
- (async () => {
79
- const prompt =
80
- "Salut quelles sont les news sur bitcoin ? et fais une analyse de sécurité";
81
- // Dynamically extract start nodes from each graph definition in graphMaps
82
- const startNodesSchema = graphMaps.map(
83
- (graphDefinition) => graphDefinition.nodes[graphDefinition.entryNode]
84
- );
85
-
86
- // Pass the start nodes into stringifyZodSchema
87
- const system = `You can select multiple workflows.
88
- Here the available workflows and parameters:
89
- workflows:${stringifyZodSchema(startNodesSchema)}`;
90
- console.log(system);
91
-
92
- const llm = await streamObject({
93
- model: openai("gpt-4o"),
94
- prompt,
95
- schema: z.object({
96
- actions: z.array(
97
- z.object({
98
- name: z.string(),
99
- parameters: z.array(
100
- z.object({
101
- name: z.string(),
102
- value: z.any(),
103
- })
104
- ),
105
- })
106
- ),
107
- response: z.string(),
108
- }),
109
- system,
110
- });
111
-
112
- for await (const chunk of llm.partialObjectStream) {
113
- if (chunk.response) {
114
- console.log(chunk.response);
115
- }
116
- }
117
-
118
- const actions = (await llm.object).actions;
119
- console.log(actions);
120
-
121
- const selectedWorkflows = (await llm.object).actions as Action[];
122
- console.dir(llm.object, { depth: null });
123
- // Define the base states
124
- const baseStateMapping: Record<string, SharedState<Context>> = {
125
- "get-news": initialState,
126
- "security-analysis": initialStateB,
127
- // Add other workflows and their base states as needed
128
- };
129
-
130
- const {
131
- initialStates,
132
- graphs: selectedGraphs,
133
- startNodes,
134
- } = setupGraphsWithActions(selectedWorkflows, baseStateMapping, graphMaps);
135
-
136
- // Execute graphs with dynamically determined initial states
137
- GraphEngine.executeGraphsInParallel<Context>(
138
- selectedGraphs,
139
- startNodes,
140
- initialStates,
141
- (graph) => {
142
- console.log(`Graph ${graph.name} updated`, graph.getState());
143
- },
144
- (error, nodeName, state) => {
145
- console.error(`Erreur dans ${nodeName}`, error, state);
146
- }
147
- );
148
- })();
@@ -1,171 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const openai_1 = require("@ai-sdk/openai");
13
- const ai_1 = require("ai");
14
- const ethers_1 = require("ethers");
15
- const zod_1 = require("zod");
16
- const engine_1 = require("./graph/engine");
17
- const index_copy_1 = require("./index copy");
18
- const setup_graphs_1 = require("./utils/setup-graphs");
19
- const stringifiy_zod_schema_1 = require("./utils/stringifiy-zod-schema");
20
- // // 2. Define the graph
21
- // ---- II. Create an LLM to select the
22
- // 2. Define the graph with a name
23
- const graphDefinitionA = {
24
- name: "prepare-evm-transaction", // Assign a name to match the workflow
25
- entryNode: "prepare-evm-transaction",
26
- nodes: {
27
- "prepare-evm-transaction": {
28
- name: "prepare-evm-transaction",
29
- description: "Prepare a transaction for the user to sign.",
30
- schema: zod_1.z.object({
31
- to: zod_1.z.string(),
32
- value: zod_1.z
33
- .string()
34
- .describe("Ask the user for the amount to send, if not specified"),
35
- chain: zod_1.z
36
- .string()
37
- .describe("Examples networks: ethereum, arbitrum, base. IMPORTANT: You must respect the network name."),
38
- }),
39
- execute: (state) => __awaiter(void 0, void 0, void 0, function* () {
40
- console.log("💰 Prepare transaction", { state });
41
- const networkConfig = index_copy_1.networkConfigs[state.chain.toLowerCase()];
42
- if (!networkConfig) {
43
- throw new Error(`Network ${state.chain} not found`);
44
- }
45
- return {
46
- to: state.to,
47
- value: (0, ethers_1.parseEther)(state.value).toString(),
48
- chain: {
49
- id: networkConfig.id || 0,
50
- rpc: networkConfig.rpc,
51
- },
52
- type: "transfer",
53
- };
54
- }),
55
- },
56
- },
57
- };
58
- const graphDefinitionB = {
59
- name: "security-analysis",
60
- entryNode: "security-analysis",
61
- nodes: {
62
- "security-analysis": {
63
- name: "security-analysis",
64
- description: "Get news",
65
- execute: () => __awaiter(void 0, void 0, void 0, function* () {
66
- return { messages: "Hello, world!" };
67
- }),
68
- relationships: [{ name: "end" }],
69
- },
70
- end: {
71
- name: "end",
72
- description: "End the graph",
73
- execute: () => __awaiter(void 0, void 0, void 0, function* () {
74
- return {
75
- messages: "Here the security analysis of Bitcoin: Bitcoin is a good investment",
76
- };
77
- }),
78
- },
79
- },
80
- };
81
- // 3. Define the initial state
82
- const initialState = {};
83
- const graphMaps = [
84
- graphDefinitionA,
85
- graphDefinitionB,
86
- // Add other graphs
87
- ];
88
- // ---- II. Create a node with LLM
89
- (() => __awaiter(void 0, void 0, void 0, function* () {
90
- const prompt = "je veux envoyer 0.0001 eth à 0x123 sur ethereum";
91
- // Dynamically extract start nodes from each graph definition in graphMaps
92
- const reasoningGraphDefinition = {
93
- name: "reasoning",
94
- entryNode: "reasoning",
95
- nodes: {
96
- reasoning: {
97
- name: "reasoning",
98
- description: "Reasoning",
99
- execute: (state) => __awaiter(void 0, void 0, void 0, function* () {
100
- console.log("Reasoning", { state });
101
- const startNodesSchema = graphMaps.map((graphDefinition) => graphDefinition.nodes[graphDefinition.entryNode]);
102
- // Pass the start nodes into stringifyZodSchema
103
- const system = `You are a wallet assistant. Don't reuse the same workflow multiple times.
104
- Here the available workflows and parameters:
105
- workflows:${(0, stringifiy_zod_schema_1.stringifyZodSchema)(startNodesSchema)}`;
106
- console.log(system);
107
- const llm = yield (0, ai_1.generateObject)({
108
- model: (0, openai_1.openai)("gpt-4o"),
109
- prompt,
110
- schema: zod_1.z.object({
111
- actions: zod_1.z.array(zod_1.z.object({
112
- name: zod_1.z.string(),
113
- parameters: zod_1.z.array(zod_1.z.object({
114
- name: zod_1.z.string(),
115
- value: zod_1.z.any(),
116
- })),
117
- })),
118
- response: zod_1.z.string(),
119
- }),
120
- system,
121
- });
122
- console.dir(llm.object, { depth: null });
123
- const actions = (yield llm.object).actions;
124
- console.log({ actions });
125
- const selectedWorkflows = (yield llm.object).actions;
126
- return {
127
- messages: "Hello, world!",
128
- actions: selectedWorkflows,
129
- };
130
- }),
131
- relationships: [{ name: "actions" }],
132
- },
133
- actions: {
134
- name: "actions",
135
- description: "Actions",
136
- execute: (state) => __awaiter(void 0, void 0, void 0, function* () {
137
- if (!state.actions) {
138
- throw new Error("No actions found");
139
- }
140
- const baseStateMapping = {
141
- "prepare-evm-transaction": initialState,
142
- // Add other workflows and their base states as needed
143
- };
144
- const { initialStates, graphs: selectedGraphs, startNodes, } = (0, setup_graphs_1.setupGraphsWithActions)(state.actions, baseStateMapping, graphMaps);
145
- // Execute graphs with dynamically determined initial states
146
- const results = yield engine_1.GraphEngine.executeGraphsInSequence(selectedGraphs, startNodes, initialStates, state.actions, (graph) => {
147
- console.log(`Graph ${graph.name} updated`, graph.getState());
148
- }, (error, nodeName, state) => {
149
- console.error(`Erreur dans ${nodeName}`, error, state);
150
- });
151
- return {
152
- actions: results,
153
- };
154
- }),
155
- condition: (state) => {
156
- if (state.actions && state.actions.length > 0) {
157
- return true;
158
- }
159
- return false;
160
- },
161
- },
162
- },
163
- };
164
- const reasoningGraph = new engine_1.GraphEngine(reasoningGraphDefinition);
165
- yield reasoningGraph.execute(initialState, "reasoning", (graph) => {
166
- console.log("Main graph updated", graph.name);
167
- console.dir(graph.getState(), { depth: null });
168
- }, (error, nodeName, state) => {
169
- console.error(`Erreur dans ${nodeName}`, error, state);
170
- });
171
- }))();
@@ -1,142 +0,0 @@
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
- }))();