GitHub Copilot commited on
Commit
e717c2f
·
1 Parent(s): 0d4bde3

Protocol 22: Resolution of Tuple Splitting & Network Shadowing

Browse files
logos/agents/dolphin.py CHANGED
@@ -6,9 +6,8 @@ import re
6
 
7
  class EntropyKillSwitch:
8
  """
9
- Role: SYSTEM GUARD (The 'Prefix Integrator')
10
- Function: Monitors the 'Temperature' of the reasoning chain.
11
- If Entropy > Threshold, it KILLS the generation to prevent hallucination.
12
  """
13
  def __init__(self, threshold=0.75, window_size=5):
14
  self.threshold = threshold
@@ -17,55 +16,42 @@ class EntropyKillSwitch:
17
  self.status = "STABLE"
18
 
19
  def calculate_entropy(self, logprobs):
20
- """
21
- Converts log probabilities into Shannon Entropy.
22
- High Entropy = High Uncertainty = Likely Hallucination.
23
- """
24
- if not logprobs:
25
- return 0.0
26
 
27
- # Convert logprobs (dict) to probability distribution
28
- # Some APIs return logprobs as a list of dicts, others as a flat dict
29
  if isinstance(logprobs, list):
30
  probs = [math.exp(item.get('logprob', -100)) for item in logprobs]
31
  else:
32
  probs = [math.exp(lp) for lp in logprobs.values()]
33
-
34
- # Normalize (just in case)
35
  total_p = sum(probs)
36
  if total_p == 0: return 1.0
37
  probs = [p/total_p for p in probs]
38
-
39
- # Shannon Entropy Formula: H = -sum(p * log(p))
40
- entropy = -sum(p * math.log(p) for p in probs if p > 0)
41
- return entropy
42
 
43
  def monitor(self, token, logprobs):
44
- """
45
- Ingests a single token's data. Returns TRUE if we need to KILL.
46
- """
47
  current_entropy = self.calculate_entropy(logprobs)
48
  self.entropy_trace.append(current_entropy)
49
 
50
- # Keep window small (Prefix Integration)
51
  if len(self.entropy_trace) > self.window_size:
52
  self.entropy_trace.pop(0)
53
 
54
- # Calculate Rolling Average (if we have data)
55
  avg_entropy = np.mean(self.entropy_trace) if self.entropy_trace else 0
56
 
57
- # THE KILL SWITCH
58
  if avg_entropy > self.threshold:
59
  self.status = "HALLUCINATION_DETECTED"
60
- return True # TRIGGER KILL
61
-
62
  self.status = "STABLE"
63
- return False # CONTINUE
64
 
65
  def monitor_bulk(self, logprobs_content):
66
  """
67
- Analyzes a bulk list of logprobs from a non-streaming response.
68
- Expected format: choices[0].logprobs.content (List of Dicts)
69
  """
70
  if not logprobs_content:
71
  return
 
6
 
7
  class EntropyKillSwitch:
8
  """
9
+ PROTOCOL 22: THE PREFIX INTEGRATOR
10
+ Monitors the 'Temperature' of the reasoning chain.
 
11
  """
12
  def __init__(self, threshold=0.75, window_size=5):
13
  self.threshold = threshold
 
16
  self.status = "STABLE"
17
 
18
  def calculate_entropy(self, logprobs):
19
+ # Converts log probabilities into Shannon Entropy
20
+ if not logprobs: return 0.0
 
 
 
 
21
 
22
+ # Handle list vs dict format
 
23
  if isinstance(logprobs, list):
24
  probs = [math.exp(item.get('logprob', -100)) for item in logprobs]
25
  else:
26
  probs = [math.exp(lp) for lp in logprobs.values()]
27
+
 
28
  total_p = sum(probs)
29
  if total_p == 0: return 1.0
30
  probs = [p/total_p for p in probs]
31
+ return -sum(p * math.log(p) for p in probs if p > 0)
 
 
 
32
 
33
  def monitor(self, token, logprobs):
34
+ # The "Kill" Logic
 
 
35
  current_entropy = self.calculate_entropy(logprobs)
36
  self.entropy_trace.append(current_entropy)
37
 
 
38
  if len(self.entropy_trace) > self.window_size:
39
  self.entropy_trace.pop(0)
40
 
 
41
  avg_entropy = np.mean(self.entropy_trace) if self.entropy_trace else 0
42
 
43
+ # If uncertainty spikes, we kill the stream
44
  if avg_entropy > self.threshold:
45
  self.status = "HALLUCINATION_DETECTED"
46
+ return True
47
+
48
  self.status = "STABLE"
49
+ return False
50
 
51
  def monitor_bulk(self, logprobs_content):
52
  """
53
+ PROTOCOL 22: Parallel Wave Integration.
54
+ Analyzes bulk telemetry from reasoning waves.
55
  """
56
  if not logprobs_content:
57
  return
logos/connectors.py CHANGED
@@ -109,7 +109,7 @@ class OCRConnector:
109
  """
110
  try:
111
  prompt = "Extract and transcribe all visible text from this image exactly as it appears. Return only the text."
112
- full_text = self.client.chat(message=prompt, image_path=image_path)
113
 
114
  # Simple heuristic for word count
115
  word_count = len(full_text.split())
 
109
  """
110
  try:
111
  prompt = "Extract and transcribe all visible text from this image exactly as it appears. Return only the text."
112
+ full_text, _ = self.client.chat(message=prompt, image_path=image_path)
113
 
114
  # Simple heuristic for word count
115
  word_count = len(full_text.split())
logos/network/__init__.py CHANGED
@@ -1,6 +1,59 @@
 
 
 
 
1
 
2
- # logos.network package
3
- # Defines the Integer Topology and Physics Layers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- # Shared Network State (Defensive definition for legacy imports)
6
- SHARED_NETWORK = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import sympy
3
+ from collections import Counter
4
+ from typing import Dict, List, Tuple
5
 
6
+ class PrimeNetwork:
7
+ """
8
+ Represents the Radial Prime Topology as an instantiated graph object.
9
+ Used for both visualization and signal routing validation.
10
+ """
11
+
12
+ def __init__(self, max_integer: int = 1000):
13
+ self.max_integer = max_integer
14
+ self.positions: Dict[int, Tuple[float, float]] = {}
15
+ self.gpf_map: Dict[int, int] = {}
16
+ self.prime_counts = Counter()
17
+ self.primes: List[int] = []
18
+ self.composites: List[int] = []
19
+
20
+ # Build the network immediately
21
+ self._build()
22
 
23
+ def _get_gpf(self, n: int) -> int:
24
+ """Returns the Greatest Prime Factor."""
25
+ if n <= 1: return 1
26
+ i = 2
27
+ while i * i <= n:
28
+ if n % i:
29
+ i += 1
30
+ else:
31
+ n //= i
32
+ return n
33
+
34
+ def _build(self):
35
+ """Constructs the network nodes and edges."""
36
+ for n in range(1, self.max_integer + 1):
37
+ # Radial position based on Mod 10
38
+ angle = np.pi/2 - (2 * np.pi * (n % 10)) / 10 # Clockwise from Top
39
+ radius = n
40
+ self.positions[n] = (radius * np.cos(angle), radius * np.sin(angle))
41
+
42
+ if n > 1:
43
+ if sympy.isprime(n):
44
+ self.primes.append(n)
45
+ else:
46
+ self.composites.append(n)
47
+ gpf = self._get_gpf(n)
48
+ self.gpf_map[n] = gpf
49
+ self.prime_counts[gpf] += 1
50
+ elif n == 1:
51
+ self.primes.append(1)
52
+
53
+ def validate_wave(self, heat_code: int) -> bool:
54
+ """Check if a subset of the wave aligns with valid network topology."""
55
+ residue = heat_code % 10
56
+ return residue in [1, 3, 7, 9]
57
+
58
+ # Pre-calc network
59
+ SHARED_NETWORK = PrimeNetwork(max_integer=2000)