-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-query-routing-fix.js
More file actions
197 lines (172 loc) · 6.85 KB
/
test-query-routing-fix.js
File metadata and controls
197 lines (172 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Test the actual logic functions for comprehensive query routing
function isMarketLevelQuery(query) {
const lowerQuery = query.toLowerCase();
// Keywords that indicate market-level intent
const marketKeywords = [
'market', 'ethereum', 'polygon', 'solana', 'binance', 'avalanche', 'linea',
'blockchain', 'network', 'overall', 'general', 'activity on', 'trading on',
'volume on', 'trends', 'what\'s the', 'show me', 'any suspicious',
'wash trading volume', 'nft market', 'defi market', 'trading volume',
'market analytics', 'market insights', 'market data', 'chain activity',
'network activity', 'protocol activity'
];
// Keywords that indicate wallet-specific intent
const walletKeywords = [
'my wallet', 'my portfolio', 'my holdings', 'my balance', 'my nfts',
'my tokens', 'my defi', 'my score', 'wallet address', 'this wallet',
'connected wallet', 'my nft holdings', 'my token balance', 'my defi holdings'
];
// Check if query contains wallet address
const hasWalletAddress = /0x[a-fA-F0-9]{40}/.test(query);
// If query explicitly mentions wallet-specific terms or has an address, it's wallet-specific
if (walletKeywords.some(keyword => lowerQuery.includes(keyword)) || hasWalletAddress) {
return false;
}
// If query mentions market-level keywords, it's market-level
if (marketKeywords.some(keyword => lowerQuery.includes(keyword))) {
return true;
}
// Default: check for general blockchain/market context without personal pronouns
return !lowerQuery.includes('my ') && !lowerQuery.includes('wallet');
}
function isMarketInsightQuery(query) {
const lowerQuery = query.toLowerCase();
const marketInsightKeywords = [
'market analytics', 'market insights', 'market data', 'market trends',
'trading analytics', 'trading insights', 'volume analytics', 'sales analytics',
'nft market', 'defi market', 'market overview', 'market summary',
'holder analytics', 'trader analytics', 'market scores', 'market sentiment'
];
return marketInsightKeywords.some(keyword => lowerQuery.includes(keyword)) ||
(isMarketLevelQuery(query) && (
lowerQuery.includes('analytics') || lowerQuery.includes('insights') ||
lowerQuery.includes('trends') || lowerQuery.includes('volume') ||
lowerQuery.includes('trading') || lowerQuery.includes('holders') ||
lowerQuery.includes('traders') || lowerQuery.includes('scores')
));
}
function extractWalletAddress(query) {
const addressMatch = query.match(/0x[a-fA-F0-9]{40}/);
return addressMatch ? addressMatch[0] : null;
}
console.log('🔧 Testing Comprehensive Query Routing Fix\n');
// Test cases - the problematic queries that were being misrouted
const testCases = [
// Market-level queries (should NOT go to wallet endpoints)
{
query: 'show me washtrade activity on Ethereum',
expectedType: 'Market-level washtrade',
hasConnectedWallet: true
},
{
query: 'What\'s the wash trading volume on Polygon?',
expectedType: 'Market-level washtrade',
hasConnectedWallet: true
},
{
query: 'Any suspicious NFT trading on Solana?',
expectedType: 'Market-level washtrade',
hasConnectedWallet: true
},
{
query: 'Ethereum NFT market trends',
expectedType: 'Market-level insights',
hasConnectedWallet: true
},
{
query: 'Polygon DeFi trading volume',
expectedType: 'Market-level insights',
hasConnectedWallet: true
},
{
query: 'Show me Binance NFT analytics',
expectedType: 'Market-level insights',
hasConnectedWallet: true
},
// Wallet-specific queries (should go to wallet endpoints)
{
query: 'my wallet score',
expectedType: 'Wallet-specific',
hasConnectedWallet: true
},
{
query: 'show my portfolio',
expectedType: 'Wallet-specific',
hasConnectedWallet: true
},
{
query: 'my NFT holdings',
expectedType: 'Wallet-specific',
hasConnectedWallet: true
},
{
query: 'analyze 0x70B2D7dBEcC2238e0d2A3159320E11D7D85dEDe8',
expectedType: 'Wallet-specific (with address)',
hasConnectedWallet: false
},
// Edge cases
{
query: 'NFT volume',
expectedType: 'Market-level (ambiguous but general)',
hasConnectedWallet: true
},
{
query: 'trading performance',
expectedType: 'Market-level (ambiguous but general)',
hasConnectedWallet: true
}
];
let passedTests = 0;
let totalTests = testCases.length;
testCases.forEach((testCase, index) => {
console.log(`\n📝 Test ${index + 1}: "${testCase.query}"`);
console.log(` Expected: ${testCase.expectedType}`);
console.log(` Connected Wallet: ${testCase.hasConnectedWallet}`);
const isMarketLevel = isMarketLevelQuery(testCase.query);
const isMarketInsight = isMarketInsightQuery(testCase.query);
const hasWalletAddr = extractWalletAddress(testCase.query) !== null;
let actualType;
let shouldRouteCorrectly = true;
if (hasWalletAddr) {
actualType = 'Wallet-specific (with address)';
} else if (isMarketInsight) {
actualType = 'Market-level insights';
} else if (isMarketLevel) {
actualType = 'Market-level (educational)';
} else {
// Check if explicitly wallet-specific
const lowerQuery = testCase.query.toLowerCase();
const walletKeywords = [
'my wallet', 'my portfolio', 'my holdings', 'my balance', 'my nfts',
'my tokens', 'my defi', 'my score', 'wallet address', 'this wallet',
'connected wallet', 'my nft holdings', 'my token balance', 'my defi holdings'
];
const isExplicitlyWalletSpecific = walletKeywords.some(keyword => lowerQuery.includes(keyword));
if (isExplicitlyWalletSpecific && testCase.hasConnectedWallet) {
actualType = 'Wallet-specific';
} else if (testCase.query.toLowerCase().includes('wash')) {
actualType = 'Market-level washtrade';
} else {
actualType = 'Market-level (ambiguous but general)';
}
}
// Check if routing matches expectation
const routingCorrect = actualType.includes(testCase.expectedType.split(' ')[0]);
console.log(` Actual: ${actualType}`);
console.log(` Result: ${routingCorrect ? '✅ PASS' : '❌ FAIL'}`);
if (routingCorrect) {
passedTests++;
}
});
console.log(`\n📊 Test Results: ${passedTests}/${totalTests} tests passed`);
if (passedTests === totalTests) {
console.log('🎉 All tests passed! Query routing fix is working correctly.');
} else {
console.log('⚠️ Some tests failed. Review the logic for edge cases.');
}
console.log('\n🔧 Key Improvements Made:');
console.log(' • Intent-based routing prioritizes query meaning over connected wallet');
console.log(' • Market-level queries go to appropriate endpoints');
console.log(' • Wallet-specific queries only trigger when explicitly requested');
console.log(' • Enhanced keyword detection for better accuracy');
console.log(' • Market insights routed to specialized copilot agent');