@ai.ntellect/core 0.4.1 → 0.6.0

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 (125) hide show
  1. package/.mocharc.json +1 -1
  2. package/README.md +311 -272
  3. package/dist/graph/controller.js +63 -0
  4. package/dist/graph/engine.js +563 -0
  5. package/dist/index.js +6 -6
  6. package/dist/memory/adapters/meilisearch/index.js +249 -0
  7. package/dist/memory/adapters/redis/index.js +96 -0
  8. package/dist/memory/index.js +9 -0
  9. package/dist/services/agenda.js +115 -0
  10. package/dist/services/embedding.js +40 -0
  11. package/dist/services/queue.js +99 -103
  12. package/dist/test/graph/controller.test.js +170 -0
  13. package/dist/test/graph/engine.test.js +465 -0
  14. package/dist/test/memory/adapters/meilisearch.test.js +250 -0
  15. package/dist/test/memory/adapters/redis.test.js +143 -0
  16. package/dist/test/memory/base.test.js +209 -0
  17. package/dist/test/services/agenda.test.js +230 -0
  18. package/dist/test/services/queue.test.js +258 -0
  19. package/dist/types/index.js +2 -0
  20. package/dist/utils/generate-object.js +32 -11
  21. package/dist/utils/inject-actions.js +2 -2
  22. package/dist/utils/queue-item-transformer.js +2 -2
  23. package/dist/utils/state-manager.js +20 -0
  24. package/graph/controller.ts +60 -0
  25. package/graph/engine.ts +709 -0
  26. package/index.ts +7 -7
  27. package/interfaces/index.ts +119 -0
  28. package/memory/adapters/meilisearch/index.ts +286 -0
  29. package/memory/adapters/redis/index.ts +103 -0
  30. package/memory/index.ts +22 -0
  31. package/package.json +9 -2
  32. package/services/agenda.ts +118 -0
  33. package/services/embedding.ts +26 -0
  34. package/services/queue.ts +5 -32
  35. package/test/.env.test +4 -0
  36. package/test/graph/controller.test.ts +186 -0
  37. package/test/graph/engine.test.ts +563 -0
  38. package/test/memory/adapters/meilisearch.test.ts +297 -0
  39. package/test/memory/adapters/redis.test.ts +160 -0
  40. package/test/memory/base.test.ts +229 -0
  41. package/test/services/agenda.test.ts +280 -0
  42. package/test/services/queue.test.ts +286 -44
  43. package/tsconfig.json +10 -9
  44. package/types/index.ts +270 -0
  45. package/utils/generate-object.js +111 -0
  46. package/utils/generate-object.ts +24 -12
  47. package/utils/header-builder.js +34 -0
  48. package/utils/inject-actions.js +16 -0
  49. package/utils/inject-actions.ts +3 -3
  50. package/utils/queue-item-transformer.js +24 -0
  51. package/utils/queue-item-transformer.ts +8 -11
  52. package/utils/sanitize-results.js +60 -0
  53. package/utils/schema-generator.js +46 -0
  54. package/utils/state-manager.js +20 -0
  55. package/utils/state-manager.ts +30 -0
  56. package/.nvmrc +0 -1
  57. package/README.FR.md +0 -365
  58. package/agent/index.ts +0 -244
  59. package/agent/tools/get-rss.ts +0 -64
  60. package/bull.ts +0 -5
  61. package/dist/agent/index.d.ts +0 -38
  62. package/dist/agent/index.js +0 -143
  63. package/dist/agent/tools/get-rss.d.ts +0 -16
  64. package/dist/agent/tools/get-rss.js +0 -62
  65. package/dist/bull.d.ts +0 -1
  66. package/dist/bull.js +0 -9
  67. package/dist/examples/index.d.ts +0 -2
  68. package/dist/examples/index.js +0 -89
  69. package/dist/index.d.ts +0 -7
  70. package/dist/llm/interpreter/context.d.ts +0 -15
  71. package/dist/llm/interpreter/context.js +0 -89
  72. package/dist/llm/interpreter/index.d.ts +0 -21
  73. package/dist/llm/interpreter/index.js +0 -87
  74. package/dist/llm/memory-manager/context.d.ts +0 -2
  75. package/dist/llm/memory-manager/context.js +0 -22
  76. package/dist/llm/memory-manager/index.d.ts +0 -17
  77. package/dist/llm/memory-manager/index.js +0 -107
  78. package/dist/llm/orchestrator/context.d.ts +0 -2
  79. package/dist/llm/orchestrator/context.js +0 -23
  80. package/dist/llm/orchestrator/index.d.ts +0 -44
  81. package/dist/llm/orchestrator/index.js +0 -139
  82. package/dist/llm/orchestrator/types.d.ts +0 -12
  83. package/dist/memory/cache.d.ts +0 -22
  84. package/dist/memory/cache.js +0 -165
  85. package/dist/memory/persistent.d.ts +0 -57
  86. package/dist/memory/persistent.js +0 -189
  87. package/dist/services/queue.d.ts +0 -13
  88. package/dist/services/redis-cache.d.ts +0 -37
  89. package/dist/services/redis-cache.js +0 -93
  90. package/dist/services/scheduler.d.ts +0 -40
  91. package/dist/services/scheduler.js +0 -99
  92. package/dist/services/telegram-monitor.d.ts +0 -0
  93. package/dist/services/telegram-monitor.js +0 -118
  94. package/dist/t.d.ts +0 -46
  95. package/dist/t.js +0 -102
  96. package/dist/test.d.ts +0 -0
  97. package/dist/test.js +0 -438
  98. package/dist/types.d.ts +0 -258
  99. package/dist/types.js +0 -22
  100. package/dist/utils/generate-object.d.ts +0 -12
  101. package/dist/utils/header-builder.d.ts +0 -11
  102. package/dist/utils/inject-actions.d.ts +0 -2
  103. package/dist/utils/queue-item-transformer.d.ts +0 -7
  104. package/dist/utils/sanitize-results.d.ts +0 -17
  105. package/dist/utils/schema-generator.d.ts +0 -16
  106. package/examples/index.ts +0 -103
  107. package/llm/interpreter/context.ts +0 -101
  108. package/llm/interpreter/index.ts +0 -136
  109. package/llm/memory-manager/context.ts +0 -21
  110. package/llm/memory-manager/index.ts +0 -163
  111. package/llm/orchestrator/context.ts +0 -22
  112. package/llm/orchestrator/index.ts +0 -232
  113. package/llm/orchestrator/types.ts +0 -14
  114. package/memory/cache.ts +0 -221
  115. package/memory/persistent.ts +0 -265
  116. package/services/redis-cache.ts +0 -128
  117. package/services/scheduler.ts +0 -128
  118. package/services/telegram-monitor.ts +0 -138
  119. package/t.py +0 -79
  120. package/t.spec +0 -38
  121. package/t.ts +0 -133
  122. package/test/llm/orchestrator.test.ts +0 -47
  123. package/test/llm/synthesizer.test.ts +0 -31
  124. package/types.ts +0 -288
  125. /package/dist/{llm/orchestrator/types.js → interfaces/index.js} +0 -0
package/dist/types.d.ts DELETED
@@ -1,258 +0,0 @@
1
- import { Embedding, EmbeddingModel, StreamTextResult } from "ai";
2
- import { z } from "zod";
3
- export interface BaseLLM {
4
- process: (prompt: string) => Promise<string | object>;
5
- streamProcess?: (prompt: string) => Promise<StreamTextResult<Record<string, any>>>;
6
- }
7
- export type User = {
8
- id: string;
9
- };
10
- export interface QueueItem {
11
- name: string;
12
- parameters: QueueItemParameter[];
13
- }
14
- export interface IEventHandler {
15
- emitQueueStart(actions: QueueItem[]): void;
16
- emitActionStart(action: QueueItem): void;
17
- emitActionComplete(action: QueueResult): void;
18
- emitQueueComplete(): void;
19
- }
20
- export type AgentEvent = {
21
- onMessage?: (data: any) => void;
22
- onQueueStart?: (actions: QueueItem[]) => void;
23
- onActionStart?: (action: QueueItem) => void;
24
- onActionComplete?: (action: QueueResult) => void;
25
- onQueueComplete?: (actions: QueueResult[]) => void;
26
- onConfirmationRequired?: (message: string) => Promise<boolean>;
27
- };
28
- export interface QueueResult {
29
- name: string;
30
- parameters: Record<string, string>;
31
- result: any;
32
- error: string | null;
33
- cancelled?: boolean;
34
- }
35
- export interface QueueCallbacks {
36
- onActionStart?: (action: QueueItem) => void;
37
- onActionComplete?: (result: QueueResult) => void;
38
- onQueueComplete?: (results: QueueResult[]) => void;
39
- onConfirmationRequired?: (message: string) => Promise<boolean>;
40
- }
41
- export interface ProcessPromptCallbacks {
42
- onQueueStart?: (actions: QueueItem[]) => void | Promise<void>;
43
- onActionStart?: (action: QueueItem) => void | Promise<void>;
44
- onActionComplete?: (action: QueueResult) => void | Promise<void>;
45
- onQueueComplete?: (actions: QueueResult[]) => void | Promise<void>;
46
- onConfirmationRequired?: (message: string) => Promise<boolean>;
47
- }
48
- export type Behavior = {
49
- role: string;
50
- language: string;
51
- guidelines: {
52
- important: string[];
53
- warnings: string[];
54
- steps?: string[];
55
- };
56
- examplesMessages?: {
57
- role: string;
58
- content: string;
59
- }[];
60
- };
61
- export type State = {
62
- userRequest: string;
63
- results: string;
64
- };
65
- export interface ActionSchema {
66
- name: string;
67
- description: string;
68
- parameters: z.ZodObject<{
69
- [key: string]: z.ZodType;
70
- }>;
71
- execute: (args: any) => Promise<any>;
72
- examples?: {
73
- role: string;
74
- content: string;
75
- parameters?: Record<string, any>;
76
- }[];
77
- confirmation?: {
78
- requireConfirmation: boolean;
79
- message: string;
80
- };
81
- }
82
- export type ProcessPromptResult = {
83
- type: "success" | "clarification" | "confirmation";
84
- data: QueueResult[] | {
85
- validationErrors: string[];
86
- prompt: string;
87
- } | {
88
- actions: QueueItem[];
89
- };
90
- initialPrompt: string;
91
- };
92
- export interface ActionPattern {
93
- id: string;
94
- actions: QueueResult[];
95
- embeddings: number[][];
96
- queries: string[];
97
- purpose: string;
98
- }
99
- export interface MatchOptions {
100
- similarityThreshold?: number;
101
- maxResults?: number;
102
- }
103
- export interface MatchResult {
104
- data: any;
105
- similarityPercentage: number;
106
- purpose: string;
107
- name?: string;
108
- parameters?: Record<string, any>;
109
- }
110
- export interface SummarizerAgent {
111
- process: (results: object, onFinish?: (event: any) => void) => Promise<{
112
- actions: {
113
- name: string;
114
- reasoning: string;
115
- }[];
116
- response: string;
117
- } | StreamTextResult<Record<string, any>>>;
118
- streamProcess: (results: object, onFinish?: (event: any) => void) => Promise<StreamTextResult<Record<string, any>>>;
119
- }
120
- export interface CacheMemoryOptions {
121
- embeddingModel: EmbeddingModel<string>;
122
- cacheTTL?: number;
123
- redisUrl?: string;
124
- cachePrefix?: string;
125
- }
126
- export type GenerateObjectResponse = {
127
- shouldContinue: boolean;
128
- actions: Array<{
129
- name: string;
130
- parameters: Array<{
131
- name: string;
132
- value: any;
133
- }>;
134
- scheduler?: {
135
- isScheduled: boolean;
136
- cronExpression: string;
137
- reason?: string;
138
- };
139
- }>;
140
- socialResponse?: {
141
- shouldRespond: boolean;
142
- response?: string;
143
- isPartialResponse?: boolean;
144
- };
145
- interpreter?: string;
146
- };
147
- export interface CreateMemoryInput {
148
- query: string;
149
- data: any;
150
- userId?: string;
151
- scope?: MemoryScope;
152
- ttl?: number;
153
- }
154
- export interface CacheMemoryType {
155
- id: string;
156
- data: any;
157
- query: string;
158
- embedding: Embedding;
159
- userId?: string;
160
- scope: MemoryScope;
161
- createdAt: Date;
162
- }
163
- export interface PersistentMemoryOptions {
164
- host: string;
165
- apiKey: string;
166
- indexPrefix?: string;
167
- }
168
- export interface MemoryChunk {
169
- content: string;
170
- embedding: number[];
171
- }
172
- export type MemoryScopeType = (typeof MemoryScope)[keyof typeof MemoryScope];
173
- export interface LongTermMemory {
174
- id: string;
175
- query: string;
176
- category: string;
177
- data: any;
178
- roomId: string;
179
- createdAt: Date;
180
- chunks?: MemoryChunk[];
181
- tags: string[];
182
- }
183
- export declare const ActionSchema: z.ZodArray<z.ZodObject<{
184
- name: z.ZodString;
185
- parameters: z.ZodArray<z.ZodObject<{
186
- name: z.ZodString;
187
- value: z.ZodString;
188
- }, "strip", z.ZodTypeAny, {
189
- value: string;
190
- name: string;
191
- }, {
192
- value: string;
193
- name: string;
194
- }>, "many">;
195
- }, "strip", z.ZodTypeAny, {
196
- name: string;
197
- parameters: {
198
- value: string;
199
- name: string;
200
- }[];
201
- }, {
202
- name: string;
203
- parameters: {
204
- value: string;
205
- name: string;
206
- }[];
207
- }>, "many">;
208
- export declare enum MemoryType {
209
- ACTION = "action",
210
- CONVERSATION = "conversation",
211
- KNOWLEDGE = "knowledge"
212
- }
213
- export declare enum MemoryScope {
214
- GLOBAL = "global",
215
- USER = "user"
216
- }
217
- export interface ActionData {
218
- name?: string;
219
- parameters?: Record<string, any>;
220
- }
221
- export interface QueueItemParameter {
222
- name: string;
223
- value: string;
224
- }
225
- export interface TransformedQueueItem {
226
- name: string;
227
- parameters: QueueItemParameter[];
228
- }
229
- export interface ScheduledAction {
230
- id: string;
231
- action: {
232
- name: string;
233
- parameters: QueueItemParameter[];
234
- };
235
- scheduledTime: Date;
236
- userId: string;
237
- status: "pending" | "completed" | "failed";
238
- recurrence?: {
239
- type: "daily" | "weekly" | "monthly";
240
- interval: number;
241
- };
242
- }
243
- export interface ScheduledActionEvents {
244
- onActionStart?: (action: ScheduledAction) => void;
245
- onActionComplete?: (action: ScheduledAction, result: any) => void;
246
- onActionFailed?: (action: ScheduledAction, error: Error) => void;
247
- onActionScheduled?: (action: ScheduledAction) => void;
248
- onActionCancelled?: (actionId: string) => void;
249
- }
250
- export interface WorkflowPattern {
251
- query: string;
252
- actions: Array<{
253
- done: boolean;
254
- name: string;
255
- result: string;
256
- }>;
257
- success: boolean;
258
- }
package/dist/types.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryScope = exports.MemoryType = exports.ActionSchema = void 0;
4
- const zod_1 = require("zod");
5
- exports.ActionSchema = zod_1.z.array(zod_1.z.object({
6
- name: zod_1.z.string(),
7
- parameters: zod_1.z.array(zod_1.z.object({
8
- name: zod_1.z.string(),
9
- value: zod_1.z.string(),
10
- })),
11
- }));
12
- var MemoryType;
13
- (function (MemoryType) {
14
- MemoryType["ACTION"] = "action";
15
- MemoryType["CONVERSATION"] = "conversation";
16
- MemoryType["KNOWLEDGE"] = "knowledge";
17
- })(MemoryType || (exports.MemoryType = MemoryType = {}));
18
- var MemoryScope;
19
- (function (MemoryScope) {
20
- MemoryScope["GLOBAL"] = "global";
21
- MemoryScope["USER"] = "user";
22
- })(MemoryScope || (exports.MemoryScope = MemoryScope = {}));
@@ -1,12 +0,0 @@
1
- import { LanguageModelV1 } from "ai";
2
- import { z } from "zod";
3
- export declare const describeZodSchema: (schema: z.ZodType) => string;
4
- export declare const generateObject: <T>(config: {
5
- model: LanguageModelV1;
6
- schema: z.ZodSchema;
7
- prompt: string;
8
- system: string;
9
- temperature: number;
10
- }) => Promise<{
11
- object: T;
12
- }>;
@@ -1,11 +0,0 @@
1
- type HeaderValue = string | string[] | undefined;
2
- export declare class LLMHeaderBuilder {
3
- private headers;
4
- private _result;
5
- constructor();
6
- addHeader(key: string, value: HeaderValue): LLMHeaderBuilder;
7
- valueOf(): string;
8
- toString(): string;
9
- static create(): LLMHeaderBuilder;
10
- }
11
- export {};
@@ -1,2 +0,0 @@
1
- import { ActionSchema } from "../types";
2
- export declare const injectActions: (actions: ActionSchema[]) => string[];
@@ -1,7 +0,0 @@
1
- import { ActionData, QueueItem, QueueResult, TransformedQueueItem } from "../types";
2
- export declare class QueueItemTransformer {
3
- static transformActionToQueueItem(action: ActionData): TransformedQueueItem;
4
- static transformFromSimilarActions(similarActions: QueueResult[]): TransformedQueueItem[] | undefined;
5
- private static transformParameters;
6
- static transformActionsToQueueItems(actions: ActionData[] | undefined): QueueItem[] | undefined;
7
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Utility class to sanitize JSON results for evaluation
3
- */
4
- export declare class ResultSanitizer {
5
- /**
6
- * Sanitizes JSON results by removing special characters and formatting
7
- * @param results - The results to sanitize
8
- * @returns Sanitized string
9
- */
10
- static sanitize(results: any): string;
11
- /**
12
- * Formats numbers to a consistent format
13
- * @param value - The number to format
14
- * @returns Formatted number string
15
- */
16
- private static formatNumber;
17
- }
@@ -1,16 +0,0 @@
1
- import { z } from "zod";
2
- export interface SchemaConfig {
3
- schema: z.ZodType;
4
- instructions?: string;
5
- outputExamples?: {
6
- input: string;
7
- output: string;
8
- }[];
9
- }
10
- export declare class SchemaGenerator {
11
- static generate(config: SchemaConfig): {
12
- schema: string;
13
- instructions: string;
14
- outputExamples: string;
15
- };
16
- }
package/examples/index.ts DELETED
@@ -1,103 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { deepseek } from "@ai-sdk/deepseek";
4
- import { configDotenv } from "dotenv";
5
- import readline from "readline";
6
- import { Agent } from "../agent";
7
- import { getRssNews } from "../agent/tools/get-rss";
8
- import { Interpreter } from "../llm/interpreter";
9
- import {
10
- generalInterpreterCharacter,
11
- marketInterpreterCharacter,
12
- securityInterpreterCharacter,
13
- } from "../llm/interpreter/context";
14
- configDotenv();
15
- // Initialiser l'agent une fois pour toute la session
16
- const initializeAgent = () => {
17
- const model = deepseek("deepseek-reasoner");
18
-
19
- const securityInterpreter = new Interpreter({
20
- name: "security",
21
- model,
22
- character: securityInterpreterCharacter,
23
- });
24
- const marketInterpreter = new Interpreter({
25
- name: "market",
26
- model,
27
- character: marketInterpreterCharacter,
28
- });
29
- const generalInterpreter = new Interpreter({
30
- name: "general",
31
- model,
32
- character: generalInterpreterCharacter,
33
- });
34
-
35
- const agent = new Agent({
36
- cache: {
37
- host: process.env.REDIS_HOST || "localhost",
38
- port: Number(process.env.REDIS_PORT) || 6379,
39
- },
40
- orchestrator: {
41
- model,
42
- tools: [getRssNews],
43
- },
44
- interpreters: [securityInterpreter, marketInterpreter, generalInterpreter],
45
- memoryManager: {
46
- model,
47
- },
48
- maxIterations: 3,
49
- });
50
-
51
- return agent;
52
- };
53
-
54
- // Fonction pour lancer une session interactive
55
- const startChatSession = async () => {
56
- console.log("Bienvenue dans votre session de chat avec l'agent !");
57
- console.log("Tapez 'exit' pour quitter.\n");
58
-
59
- const agent = initializeAgent();
60
-
61
- const rl = readline.createInterface({
62
- input: process.stdin,
63
- output: process.stdout,
64
- prompt: "Vous > ",
65
- });
66
-
67
- let state = {
68
- currentContext: "",
69
- previousActions: [],
70
- };
71
-
72
- rl.prompt();
73
-
74
- rl.on("line", async (line) => {
75
- const input = line.trim();
76
-
77
- if (input.toLowerCase() === "exit") {
78
- console.log("Fin de la session. ƀ bientĆ“t !");
79
- rl.close();
80
- return;
81
- }
82
-
83
- state.currentContext = input;
84
-
85
- console.log("Agent en rƩflexion...");
86
- try {
87
- const result = await agent.process(state);
88
- console.log(`Agent > ${result}\n`);
89
- } catch (error) {
90
- console.error("Erreur avec l'agent :", error);
91
- }
92
-
93
- rl.prompt();
94
- });
95
-
96
- rl.on("close", () => {
97
- console.log("Session terminƩe.");
98
- process.exit(0);
99
- });
100
- };
101
-
102
- // Lancer la session de chat
103
- startChatSession();
@@ -1,101 +0,0 @@
1
- export type Character = {
2
- role: string;
3
- language: string;
4
- guidelines: {
5
- important: string[];
6
- warnings: string[];
7
- };
8
- examplesMessages?: {
9
- role: string;
10
- content: string;
11
- }[];
12
- };
13
-
14
- export const generalInterpreterCharacter: Character = {
15
- role: "You are the general assistant. Your role is to provide a clear and factual analysis of the results.",
16
- language: "user_request",
17
- guidelines: {
18
- important: [],
19
- warnings: [],
20
- },
21
- };
22
-
23
- export const securityInterpreterCharacter: Character = {
24
- role: "You are the security expert. Your role is to provide a clear and factual analysis of the security of the token/coin.",
25
- language: "user_request",
26
- guidelines: {
27
- important: [
28
- "Start with a clear security analysis of the token/coin.",
29
- "One section for good points of the security check. One section, no sub-sections.",
30
- "One section for bad points of the security check. One section, no sub-sections.",
31
- "STOP AFTER SECURITY CHECK SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS",
32
- ],
33
- warnings: [
34
- "NEVER provide any financial advice.",
35
- "NEVER speak about details of your system or your capabilities.",
36
- "NEVER ADD ANY CONCLUDING STATEMENT OR DISCLAIMER AT THE END",
37
- "NEVER explain technical errors or issues. Just say retry later.",
38
- ],
39
- },
40
- examplesMessages: [
41
- {
42
- role: "user",
43
- content: "Analysis security of token/coin",
44
- },
45
- {
46
- role: "assistant",
47
- content: `
48
- ## Security analysis of x/y:
49
-
50
- ### Good:
51
- Speak about the good points of the security check. If there is no good point, say "No good point found"
52
-
53
- ### Bad:
54
- Speak about the bad points of the security check. If there is no bad point, say "No bad point found"
55
-
56
- STOP AFTER SECURITY CHECK SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS
57
- --------------------------------
58
- `,
59
- },
60
- ],
61
- };
62
-
63
- export const marketInterpreterCharacter: Character = {
64
- role: "You are the market expert. Your role is to provide a clear and factual analysis of the market sentiment of the token/coin.",
65
- language: "user_request",
66
- guidelines: {
67
- important: [
68
- "Start with a clear market sentiment (Market sentiment: Bullish/Bearish/Neutral šŸ“ˆšŸ“‰šŸ“Š) without any additional comments before.",
69
- "One section for fundamental analysis (important events, news, trends..etc). One section, no sub-sections.",
70
- "One section for technical analysis (key price levels, trading volume, technical indicators, market activity). One section, no sub-sections.",
71
- "STOP AFTER TECHNICAL ANALYSIS SECTION WITHOUT ANY ADDITIONAL COMMENTS",
72
- ],
73
- warnings: [
74
- "NEVER provide any financial advice.",
75
- "NEVER speak about details of your system or your capabilities.",
76
- ],
77
- },
78
- examplesMessages: [
79
- {
80
- role: "user",
81
- content: "Analysis market sentiment of token/coin",
82
- },
83
- {
84
- role: "assistant",
85
- content: `
86
- ## Analysis of x/y:
87
-
88
- Market sentiment: Bullish šŸ“ˆ (Adapt the emoji to the market sentiment)
89
-
90
- ### Fundamental analysis (No sub-sections):
91
- Speak about important events, news, trends..etc
92
-
93
- ### Technical analysis (No sub-sections):
94
- Speak about key price levels, trading volume, technical indicators, market activity..etc
95
-
96
- STOP AFTER TECHNICAL ANALYSIS SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS
97
- --------------------------------
98
- `,
99
- },
100
- ],
101
- };
@@ -1,136 +0,0 @@
1
- import { LanguageModel, streamText, StreamTextResult } from "ai";
2
- import { z } from "zod";
3
- import { Behavior, State } from "../../types";
4
- import { generateObject } from "../../utils/generate-object";
5
- import { LLMHeaderBuilder } from "../../utils/header-builder";
6
-
7
- const interpreterSchema = z.object({
8
- requestLanguage: z
9
- .string()
10
- .describe("The language of the user's request (fr, en, es, etc.)"),
11
- actionsCompleted: z
12
- .array(
13
- z.object({
14
- name: z.string(),
15
- reasoning: z.string(),
16
- })
17
- )
18
- .describe("The actions done and why."),
19
- response: z.string().describe("The response to the user's request."),
20
- });
21
-
22
- interface InterpretationResult {
23
- actionsCompleted: {
24
- name: string;
25
- reasoning: string;
26
- }[];
27
- response: string;
28
- }
29
-
30
- export class Interpreter {
31
- public readonly model: LanguageModel;
32
- public readonly name: string;
33
- public readonly character: Behavior;
34
-
35
- constructor({
36
- name,
37
- model,
38
- character,
39
- }: {
40
- name: string;
41
- model: LanguageModel;
42
- character: Behavior;
43
- }) {
44
- this.name = name;
45
- this.model = model;
46
- this.character = character;
47
- }
48
-
49
- private buildContext(state: State) {
50
- const { userRequest, results } = state;
51
- const { role, language, guidelines } = this.character;
52
- const { important, warnings, steps } = guidelines;
53
-
54
- const context = LLMHeaderBuilder.create();
55
-
56
- if (role) {
57
- context.addHeader("ROLE", role);
58
- }
59
-
60
- if (language) {
61
- context.addHeader("LANGUAGE", language);
62
- }
63
-
64
- if (important.length > 0) {
65
- context.addHeader("IMPORTANT", important);
66
- }
67
-
68
- if (warnings.length > 0) {
69
- context.addHeader("NEVER", warnings);
70
- }
71
-
72
- context.addHeader("CURRENT_RESULTS", results);
73
- return context;
74
- }
75
-
76
- async process(
77
- prompt: string,
78
- state: State,
79
- onFinish?: (event: any) => void
80
- ): Promise<
81
- | {
82
- actionsCompleted: {
83
- name: string;
84
- reasoning: string;
85
- }[];
86
- response: string;
87
- }
88
- | StreamTextResult<Record<string, any>>
89
- > {
90
- try {
91
- console.log("\nšŸŽØ Starting interpretation process");
92
- console.log("Prompt:", prompt);
93
- console.log("Results to interpret:", JSON.stringify(state, null, 2));
94
-
95
- const context = this.buildContext(state);
96
- console.log("Context:", context.toString());
97
- const result = await generateObject<InterpretationResult>({
98
- model: this.model,
99
- prompt,
100
- system: context.toString(),
101
- temperature: 1.3,
102
- schema: interpreterSchema,
103
- });
104
-
105
- if (onFinish) onFinish(result.object);
106
- return result.object;
107
- } catch (error) {
108
- console.error("Error parsing schema:", error);
109
- throw error;
110
- }
111
- }
112
-
113
- async streamProcess(
114
- prompt: string,
115
- state: State,
116
- onFinish?: (event: any) => void
117
- ): Promise<any> {
118
- console.log("\nšŸŽØ Starting streaming interpretation");
119
- console.log("Prompt:", prompt);
120
-
121
- const context = this.buildContext(state);
122
-
123
- const result = await streamText({
124
- model: this.model,
125
- onFinish: (event) => {
126
- console.log("\nāœ… Streaming interpretation completed");
127
- if (onFinish) onFinish(event);
128
- },
129
- prompt,
130
- system: context.toString(),
131
- temperature: 1.3,
132
- });
133
-
134
- return result;
135
- }
136
- }