upgraedd commited on
Commit
ffe081d
·
verified ·
1 Parent(s): 3f0f62f

Update reality adapter

Browse files
Files changed (1) hide show
  1. reality adapter +70 -1
reality adapter CHANGED
@@ -127,4 +127,73 @@ class ActualRealityAdapter:
127
  # 2) attach lm_quant_veritas context if configured to do so
128
  if self.config["adapter"].get("include_lm_context", True):
129
  analysis["_lm_context"] = {
130
- "coherence_score": lc.coherence
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  # 2) attach lm_quant_veritas context if configured to do so
128
  if self.config["adapter"].get("include_lm_context", True):
129
  analysis["_lm_context"] = {
130
+ "coherence_score": lc.coherence_score,
131
+ "entanglement_signature": lc.entanglement_signature,
132
+ "model_version": lc.model_version,
133
+ "additional_meta": lc.additional_meta,
134
+ }
135
+
136
+ # 3) add timestamp and basic metadata
137
+ record = {
138
+ "timestamp": datetime.utcnow().isoformat() + "Z",
139
+ "surface_event": surface_event,
140
+ "analysis": analysis,
141
+ }
142
+
143
+ # 4) persist to JSONL
144
+ self._append_jsonl(record)
145
+
146
+ # 5) optionally persist to sqlite
147
+ if self.use_sqlite:
148
+ self._insert_sqlite(record, lc)
149
+
150
+ logger.info("Analysis recorded for event: %s", surface_event)
151
+ return record
152
+
153
+ def _append_jsonl(self, record: Dict[str, Any]):
154
+ try:
155
+ self.jsonl_path.parent.mkdir(parents=True, exist_ok=True)
156
+ with open(self.jsonl_path, "a", encoding="utf-8") as fh:
157
+ fh.write(json.dumps(record, default=str) + "\n")
158
+ except Exception as e:
159
+ logger.error("Failed to write JSONL (%s): %s", self.jsonl_path, e)
160
+
161
+ def _insert_sqlite(self, record: Dict[str, Any], lm_context: LMContext):
162
+ try:
163
+ conn = sqlite3.connect(self.sqlite_path)
164
+ cur = conn.cursor()
165
+ cur.execute(
166
+ "INSERT INTO analyses (timestamp, surface_event, analysis_json, coherence_score, entanglement_json, model_version) VALUES (?, ?, ?, ?, ?, ?)",
167
+ (
168
+ record["timestamp"],
169
+ record["surface_event"],
170
+ json.dumps(record["analysis"], default=str),
171
+ lm_context.coherence_score,
172
+ json.dumps(lm_context.entanglement_signature, default=str),
173
+ lm_context.model_version,
174
+ ),
175
+ )
176
+ conn.commit()
177
+ conn.close()
178
+ except Exception as e:
179
+ logger.error("Failed to insert into sqlite (%s): %s", self.sqlite_path, e)
180
+
181
+
182
+ # --------------------
183
+ # CLI / Demo
184
+ # --------------------
185
+ def demo_run():
186
+ adapter = ActualRealityAdapter()
187
+ lm_ctx = LMContext(coherence_score=0.87, entanglement_signature={"signature_hash": "abc123"}, model_version="lm_quant_veritas_v7.1")
188
+ examples = [
189
+ "kennedy_assassination",
190
+ "global_banking_crash bailout",
191
+ "novel_virus_lockdown vaccination campaign",
192
+ ]
193
+ for ev in examples:
194
+ rec = adapter.analyze_and_record(ev, lm_ctx)
195
+ print("Recorded:", rec["surface_event"], "-> timestamp:", rec["timestamp"])
196
+
197
+
198
+ if __name__ == "__main__":
199
+ demo_run()