67
67
import { Action , ActionExample , Memory , IAgentRuntime , State , HandlerCallback , generateText , ModelClass , elizaLogger } from "@elizaos/core" ;
68
68
import { analyzePostSuiPrompt } from "./prompts" ;
69
69
import { ChatDataAction } from "./enum" ;
70
- import fs from 'fs' ;
70
+ import { getFolderByUserAddress } from '../getFolderdata' ;
71
+ import dotenv from 'dotenv' ;
72
+ dotenv . config ( ) ;
71
73
72
74
export default {
73
75
name : "DATA_INSIGHT" ,
@@ -86,35 +88,39 @@ export default {
86
88
_options : { [ key : string ] : unknown } ,
87
89
callback ?: HandlerCallback ) => {
88
90
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' ) ;
98
100
}
99
101
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 ) ;
102
110
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 ) ) ;
105
114
106
- // Create context for sentiment analysis
107
115
const context = analyzePostSuiPrompt ( message . content . text , combinedText ) ;
108
116
109
- // Send prompt to model and get response
110
117
const response = await generateText ( {
111
118
runtime,
112
119
context,
113
120
modelClass : ModelClass . MEDIUM ,
114
121
stop : [ "\n" ] ,
115
122
} ) ;
116
123
117
- // Send callback with analysis results
118
124
callback ( {
119
125
text : response . trim ( ) ,
120
126
action : ChatDataAction . INSIGHT_DATA ,
@@ -124,7 +130,7 @@ export default {
124
130
} ) ;
125
131
126
132
} catch ( error ) {
127
- console . error ( 'Error in sentiment analysis:' , error ) ;
133
+ console . error ( 'Error in data analysis:' , error ) ;
128
134
throw error ;
129
135
}
130
136
} ,
0 commit comments