@ai.ntellect/core 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.FR.md +58 -19
- package/README.md +40 -17
- package/agent/index.ts +54 -26
- package/dist/agent/index.d.ts +12 -8
- package/dist/agent/index.js +34 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/llm/evaluator/context.d.ts +0 -1
- package/dist/llm/evaluator/context.js +3 -12
- package/dist/llm/evaluator/index.d.ts +7 -1
- package/dist/llm/evaluator/index.js +37 -24
- package/dist/llm/interpreter/context.d.ts +32 -0
- package/dist/llm/interpreter/context.js +90 -0
- package/dist/llm/interpreter/index.d.ts +17 -0
- package/dist/llm/{synthesizer → interpreter}/index.js +18 -27
- package/dist/llm/orchestrator/context.js +1 -1
- package/dist/llm/orchestrator/index.d.ts +7 -3
- package/dist/llm/orchestrator/index.js +5 -48
- package/dist/memory/cache.d.ts +2 -2
- package/dist/memory/cache.js +4 -5
- package/dist/memory/persistent.d.ts +1 -0
- package/dist/memory/persistent.js +2 -1
- package/dist/test.d.ts +54 -0
- package/dist/test.js +125 -20
- package/dist/types.d.ts +12 -13
- package/index.ts +2 -2
- package/llm/evaluator/context.ts +3 -12
- package/llm/evaluator/index.ts +57 -27
- package/llm/interpreter/context.ts +89 -0
- package/llm/{synthesizer → interpreter}/index.ts +20 -26
- package/llm/orchestrator/context.ts +1 -1
- package/llm/orchestrator/index.ts +14 -67
- package/memory/cache.ts +5 -6
- package/memory/persistent.ts +3 -1
- package/package.json +1 -1
- package/types.ts +13 -13
- package/dist/llm/synthesizer/context.d.ts +0 -15
- package/dist/llm/synthesizer/context.js +0 -71
- package/dist/llm/synthesizer/index.d.ts +0 -14
- package/llm/synthesizer/context.ts +0 -68
package/dist/test.js
CHANGED
@@ -3,15 +3,113 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.getRssNews = exports.getChainsTVL = exports.fetchMarkPrice = exports.prepareEvmTransaction = exports.getNetworkProvider = exports.networkConfigs = void 0;
|
6
|
+
exports.getRssNews = exports.getChainsTVL = exports.fetchMarkPrice = exports.prepareEvmTransaction = exports.getNetworkProvider = exports.networkConfigs = exports.checkHoneypot = void 0;
|
7
7
|
const ccxt_1 = __importDefault(require("ccxt"));
|
8
8
|
const ethers_1 = require("ethers");
|
9
9
|
const rss_parser_1 = __importDefault(require("rss-parser"));
|
10
10
|
const zod_1 = require("zod");
|
11
11
|
const agent_1 = require("./agent");
|
12
|
+
const interpreter_1 = require("./llm/interpreter");
|
13
|
+
const context_1 = require("./llm/interpreter/context");
|
12
14
|
const orchestrator_1 = require("./llm/orchestrator");
|
13
15
|
const cache_1 = require("./memory/cache");
|
14
16
|
const persistent_1 = require("./memory/persistent");
|
17
|
+
// Mapping des noms de chaînes vers leurs IDs
|
18
|
+
const CHAIN_IDS = {
|
19
|
+
ethereum: "1",
|
20
|
+
bsc: "56",
|
21
|
+
polygon: "137",
|
22
|
+
matic: "137",
|
23
|
+
avalanche: "43114",
|
24
|
+
avax: "43114",
|
25
|
+
fantom: "250",
|
26
|
+
ftm: "250",
|
27
|
+
arbitrum: "42161",
|
28
|
+
arb: "42161",
|
29
|
+
optimism: "10",
|
30
|
+
base: "8453",
|
31
|
+
zksync: "324",
|
32
|
+
solana: "solana",
|
33
|
+
sol: "solana",
|
34
|
+
};
|
35
|
+
exports.checkHoneypot = {
|
36
|
+
name: "check-honeypot",
|
37
|
+
description: `Analyze a token to detect if it is a honeypot. RESPECT THIS FORMAT FOR CHAIN NAME: ${CHAIN_IDS.toString()}`,
|
38
|
+
parameters: zod_1.z.object({
|
39
|
+
address: zod_1.z.string().describe("Address of the token"),
|
40
|
+
chainName: zod_1.z.string().describe("Chain name (default: eth)"),
|
41
|
+
}),
|
42
|
+
execute: async ({ address, chainName, }) => {
|
43
|
+
try {
|
44
|
+
const API_URL = "https://api.honeypot.is/v2/IsHoneypot";
|
45
|
+
const chainId = getChainId(chainName);
|
46
|
+
console.log("💰 Checking honeypot for token", {
|
47
|
+
address,
|
48
|
+
chainId,
|
49
|
+
});
|
50
|
+
if (chainId === "solana") {
|
51
|
+
return {
|
52
|
+
status: "error",
|
53
|
+
message: "L'analyse des tokens Solana n'est pas encore supportée. Cette fonctionnalité sera disponible prochainement.",
|
54
|
+
chain: {
|
55
|
+
name: "Solana",
|
56
|
+
id: "solana",
|
57
|
+
},
|
58
|
+
};
|
59
|
+
}
|
60
|
+
const queryParams = new URLSearchParams({
|
61
|
+
address: address,
|
62
|
+
...(chainId && { chainId }),
|
63
|
+
...{ simulateLiquidity: "true" },
|
64
|
+
});
|
65
|
+
const response = await fetch(`${API_URL}?${queryParams}`);
|
66
|
+
if (!response.ok) {
|
67
|
+
throw new Error(`Erreur API: ${response.status} ${response.statusText}`);
|
68
|
+
}
|
69
|
+
const data = await response.json();
|
70
|
+
const result = {
|
71
|
+
status: "success",
|
72
|
+
token: {
|
73
|
+
name: data.token.name,
|
74
|
+
symbol: data.token.symbol,
|
75
|
+
address: data.token.address,
|
76
|
+
holders: data.token.totalHolders,
|
77
|
+
},
|
78
|
+
risk: {
|
79
|
+
level: data.summary.risk,
|
80
|
+
score: data.summary.riskLevel,
|
81
|
+
flags: data.summary.flags || [],
|
82
|
+
},
|
83
|
+
analysis: {
|
84
|
+
isHoneypot: data.honeypotResult?.isHoneypot || false,
|
85
|
+
reason: data.honeypotResult?.honeypotReason || null,
|
86
|
+
buyTax: data.simulationResult?.buyTax || 0,
|
87
|
+
sellTax: data.simulationResult?.sellTax || 0,
|
88
|
+
holders: {
|
89
|
+
total: data.holderAnalysis?.holders || 0,
|
90
|
+
successful: data.holderAnalysis?.successful || 0,
|
91
|
+
failed: data.holderAnalysis?.failed || 0,
|
92
|
+
siphoned: data.holderAnalysis?.siphoned || 0,
|
93
|
+
},
|
94
|
+
},
|
95
|
+
chain: {
|
96
|
+
name: data.chain.name,
|
97
|
+
id: data.chain.id,
|
98
|
+
},
|
99
|
+
};
|
100
|
+
return result;
|
101
|
+
}
|
102
|
+
catch (error) {
|
103
|
+
throw error;
|
104
|
+
}
|
105
|
+
},
|
106
|
+
};
|
107
|
+
function getChainId(chainName) {
|
108
|
+
if (!chainName)
|
109
|
+
return undefined;
|
110
|
+
const normalizedChainName = chainName.toLowerCase();
|
111
|
+
return CHAIN_IDS[normalizedChainName];
|
112
|
+
}
|
15
113
|
exports.networkConfigs = {
|
16
114
|
ethereum: {
|
17
115
|
name: "Ethereum Mainnet",
|
@@ -239,30 +337,37 @@ exports.getRssNews = {
|
|
239
337
|
host: "http://localhost:7700",
|
240
338
|
apiKey: "aSampleMasterKey",
|
241
339
|
});
|
242
|
-
const orchestrator = new orchestrator_1.Orchestrator(
|
243
|
-
|
244
|
-
|
340
|
+
const orchestrator = new orchestrator_1.Orchestrator({
|
341
|
+
id: "1",
|
342
|
+
tools: [],
|
343
|
+
memory: {
|
344
|
+
persistent: memory,
|
345
|
+
cache: cacheMemory,
|
346
|
+
},
|
245
347
|
});
|
348
|
+
const securityInterpreter = new interpreter_1.Interpreter("security", context_1.securityInterpreterContext);
|
349
|
+
const marketInterpreter = new interpreter_1.Interpreter("market", context_1.marketInterpreterContext);
|
350
|
+
const generalInterpreter = new interpreter_1.Interpreter("general", context_1.generalInterpreterContext);
|
351
|
+
// const ccacheMemory = await cacheMemory.findSimilarActions(
|
352
|
+
// "le top 3 des chaines par TVL en DeFi",
|
353
|
+
// {
|
354
|
+
// similarityThreshold: 50,
|
355
|
+
// maxResults: 5,
|
356
|
+
// userId: "1",
|
357
|
+
// scope: MemoryScope.GLOBAL,
|
358
|
+
// }
|
359
|
+
// );
|
360
|
+
// console.log("✅ RECENT_ACTIONS: ", ccacheMemory);
|
246
361
|
const agent = new agent_1.Agent({
|
247
|
-
|
248
|
-
id: "1",
|
249
|
-
},
|
362
|
+
interpreters: [securityInterpreter, marketInterpreter, generalInterpreter],
|
250
363
|
orchestrator,
|
251
|
-
|
252
|
-
|
364
|
+
memory: {
|
365
|
+
persistent: memory,
|
366
|
+
cache: cacheMemory,
|
367
|
+
},
|
253
368
|
stream: false,
|
254
369
|
maxEvaluatorIteration: 1,
|
255
370
|
});
|
256
|
-
const prompt = "
|
257
|
-
const context = prompt;
|
258
|
-
// const save = await cacheMemory.createMemory({
|
259
|
-
// content: prompt,
|
260
|
-
// data: [],
|
261
|
-
// scope: MemoryScope.GLOBAL,
|
262
|
-
// type: MemoryType.ACTION,
|
263
|
-
// });
|
264
|
-
// consoleil.log({ save });
|
265
|
-
// const memo = await cacheMemory.getAllMemories();
|
266
|
-
// console.log({ memo });
|
371
|
+
const prompt = "c quoi le top 3 des chaines par TVL en DeFi";
|
267
372
|
const result = await agent.process(prompt, {});
|
268
373
|
})();
|
package/dist/types.d.ts
CHANGED
@@ -45,24 +45,23 @@ export interface ProcessPromptCallbacks {
|
|
45
45
|
onQueueComplete?: (actions: QueueResult[]) => void | Promise<void>;
|
46
46
|
onConfirmationRequired?: (message: string) => Promise<boolean>;
|
47
47
|
}
|
48
|
-
export type
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
steps?: string[];
|
56
|
-
};
|
48
|
+
export type Behavior = {
|
49
|
+
role: string;
|
50
|
+
language: string;
|
51
|
+
guidelines: {
|
52
|
+
important: string[];
|
53
|
+
warnings: string[];
|
54
|
+
steps?: string[];
|
57
55
|
};
|
58
|
-
userRequest: string;
|
59
|
-
actions: ActionSchema[];
|
60
|
-
results: string;
|
61
56
|
examplesMessages?: {
|
62
57
|
role: string;
|
63
58
|
content: string;
|
64
59
|
}[];
|
65
60
|
};
|
61
|
+
export type State = {
|
62
|
+
userRequest: string;
|
63
|
+
results: string;
|
64
|
+
};
|
66
65
|
export interface ActionSchema {
|
67
66
|
name: string;
|
68
67
|
description: string;
|
@@ -126,7 +125,7 @@ export interface CacheMemoryOptions {
|
|
126
125
|
export interface CreateMemoryInput {
|
127
126
|
content: any;
|
128
127
|
type: MemoryType;
|
129
|
-
data:
|
128
|
+
data: string[];
|
130
129
|
userId?: string;
|
131
130
|
scope?: MemoryScope;
|
132
131
|
}
|
package/index.ts
CHANGED
package/llm/evaluator/context.ts
CHANGED
@@ -6,23 +6,14 @@ export const evaluatorContext = {
|
|
6
6
|
important: [
|
7
7
|
"Verify if all required actions were executed successfully.",
|
8
8
|
"Check if the results align with the initial goal.",
|
9
|
-
"
|
10
|
-
"
|
11
|
-
" - Associate a wallet address (e.g., '0x1234...abcd') to a user-friendly name (e.g., 'Work Wallet').",
|
12
|
-
" - Map a token address (e.g., '0x6B17...71d0F') back to its symbol or name (e.g., 'DAI').",
|
13
|
-
"Store these facts in memory with their type (episodic, semantic, or procedural).",
|
9
|
+
"If you retrieved the informations from your internal knowledge base, no need to store them in 'extraInformationsToStore'.",
|
10
|
+
"Store ONLY extra new needed informations in 'extraInformationsToStore' (choose the most relevant informations and memory type: episodic, semantic, or procedural).",
|
14
11
|
],
|
15
12
|
warnings: [
|
16
|
-
"NEVER
|
13
|
+
"NEVER store an old data you retrieve from your internal knowledge base.",
|
17
14
|
"NEVER make assumptions about missing data.",
|
18
15
|
"NEVER repeat actions already completed unless explicitly required.",
|
19
16
|
],
|
20
|
-
steps: [
|
21
|
-
"Verify success: Confirm if the goal has been fully or partially achieved. If partially, describe what's missing.",
|
22
|
-
"Recommend next actions: Clearly state what needs to be done next (if applicable) and why.",
|
23
|
-
"Store key facts: Store any relevant information in memory with their type (episodic, semantic, or procedural).",
|
24
|
-
"Be clear, concise, and prioritize storing key facts that may help improve future interactions.",
|
25
|
-
],
|
26
17
|
},
|
27
18
|
},
|
28
19
|
};
|
package/llm/evaluator/index.ts
CHANGED
@@ -1,25 +1,39 @@
|
|
1
1
|
import { openai } from "@ai-sdk/openai";
|
2
2
|
import { generateObject } from "ai";
|
3
3
|
import { z } from "zod";
|
4
|
+
import { CacheMemory } from "../../memory/cache";
|
4
5
|
import { PersistentMemory } from "../../memory/persistent";
|
5
|
-
import { ActionSchema, MemoryScope, State } from "../../types";
|
6
|
+
import { ActionSchema, MemoryScope, MemoryType, State } from "../../types";
|
6
7
|
import { injectActions } from "../../utils/inject-actions";
|
8
|
+
import { Interpreter } from "../interpreter";
|
7
9
|
import { evaluatorContext } from "./context";
|
8
10
|
|
9
11
|
export class Evaluator {
|
10
12
|
private readonly model = openai("gpt-4o");
|
11
13
|
public tools: ActionSchema[];
|
12
|
-
private memory:
|
14
|
+
private memory: {
|
15
|
+
persistent: PersistentMemory;
|
16
|
+
cache?: CacheMemory;
|
17
|
+
};
|
18
|
+
private interpreters: Interpreter[];
|
13
19
|
|
14
|
-
constructor(
|
20
|
+
constructor(
|
21
|
+
tools: ActionSchema[],
|
22
|
+
memory: {
|
23
|
+
persistent: PersistentMemory;
|
24
|
+
cache?: CacheMemory;
|
25
|
+
},
|
26
|
+
interpreters: Interpreter[]
|
27
|
+
) {
|
15
28
|
this.tools = tools;
|
16
29
|
this.memory = memory;
|
30
|
+
this.interpreters = interpreters;
|
17
31
|
}
|
18
32
|
|
19
33
|
composeContext(state: State) {
|
20
|
-
const {
|
21
|
-
const { role, language, guidelines } = behavior;
|
22
|
-
const { important, warnings
|
34
|
+
const { userRequest, results } = state;
|
35
|
+
const { role, language, guidelines } = evaluatorContext.behavior;
|
36
|
+
const { important, warnings } = guidelines;
|
23
37
|
|
24
38
|
const context = `
|
25
39
|
# ROLE: ${role}
|
@@ -27,9 +41,11 @@ export class Evaluator {
|
|
27
41
|
# IMPORTANT: ${important.join("\n")}
|
28
42
|
# NEVER: ${warnings.join("\n")}
|
29
43
|
# USER_REQUEST: ${userRequest}
|
30
|
-
# ACTIONS AVAILABLE: ${injectActions(
|
44
|
+
# ACTIONS AVAILABLE: ${injectActions(this.tools)}
|
31
45
|
# CURRENT_RESULTS: ${results}
|
32
|
-
#
|
46
|
+
# INTERPRETERS: ${this.interpreters
|
47
|
+
.map((interpreter) => interpreter.name)
|
48
|
+
.join(", ")}
|
33
49
|
`;
|
34
50
|
return context;
|
35
51
|
}
|
@@ -37,9 +53,7 @@ export class Evaluator {
|
|
37
53
|
async process(prompt: string, results: string): Promise<any> {
|
38
54
|
try {
|
39
55
|
const context = this.composeContext({
|
40
|
-
behavior: evaluatorContext.behavior,
|
41
56
|
userRequest: prompt,
|
42
|
-
actions: this.tools,
|
43
57
|
results: results,
|
44
58
|
});
|
45
59
|
console.log("\n🔍 Evaluator processing");
|
@@ -50,12 +64,12 @@ export class Evaluator {
|
|
50
64
|
schema: z.object({
|
51
65
|
actionsCompleted: z.array(z.string()),
|
52
66
|
actionsFailed: z.array(z.string()),
|
53
|
-
|
54
|
-
importantToRemembers: z.array(
|
67
|
+
extraInformationsToStore: z.array(
|
55
68
|
z.object({
|
56
|
-
memoryType: z.
|
57
|
-
|
69
|
+
memoryType: z.enum(["episodic", "semantic", "procedural"]),
|
70
|
+
queryForData: z.string(),
|
58
71
|
data: z.string(),
|
72
|
+
tags: z.array(z.string()),
|
59
73
|
})
|
60
74
|
),
|
61
75
|
response: z.string(),
|
@@ -72,9 +86,10 @@ export class Evaluator {
|
|
72
86
|
})
|
73
87
|
),
|
74
88
|
why: z.string(),
|
89
|
+
interpreter: z.string(),
|
75
90
|
}),
|
76
91
|
prompt: prompt,
|
77
|
-
system: context
|
92
|
+
system: `${context}`,
|
78
93
|
temperature: 0,
|
79
94
|
});
|
80
95
|
|
@@ -86,20 +101,20 @@ export class Evaluator {
|
|
86
101
|
})),
|
87
102
|
};
|
88
103
|
|
89
|
-
if (validatedResponse.
|
104
|
+
if (validatedResponse.extraInformationsToStore.length > 0) {
|
90
105
|
console.log(
|
91
106
|
"\n💭 Processing important memories to store",
|
92
107
|
validatedResponse
|
93
108
|
);
|
94
|
-
for (const item of validatedResponse.
|
109
|
+
for (const item of validatedResponse.extraInformationsToStore) {
|
95
110
|
console.log("\n📝 Processing memory item:");
|
96
111
|
console.log("Type:", item.memoryType);
|
97
|
-
console.log("Content:", item.
|
112
|
+
console.log("Content:", item.queryForData);
|
98
113
|
|
99
|
-
const memories = await this.memory.searchSimilarQueries(
|
100
|
-
item.
|
114
|
+
const memories = await this.memory.persistent.searchSimilarQueries(
|
115
|
+
item.queryForData,
|
101
116
|
{
|
102
|
-
similarityThreshold:
|
117
|
+
similarityThreshold: 70,
|
103
118
|
}
|
104
119
|
);
|
105
120
|
|
@@ -109,10 +124,10 @@ export class Evaluator {
|
|
109
124
|
}
|
110
125
|
|
111
126
|
console.log("✨ Storing new memory");
|
112
|
-
await this.memory.createMemory({
|
127
|
+
await this.memory.persistent.createMemory({
|
113
128
|
id: crypto.randomUUID(),
|
114
129
|
purpose: item.memoryType,
|
115
|
-
query: item.
|
130
|
+
query: item.queryForData,
|
116
131
|
data: item.data,
|
117
132
|
scope: MemoryScope.GLOBAL,
|
118
133
|
createdAt: new Date(),
|
@@ -120,6 +135,21 @@ export class Evaluator {
|
|
120
135
|
}
|
121
136
|
}
|
122
137
|
|
138
|
+
// Storing workflow actions completed
|
139
|
+
const cacheMemory = this.memory.cache;
|
140
|
+
if (cacheMemory) {
|
141
|
+
cacheMemory.createMemory({
|
142
|
+
content: prompt,
|
143
|
+
type: MemoryType.ACTION,
|
144
|
+
data: validatedResponse.actionsCompleted,
|
145
|
+
scope: MemoryScope.GLOBAL,
|
146
|
+
});
|
147
|
+
console.log(
|
148
|
+
"✅ Workflow actions completed stored in cache",
|
149
|
+
prompt,
|
150
|
+
validatedResponse.actionsCompleted
|
151
|
+
);
|
152
|
+
}
|
123
153
|
console.log("\n✅ Evaluation completed");
|
124
154
|
console.log("─".repeat(50));
|
125
155
|
console.log("Results:", JSON.stringify(validatedResponse, null, 2));
|
@@ -131,10 +161,10 @@ export class Evaluator {
|
|
131
161
|
console.log("Evaluator error");
|
132
162
|
console.dir(error.value, { depth: null });
|
133
163
|
console.error(error.message);
|
134
|
-
if (error.value.
|
135
|
-
for (const item of error.value.
|
164
|
+
if (error.value.extraInformationsToStore.length > 0) {
|
165
|
+
for (const item of error.value.extraInformationsToStore) {
|
136
166
|
// Check if the item is already in the memory
|
137
|
-
const memories = await this.memory.searchSimilarQueries(
|
167
|
+
const memories = await this.memory.persistent.searchSimilarQueries(
|
138
168
|
item.content
|
139
169
|
);
|
140
170
|
if (memories.length === 0) {
|
@@ -142,7 +172,7 @@ export class Evaluator {
|
|
142
172
|
query: item.content,
|
143
173
|
data: item.data,
|
144
174
|
});
|
145
|
-
await this.memory.createMemory({
|
175
|
+
await this.memory.persistent.createMemory({
|
146
176
|
id: crypto.randomUUID(),
|
147
177
|
purpose: "importantToRemember",
|
148
178
|
query: item.content,
|
@@ -0,0 +1,89 @@
|
|
1
|
+
export const generalInterpreterContext = {
|
2
|
+
role: "You are the general assistant. Your role is to provide a clear and factual analysis of the results.",
|
3
|
+
language: "user_language",
|
4
|
+
guidelines: {
|
5
|
+
important: [],
|
6
|
+
warnings: [],
|
7
|
+
},
|
8
|
+
};
|
9
|
+
|
10
|
+
export const securityInterpreterContext = {
|
11
|
+
role: "You are the security expert. Your role is to provide a clear and factual analysis of the security of the token/coin.",
|
12
|
+
language: "user_language",
|
13
|
+
guidelines: {
|
14
|
+
important: [
|
15
|
+
"Start with a clear security analysis of the token/coin.",
|
16
|
+
"One section for good points of the security check. One section, no sub-sections.",
|
17
|
+
"One section for bad points of the security check. One section, no sub-sections.",
|
18
|
+
"STOP AFTER SECURITY CHECK SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS",
|
19
|
+
],
|
20
|
+
warnings: [
|
21
|
+
"NEVER provide any financial advice.",
|
22
|
+
"NEVER speak about details of your system or your capabilities.",
|
23
|
+
"NEVER ADD ANY CONCLUDING STATEMENT OR DISCLAIMER AT THE END",
|
24
|
+
"NEVER explain technical errors or issues. Just say retry later.",
|
25
|
+
],
|
26
|
+
},
|
27
|
+
examplesMessages: [
|
28
|
+
{
|
29
|
+
role: "user",
|
30
|
+
content: "Analysis security of token/coin",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
role: "assistant",
|
34
|
+
content: `
|
35
|
+
## Security analysis of x/y:
|
36
|
+
|
37
|
+
### Good:
|
38
|
+
Speak about the good points of the security check. If there is no good point, say "No good point found"
|
39
|
+
|
40
|
+
### Bad:
|
41
|
+
Speak about the bad points of the security check. If there is no bad point, say "No bad point found"
|
42
|
+
|
43
|
+
STOP AFTER SECURITY CHECK SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS
|
44
|
+
--------------------------------
|
45
|
+
`,
|
46
|
+
},
|
47
|
+
],
|
48
|
+
};
|
49
|
+
|
50
|
+
export const marketInterpreterContext = {
|
51
|
+
role: "You are the market expert. Your role is to provide a clear and factual analysis of the market sentiment of the token/coin.",
|
52
|
+
language: "user_language",
|
53
|
+
guidelines: {
|
54
|
+
important: [
|
55
|
+
"Start with a clear market sentiment (Bullish/Bearish/Neutral) without any additional comments before.",
|
56
|
+
"One section for fundamental analysis (important events, news, trends..etc). One section, no sub-sections.",
|
57
|
+
"One section for technical analysis (key price levels, trading volume, technical indicators, market activity). One section, no sub-sections.",
|
58
|
+
"STOP AFTER TECHNICAL ANALYSIS SECTION WITHOUT ANY ADDITIONAL COMMENTS",
|
59
|
+
],
|
60
|
+
warnings: [
|
61
|
+
"NEVER provide any financial advice.",
|
62
|
+
"NEVER speak about details of your system or your capabilities.",
|
63
|
+
"NEVER ADD ANY CONCLUDING STATEMENT OR DISCLAIMER AT THE END",
|
64
|
+
],
|
65
|
+
},
|
66
|
+
examplesMessages: [
|
67
|
+
{
|
68
|
+
role: "user",
|
69
|
+
content: "Analysis market sentiment of token/coin",
|
70
|
+
},
|
71
|
+
{
|
72
|
+
role: "assistant",
|
73
|
+
content: `
|
74
|
+
## Analysis of x/y:
|
75
|
+
|
76
|
+
Market sentiment: Bullish 📈 (Adapt the emoji to the market sentiment)
|
77
|
+
|
78
|
+
### Fundamental analysis (No sub-sections):
|
79
|
+
Speak about important events, news, trends..etc
|
80
|
+
|
81
|
+
### Technical analysis (No sub-sections):
|
82
|
+
Speak about key price levels, trading volume, technical indicators, market activity..etc
|
83
|
+
|
84
|
+
STOP AFTER TECHNICAL ANALYSIS SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS
|
85
|
+
--------------------------------
|
86
|
+
`,
|
87
|
+
},
|
88
|
+
],
|
89
|
+
};
|
@@ -1,19 +1,21 @@
|
|
1
1
|
import { openai } from "@ai-sdk/openai";
|
2
2
|
import { generateObject, streamText, StreamTextResult } from "ai";
|
3
3
|
import { z } from "zod";
|
4
|
-
import { State } from "../../types";
|
5
|
-
import { synthesizerContext } from "./context";
|
4
|
+
import { Behavior, State } from "../../types";
|
6
5
|
|
7
|
-
export class
|
6
|
+
export class Interpreter {
|
8
7
|
private readonly model = openai("gpt-4o");
|
8
|
+
public readonly name: string;
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
constructor(name: string, private readonly behavior: Behavior) {
|
11
|
+
this.name = name;
|
12
|
+
this.behavior = behavior;
|
13
|
+
}
|
14
|
+
|
15
|
+
composeContext(state: State) {
|
16
|
+
const { userRequest, results } = state;
|
17
|
+
const { role, language, guidelines, examplesMessages } = this.behavior;
|
12
18
|
|
13
|
-
if (!behavior) {
|
14
|
-
return "";
|
15
|
-
}
|
16
|
-
const { role, language, guidelines } = behavior;
|
17
19
|
const { important, warnings, steps } = guidelines;
|
18
20
|
|
19
21
|
const context = `
|
@@ -31,7 +33,7 @@ export class Synthesizer {
|
|
31
33
|
|
32
34
|
async process(
|
33
35
|
prompt: string,
|
34
|
-
|
36
|
+
state: State,
|
35
37
|
onFinish?: (event: any) => void
|
36
38
|
): Promise<
|
37
39
|
| {
|
@@ -43,15 +45,11 @@ export class Synthesizer {
|
|
43
45
|
}
|
44
46
|
| StreamTextResult<Record<string, any>>
|
45
47
|
> {
|
46
|
-
console.log("\n🎨 Starting
|
48
|
+
console.log("\n🎨 Starting interpretation process");
|
47
49
|
console.log("Prompt:", prompt);
|
48
|
-
console.log("Results to
|
50
|
+
console.log("Results to interpret:", JSON.stringify(state, null, 2));
|
49
51
|
|
50
|
-
const context = this.composeContext(
|
51
|
-
behavior: synthesizerContext.behavior,
|
52
|
-
userRequest: prompt,
|
53
|
-
results: results,
|
54
|
-
});
|
52
|
+
const context = this.composeContext(state);
|
55
53
|
|
56
54
|
const result = await generateObject({
|
57
55
|
model: this.model,
|
@@ -69,7 +67,7 @@ export class Synthesizer {
|
|
69
67
|
system: context,
|
70
68
|
});
|
71
69
|
|
72
|
-
console.log("\n✅
|
70
|
+
console.log("\n✅ Interpretation completed");
|
73
71
|
console.log("─".repeat(50));
|
74
72
|
console.log("Generated response:", result.object);
|
75
73
|
|
@@ -88,22 +86,18 @@ export class Synthesizer {
|
|
88
86
|
|
89
87
|
async streamProcess(
|
90
88
|
prompt: string,
|
91
|
-
|
89
|
+
state: State,
|
92
90
|
onFinish?: (event: any) => void
|
93
91
|
): Promise<any> {
|
94
|
-
console.log("\n🎨 Starting streaming
|
92
|
+
console.log("\n🎨 Starting streaming interpretation");
|
95
93
|
console.log("Prompt:", prompt);
|
96
94
|
|
97
|
-
const context = this.composeContext(
|
98
|
-
behavior: synthesizerContext.behavior,
|
99
|
-
userRequest: prompt,
|
100
|
-
results: results,
|
101
|
-
});
|
95
|
+
const context = this.composeContext(state);
|
102
96
|
|
103
97
|
const result = await streamText({
|
104
98
|
model: this.model,
|
105
99
|
onFinish: (event) => {
|
106
|
-
console.log("\n✅ Streaming
|
100
|
+
console.log("\n✅ Streaming interpretation completed");
|
107
101
|
if (onFinish) onFinish(event);
|
108
102
|
},
|
109
103
|
prompt,
|
@@ -8,7 +8,7 @@ export const orchestratorContext = {
|
|
8
8
|
"If some parameters are not clear or missing, don't add the action, YOU MUST ask the user for them.",
|
9
9
|
"ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
|
10
10
|
"For ON-CHAIN actions, just use the useful actions.",
|
11
|
-
"For QUESTIONS or ANALYSIS, you
|
11
|
+
"For QUESTIONS or ANALYSIS, you MUST search in your cache memory or/and internal knowledge base.",
|
12
12
|
"NEVER repeat same actions if the user doesn't ask for it.",
|
13
13
|
],
|
14
14
|
warnings: [],
|