Spaces:
Running
Running
Reality123b
commited on
Commit
•
689b1ad
1
Parent(s):
b907e84
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from sentence_transformers import SentenceTransformer, util
|
|
10 |
import torch
|
11 |
import numpy as np
|
12 |
import networkx as nx
|
|
|
13 |
|
14 |
@dataclass
|
15 |
class ChatMessage:
|
@@ -75,6 +76,20 @@ class XylariaChat:
|
|
75 |
]
|
76 |
|
77 |
self.system_prompt = """You are a helpful and harmless assistant. You are Xylaria developed by Sk Md Saad Amin. You should think step-by-step """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
def update_internal_state(self, emotion_deltas, cognitive_load_deltas, introspection_delta, engagement_delta):
|
80 |
for emotion, delta in emotion_deltas.items():
|
@@ -102,6 +117,16 @@ class XylariaChat:
|
|
102 |
|
103 |
def update_belief_system(self, statement, belief_score):
|
104 |
self.belief_system[statement] = belief_score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
def run_metacognitive_layer(self):
|
107 |
coherence_score = self.calculate_coherence()
|
@@ -446,6 +471,25 @@ class XylariaChat:
|
|
446 |
|
447 |
self.update_knowledge_graph(entities, relationships)
|
448 |
self.run_metacognitive_layer()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
|
450 |
input_tokens = sum(len(msg['content'].split()) for msg in messages)
|
451 |
max_new_tokens = 16384 - input_tokens - 50
|
|
|
10 |
import torch
|
11 |
import numpy as np
|
12 |
import networkx as nx
|
13 |
+
from collections import Counter
|
14 |
|
15 |
@dataclass
|
16 |
class ChatMessage:
|
|
|
76 |
]
|
77 |
|
78 |
self.system_prompt = """You are a helpful and harmless assistant. You are Xylaria developed by Sk Md Saad Amin. You should think step-by-step """
|
79 |
+
|
80 |
+
self.causal_rules_db = {
|
81 |
+
"rain": ["wet roads", "flooding"],
|
82 |
+
"fire": ["heat", "smoke"],
|
83 |
+
"study": ["learn", "good grades"],
|
84 |
+
"exercise": ["fitness", "health"]
|
85 |
+
}
|
86 |
+
|
87 |
+
self.concept_generalizations = {
|
88 |
+
"planet": "system with orbiting bodies",
|
89 |
+
"star": "luminous sphere of plasma",
|
90 |
+
"democracy": "government by the people",
|
91 |
+
"photosynthesis": "process used by plants to convert light to energy"
|
92 |
+
}
|
93 |
|
94 |
def update_internal_state(self, emotion_deltas, cognitive_load_deltas, introspection_delta, engagement_delta):
|
95 |
for emotion, delta in emotion_deltas.items():
|
|
|
117 |
|
118 |
def update_belief_system(self, statement, belief_score):
|
119 |
self.belief_system[statement] = belief_score
|
120 |
+
|
121 |
+
def dynamic_belief_update(self, user_message):
|
122 |
+
sentences = [s.strip() for s in user_message.split('.') if s.strip()]
|
123 |
+
sentence_counts = Counter(sentences)
|
124 |
+
|
125 |
+
for sentence, count in sentence_counts.items():
|
126 |
+
if count >= 2:
|
127 |
+
belief_score = self.belief_system.get(sentence, 0.5)
|
128 |
+
belief_score = min(belief_score + 0.2, 1.0)
|
129 |
+
self.update_belief_system(sentence, belief_score)
|
130 |
|
131 |
def run_metacognitive_layer(self):
|
132 |
coherence_score = self.calculate_coherence()
|
|
|
471 |
|
472 |
self.update_knowledge_graph(entities, relationships)
|
473 |
self.run_metacognitive_layer()
|
474 |
+
|
475 |
+
for message in messages:
|
476 |
+
if message['role'] == 'user':
|
477 |
+
self.dynamic_belief_update(message['content'])
|
478 |
+
|
479 |
+
for cause, effects in self.causal_rules_db.items():
|
480 |
+
if any(cause in msg['content'].lower() for msg in messages if msg['role'] == 'user') and any(
|
481 |
+
effect in msg['content'].lower() for msg in messages for effect in effects):
|
482 |
+
self.store_information("Causal Inference", f"It seems {cause} might be related to {', '.join(effects)}.")
|
483 |
+
|
484 |
+
for concept, generalization in self.concept_generalizations.items():
|
485 |
+
if any(concept in msg['content'].lower() for msg in messages if msg['role'] == 'user'):
|
486 |
+
self.store_information("Inferred Knowledge", f"This reminds me of a general principle: {generalization}.")
|
487 |
+
|
488 |
+
if self.internal_state["emotions"]["curiosity"] > 0.8 and any("?" in msg['content'] for msg in messages if msg['role'] == 'user'):
|
489 |
+
print("Simulating external knowledge seeking...")
|
490 |
+
self.store_information("External Knowledge", "This is a placeholder for external information I would have found")
|
491 |
+
|
492 |
+
self.store_information("User Input", user_input)
|
493 |
|
494 |
input_tokens = sum(len(msg['content'].split()) for msg in messages)
|
495 |
max_new_tokens = 16384 - input_tokens - 50
|