Spaces:
Running
Running
AJAY KASU commited on
Commit ·
3859409
1
Parent(s): aa089b7
Fix: Implement Sentiment Guard to handle 'KEEP THE TECH' requests correctly
Browse files- api/static/index.html +25 -4
api/static/index.html
CHANGED
|
@@ -422,18 +422,39 @@
|
|
| 422 |
const lowerInput = input.toLowerCase();
|
| 423 |
|
| 424 |
// Check Sectors
|
|
|
|
| 425 |
for (const [sector, keywords] of Object.entries(sectorKeywords)) {
|
| 426 |
if (keywords.some(k => lowerInput.includes(k))) {
|
| 427 |
-
//
|
| 428 |
-
|
| 429 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
}
|
| 431 |
}
|
| 432 |
|
| 433 |
// Check Tickers
|
| 434 |
for (const [ticker, keywords] of Object.entries(stockKeywords)) {
|
| 435 |
if (keywords.some(k => lowerInput.includes(k))) {
|
| 436 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
}
|
| 438 |
}
|
| 439 |
|
|
|
|
| 422 |
const lowerInput = input.toLowerCase();
|
| 423 |
|
| 424 |
// Check Sectors
|
| 425 |
+
const includeKeywords = ["keep", "include", "with", "stay", "portfolio", "only"];
|
| 426 |
for (const [sector, keywords] of Object.entries(sectorKeywords)) {
|
| 427 |
if (keywords.some(k => lowerInput.includes(k))) {
|
| 428 |
+
// SENTIMENT GUARD: Check if the user specifically asked to KEEP this sector
|
| 429 |
+
const isKept = includeKeywords.some(inc =>
|
| 430 |
+
lowerInput.includes(`${inc} the ${sector.toLowerCase()}`) ||
|
| 431 |
+
lowerInput.includes(`${inc} ${sector.toLowerCase()}`) ||
|
| 432 |
+
// Check for common short nicknames like "tech"
|
| 433 |
+
keywords.some(key => lowerInput.includes(`${inc} the ${key}`)) ||
|
| 434 |
+
keywords.some(key => lowerInput.includes(`${inc} ${key}`))
|
| 435 |
+
);
|
| 436 |
+
|
| 437 |
+
if (!isKept) {
|
| 438 |
+
excluded.push(sector);
|
| 439 |
+
} else {
|
| 440 |
+
console.log(`Sentiment Guard: Preserving ${sector} based on include intent.`);
|
| 441 |
+
}
|
| 442 |
}
|
| 443 |
}
|
| 444 |
|
| 445 |
// Check Tickers
|
| 446 |
for (const [ticker, keywords] of Object.entries(stockKeywords)) {
|
| 447 |
if (keywords.some(k => lowerInput.includes(k))) {
|
| 448 |
+
const isKept = includeKeywords.some(inc =>
|
| 449 |
+
lowerInput.includes(`${inc} the ${ticker.toLowerCase()}`) ||
|
| 450 |
+
lowerInput.includes(`${inc} ${ticker.toLowerCase()}`) ||
|
| 451 |
+
keywords.some(key => lowerInput.includes(`${inc} the ${key}`)) ||
|
| 452 |
+
keywords.some(key => lowerInput.includes(`${inc} ${key}`))
|
| 453 |
+
);
|
| 454 |
+
|
| 455 |
+
if (!isKept) {
|
| 456 |
+
excludedTickers.push(ticker);
|
| 457 |
+
}
|
| 458 |
}
|
| 459 |
}
|
| 460 |
|