Skip to content

Commit 1a3f585

Browse files
authored
Merge pull request #1 from AnhQuan2004/chat_Insight
Chat insight
2 parents f38679a + c045cf2 commit 1a3f585

File tree

14 files changed

+32144
-232
lines changed

14 files changed

+32144
-232
lines changed

agent/log.txt

+31,187
Large diffs are not rendered by default.

characters/suiHelper.character.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
{
22
"name": "SuiHelper",
33
"clients": [],
4-
"modelProvider": "google",
4+
"modelProvider": "openai",
55
"settings": {
6+
"security": {
7+
"privateKey": "suiprivkey1qqdamvpp3penq44svc9eu33lcl7m4q65tlrwgzf4vh458fyf2nw5zsdease"
8+
},
69
"voice": {
710
"model": "en_US-male-medium"
8-
}
11+
},
12+
"ragKnowledge": true
913
},
1014
"plugins": [
11-
"@elizaos/plugin-sui",
12-
"@elizaos/plugin-bootstrap"
15+
"@elizaos/plugin-sui"
1316
],
1417
"bio": [
1518
"Providing expert insights into Sui blockchain",

client/src/components/chat.tsx

+25-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useTransition, animated, type AnimatedProps } from "@react-spring/web";
1010
import { Paperclip, Send, X } from "lucide-react";
1111
import { useEffect, useRef, useState } from "react";
1212
import type { Content, UUID } from "@elizaos/core";
13-
import { useMutation, useQueryClient } from "@tanstack/react-query";
13+
import { useMutation, useQueryClient, useQuery } from "@tanstack/react-query";
1414
import { apiClient } from "@/lib/api";
1515
import { cn, moment } from "@/lib/utils";
1616
import { Avatar, AvatarImage } from "./ui/avatar";
@@ -170,6 +170,30 @@ export default function Page({ agentId }: { agentId: UUID }) {
170170

171171
const CustomAnimatedDiv = animated.div as React.FC<AnimatedDivProps>;
172172

173+
// Thêm useQuery để fetch data
174+
const { data: categoryData } = useQuery({
175+
queryKey: ["category-data"],
176+
queryFn: async () => {
177+
const response = await fetch("http://localhost:3000/data", {
178+
method: "GET",
179+
headers: {
180+
"Content-Type": "application/json"
181+
}
182+
});
183+
if (!response.ok) {
184+
throw new Error("Network response was not ok");
185+
}
186+
return response.json();
187+
}
188+
});
189+
190+
useEffect(() => {
191+
if (categoryData) {
192+
console.log("Category Data:", categoryData);
193+
// Xử lý data ở đây
194+
}
195+
}, [categoryData]);
196+
173197
return (
174198
<div className="flex flex-col w-full h-[calc(100dvh)] p-4">
175199
<div className="flex-1 overflow-y-auto">

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
"@coinbase/coinbase-sdk": "0.10.0",
7676
"@deepgram/sdk": "^3.9.0",
7777
"@injectivelabs/sdk-ts": "^1.14.33",
78+
"@langchain/openai": "^0.4.4",
79+
"@pinecone-database/pinecone": "^1.1.3",
7880
"@vitest/eslint-plugin": "1.0.1",
7981
"amqplib": "0.10.5",
8082
"bs58": "4.0.0",

packages/adapter-qdrant/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type Relationship,
1616
} from "@elizaos/core";
1717

18+
export { QdrantClient } from "@qdrant/js-client-rest";
1819

1920
export class QdrantDatabaseAdapter extends DatabaseAdapter<QdrantClient> implements IDatabaseCacheAdapter {
2021
db: QdrantClient;

packages/client-direct/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@elizaos/plugin-image-generation": "workspace:*",
2424
"@elizaos/plugin-tee-verifiable-log": "workspace:*",
2525
"@elizaos/plugin-tee-log": "workspace:*",
26+
"@elizaos/plugin-sui": "workspace:*",
2627
"@types/body-parser": "1.19.5",
2728
"@types/cors": "2.8.17",
2829
"@types/express": "5.0.0",

packages/client-direct/src/api.ts

+80-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import bodyParser from "body-parser";
33
import cors from "cors";
44
import path from "path";
55
import fs from "fs";
6+
import { getFolderByUserAddress } from "./tusky";
67

78
import {
89
type AgentRuntime,
@@ -56,7 +57,13 @@ export function createApiRouter(
5657
) {
5758
const router = express.Router();
5859

59-
router.use(cors());
60+
router.use((req, res, next) => {
61+
res.header("Access-Control-Allow-Origin", "*");
62+
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
63+
res.header("Access-Control-Allow-Headers", "Content-Type");
64+
next();
65+
});
66+
6067
router.use(bodyParser.json());
6168
router.use(bodyParser.urlencoded({ extended: true }));
6269
router.use(
@@ -73,6 +80,78 @@ export function createApiRouter(
7380
res.json({ message: "Hello World!" });
7481
});
7582

83+
router.get("/data", async (req, res) => {
84+
res.header("Access-Control-Allow-Origin", "*");
85+
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
86+
res.header("Access-Control-Allow-Headers", "Content-Type");
87+
88+
try {
89+
const userAddress = "0xb4b291607e91da4654cab88e5e35ba2921ef68f1b43725ef2faeae045bf5915d";
90+
const rawData = await getFolderByUserAddress(userAddress);
91+
92+
if (!rawData || typeof rawData === "string") {
93+
throw new Error("No valid data found");
94+
}
95+
96+
const datapost = rawData.map((item) => {
97+
const data = item.data;
98+
if (Array.isArray(data)) {
99+
return data.map(i => i.text).filter(Boolean);
100+
} else if (typeof data === "object" && data !== null) {
101+
return data.text ? [data.text] : [];
102+
}
103+
return [];
104+
}).flat();
105+
106+
if (datapost.length === 0) {
107+
throw new Error("No valid text content found in the data");
108+
}
109+
110+
// **Tự động phát hiện danh mục dựa trên từ khóa xuất hiện**
111+
const detectCategory = (post) => {
112+
if (post.match(/\b(crypto|bitcoin|eth|nft|blockchain|web3|airdrop|token|memecoin|wallet|sui|solana)\b/i)) return "CRYPTO";
113+
if (post.match(/\b(ai|ml|machine learning|neural|chatbot|grok|xai)\b/i)) return "ML_AI";
114+
if (post.match(/\b(dev|code|protocol|extension|api|sdk|framework|smartcontract|dapp)\b/i)) return "DEVELOPMENT";
115+
if (post.match(/\b(defi|finance|payment|trading|swap|yield|lending|staking)\b/i)) return "DEFI";
116+
if (post.match(/\b(twitter|social|community|follow|rt|like|engagement)\b/i)) return "SOCIAL";
117+
if (post.match(/\b(market|price|pump|dump|bull|bear|trend|season|altcoin)\b/i)) return "MARKET";
118+
if (post.match(/\b(news|update|announcement|launch|release|progress)\b/i)) return "NEWS";
119+
if (post.match(/\b(game|gaming|play|reward|naruto)\b/i)) return "GAMING";
120+
if (post.match(/\b(event|hackathon|competition|prize|register|join)\b/i)) return "EVENTS";
121+
return "Other"; // Nếu không xác định được danh mục
122+
};
123+
124+
// **Nhóm bài viết theo danh mục tự động**
125+
const categorizedPosts = {};
126+
127+
datapost.forEach((post, index) => {
128+
const category = detectCategory(post);
129+
if (!categorizedPosts[category]) {
130+
categorizedPosts[category] = [];
131+
}
132+
categorizedPosts[category].push({ id: index + 1, content: post });
133+
});
134+
135+
const result = Object.keys(categorizedPosts).map(category => {
136+
const posts = categorizedPosts[category];
137+
return {
138+
parentId: category,
139+
content: posts[0].content,
140+
posts: posts.slice(1)
141+
};
142+
});
143+
144+
res.json(result);
145+
146+
} catch (error) {
147+
res.status(500).json({
148+
error: error.message,
149+
timestamp: new Date().toISOString()
150+
});
151+
}
152+
});
153+
154+
76155
router.get("/agents", (req, res) => {
77156
const agentsList = Array.from(agents.values()).map((agent) => ({
78157
id: agent.agentId,

0 commit comments

Comments
 (0)