Spaces:
Running
Running
Komalpreet Kaur commited on
fix: remove example contamination from neocortex extraction prompt
Browse files- app/services/neocortex.py +15 -8
- frontend/src/App.css +28 -0
- frontend/src/components/CognitiveDashboard.css +32 -0
- frontend/vite.config.js +1 -1
app/services/neocortex.py
CHANGED
|
@@ -16,18 +16,25 @@ def extract_and_store_knowledge(text: str, user_id: str = "default_user"):
|
|
| 16 |
api_key = settings.GROQ_API_KEY if settings.GROQ_API_KEY else "dummy_key"
|
| 17 |
llm = ChatGroq(model="llama-3.1-8b-instant", api_key=api_key)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
Return ONLY a valid JSON array of objects. Each object must have "subject", "relation", and "object" keys.
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
Text: {text}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
[
|
| 28 |
-
{{"subject": "BAXTER", "relation": "IS_A", "object": "DOG"}},
|
| 29 |
-
{{"subject": "BAXTER", "relation": "LIKES", "object": "TENNIS BALLS"}}
|
| 30 |
-
]
|
| 31 |
"""
|
| 32 |
try:
|
| 33 |
response = llm.invoke([HumanMessage(content=prompt)])
|
|
|
|
| 16 |
api_key = settings.GROQ_API_KEY if settings.GROQ_API_KEY else "dummy_key"
|
| 17 |
llm = ChatGroq(model="llama-3.1-8b-instant", api_key=api_key)
|
| 18 |
|
| 19 |
+
# Skip extraction for very short inputs (e.g. just a name) — not enough
|
| 20 |
+
# content to contain meaningful relationships.
|
| 21 |
+
if len(text.strip().split()) < 4:
|
| 22 |
+
print(f"Neocortex: Input too short for extraction ({len(text.strip().split())} words), skipping.")
|
| 23 |
+
return 0
|
| 24 |
+
|
| 25 |
+
prompt = f"""You are the semantic logic center of a brain. Extract factual entities and their relationships from the text below.
|
| 26 |
Return ONLY a valid JSON array of objects. Each object must have "subject", "relation", and "object" keys.
|
| 27 |
+
Use concise, CAPITALIZED entity names.
|
| 28 |
+
|
| 29 |
+
RULES:
|
| 30 |
+
1. ONLY extract facts that are EXPLICITLY stated in the text. Do NOT invent, guess, or assume anything.
|
| 31 |
+
2. If the text does not contain clear factual relationships, return an empty array: []
|
| 32 |
+
3. Do NOT use any example data. Every triple you return must come directly from the text.
|
| 33 |
|
| 34 |
Text: {text}
|
| 35 |
|
| 36 |
+
Return format: [{{"subject": "ENTITY_A", "relation": "RELATION_TYPE", "object": "ENTITY_B"}}]
|
| 37 |
+
If no relationships exist, return: []
|
|
|
|
|
|
|
|
|
|
| 38 |
"""
|
| 39 |
try:
|
| 40 |
response = llm.invoke([HumanMessage(content=prompt)])
|
frontend/src/App.css
CHANGED
|
@@ -443,6 +443,34 @@
|
|
| 443 |
to { opacity: 1; transform: translateY(0) scale(1); }
|
| 444 |
}
|
| 445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
@keyframes feedItemIn {
|
| 447 |
from { opacity: 0; transform: translateX(20px); }
|
| 448 |
to { opacity: 1; transform: translateX(0); }
|
|
|
|
| 443 |
to { opacity: 1; transform: translateY(0) scale(1); }
|
| 444 |
}
|
| 445 |
|
| 446 |
+
body.dark-theme .telemetry-overlay {
|
| 447 |
+
background: rgba(0, 0, 0, 0.6);
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
body.dark-theme .telemetry-modal {
|
| 451 |
+
background: rgba(25, 25, 25, 0.85);
|
| 452 |
+
border-color: rgba(255, 255, 255, 0.05);
|
| 453 |
+
color: #fff;
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
body.dark-theme .modal-header {
|
| 457 |
+
background: rgba(255, 255, 255, 0.02);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
body.dark-theme .modal-header h3 {
|
| 461 |
+
color: #ccc;
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
body.dark-theme .modal-header button {
|
| 465 |
+
background: rgba(255, 255, 255, 0.1);
|
| 466 |
+
color: #ccc;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
body.dark-theme .modal-header button:hover {
|
| 470 |
+
background: #ff6b35;
|
| 471 |
+
color: white;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
@keyframes feedItemIn {
|
| 475 |
from { opacity: 0; transform: translateX(20px); }
|
| 476 |
to { opacity: 1; transform: translateX(0); }
|
frontend/src/components/CognitiveDashboard.css
CHANGED
|
@@ -154,3 +154,35 @@
|
|
| 154 |
letter-spacing: -0.05em;
|
| 155 |
margin-left: auto;
|
| 156 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
letter-spacing: -0.05em;
|
| 155 |
margin-left: auto;
|
| 156 |
}
|
| 157 |
+
|
| 158 |
+
/* ── Dark Mode Overrides ── */
|
| 159 |
+
body.dark-theme .status-card {
|
| 160 |
+
background: rgba(255, 255, 255, 0.05);
|
| 161 |
+
border-color: rgba(255, 255, 255, 0.05);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
body.dark-theme .status-card h3 {
|
| 165 |
+
color: #bbb;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
body.dark-theme .system-chart {
|
| 169 |
+
background: rgba(0, 0, 0, 0.2);
|
| 170 |
+
border-color: rgba(255, 255, 255, 0.05);
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
body.dark-theme .current-state span {
|
| 174 |
+
color: #aaa;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
body.dark-theme .metric-item {
|
| 178 |
+
background: rgba(0, 0, 0, 0.2);
|
| 179 |
+
border-color: rgba(255, 255, 255, 0.05);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
body.dark-theme .metric-item strong {
|
| 183 |
+
color: #fff;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
body.dark-theme .metric-info label {
|
| 187 |
+
color: #aaa;
|
| 188 |
+
}
|
frontend/vite.config.js
CHANGED
|
@@ -7,7 +7,7 @@ export default defineConfig({
|
|
| 7 |
server: {
|
| 8 |
proxy: {
|
| 9 |
'/api': {
|
| 10 |
-
target: 'http://
|
| 11 |
changeOrigin: true,
|
| 12 |
}
|
| 13 |
}
|
|
|
|
| 7 |
server: {
|
| 8 |
proxy: {
|
| 9 |
'/api': {
|
| 10 |
+
target: 'http://localhost:8000',
|
| 11 |
changeOrigin: true,
|
| 12 |
}
|
| 13 |
}
|