Skip to content

Commit 6fe6705

Browse files
committed
fix
1 parent a3f4d80 commit 6fe6705

File tree

3 files changed

+267
-106
lines changed

3 files changed

+267
-106
lines changed

packages/plugin-sui/package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
"exports": {
99
"./package.json": "./package.json",
1010
".": {
11-
"import": {
12-
"@elizaos/source": "./src/index.ts",
13-
"types": "./dist/index.d.ts",
14-
"default": "./dist/index.js"
15-
}
11+
"import": "./dist/index.js",
12+
"require": "./dist/index.cjs"
1613
}
1714
},
1815
"files": [

packages/plugin-sui/src/actions/chat_data.ts

+24-18
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
import { Action, ActionExample, Memory, IAgentRuntime, State, HandlerCallback, generateText, ModelClass, elizaLogger } from "@elizaos/core";
6868
import { analyzePostSuiPrompt } from "./prompts";
6969
import { ChatDataAction } from "./enum";
70-
import fs from 'fs';
70+
import { getFolderByUserAddress } from '../getFolderdata';
71+
import dotenv from 'dotenv';
72+
dotenv.config();
7173

7274
export default {
7375
name: "DATA_INSIGHT",
@@ -86,35 +88,39 @@ export default {
8688
_options: { [key: string]: unknown },
8789
callback?: HandlerCallback) => {
8890
try {
89-
// Read data from data.ts file
90-
const fileData = fs.readFileSync('../data/data.ts', 'utf-8');
91-
92-
// Parse JSON data from file
93-
const parsedData = JSON.parse(fileData);
94-
95-
// Check if data is not an array or has no valid posts
96-
if (!Array.isArray(parsedData) || parsedData.length === 0) {
97-
throw new Error('No valid posts found in the file');
91+
console.log("Starting to fetch data...");
92+
93+
const rawData = await getFolderByUserAddress(
94+
"0xb4b291607e91da4654cab88e5e35ba2921ef68f1b43725ef2faeae045bf5915d"
95+
);
96+
console.log("Raw data received:", rawData);
97+
98+
if (!rawData || typeof rawData === "string") {
99+
throw new Error('No valid data found');
98100
}
99101

100-
// Filter posts from parsedData to get only text
101-
const datapost = parsedData.map((item: any) => item.text);
102+
const datapost = rawData.map((item: any) => {
103+
if (!item.data.msg) {
104+
return item.data.map((i: any) => i.text).filter(Boolean);
105+
}
106+
return [];
107+
}).flat();
108+
109+
console.log("Processed data posts:", datapost);
102110

103-
// Convert array of posts into a single string
104-
const combinedText = datapost.join(' '); // Join all posts together
111+
const combinedText = datapost.join(' ');
112+
console.log("Combined text length:", combinedText.length);
113+
console.log("Sample of combined text:", combinedText.substring(0, 200));
105114

106-
// Create context for sentiment analysis
107115
const context = analyzePostSuiPrompt(message.content.text, combinedText);
108116

109-
// Send prompt to model and get response
110117
const response = await generateText({
111118
runtime,
112119
context,
113120
modelClass: ModelClass.MEDIUM,
114121
stop: ["\n"],
115122
});
116123

117-
// Send callback with analysis results
118124
callback({
119125
text: response.trim(),
120126
action: ChatDataAction.INSIGHT_DATA,
@@ -124,7 +130,7 @@ export default {
124130
});
125131

126132
} catch (error) {
127-
console.error('Error in sentiment analysis:', error);
133+
console.error('Error in data analysis:', error);
128134
throw error;
129135
}
130136
},

0 commit comments

Comments
 (0)