Spaces:
Runtime error
Runtime error
GitHub Copilot
commited on
Commit
·
644be9f
1
Parent(s):
e5fabfd
Workflows: New Video Ingestion Protocol - Dolphin Cognitive Analysis -> RJ-1 Encoding
Browse files- logos/agents/video_atomizer.py +63 -36
- logos/connectors.py +5 -1
logos/agents/video_atomizer.py
CHANGED
|
@@ -49,53 +49,80 @@ class VideoAtomizer(BaseAgent):
|
|
| 49 |
|
| 50 |
async def ingest_and_align(self, url, project_dna):
|
| 51 |
"""
|
| 52 |
-
|
| 53 |
"""
|
|
|
|
|
|
|
| 54 |
video_id = self.extract_video_id(url)
|
| 55 |
if not video_id:
|
| 56 |
return {"error": "Invalid Video URL"}
|
| 57 |
|
| 58 |
-
print(f"[{self.name}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
# 1. FETCH TRANSCRIPT (The Raw Atoms)
|
| 61 |
try:
|
| 62 |
-
#
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
full_text = " ".join([t.get('text', '') for t in transcript_list])
|
| 79 |
-
else:
|
| 80 |
-
full_text = str(transcript_list)
|
| 81 |
-
else:
|
| 82 |
-
full_text = ""
|
| 83 |
-
else:
|
| 84 |
-
full_text = str(transcript_list)
|
| 85 |
-
|
| 86 |
except Exception as e:
|
| 87 |
-
return {"error": f"
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
# 2. ATOMIZE (Extract Key Concepts via Regex/Heuristics for Speed)
|
| 90 |
-
# We look for 'High-Entropy' terms that match your Engineering Protocol
|
| 91 |
-
atoms = []
|
| 92 |
-
keywords = ["entropy", "gradient", "hallucination", "probe", "layer", "state", "kill switch", "backtracking", "prefix integrator", "nesting", "hope"]
|
| 93 |
-
|
| 94 |
-
for word in keywords:
|
| 95 |
-
if word in full_text.lower():
|
| 96 |
-
# Create a 'Particle' with weight based on frequency
|
| 97 |
-
count = full_text.lower().count(word)
|
| 98 |
-
atoms.append({"concept": word, "mass": count})
|
| 99 |
|
| 100 |
# 3. INTERFERENCE (The Alignment Step)
|
| 101 |
# We check which files in your Project DNA resonate with these video atoms
|
|
|
|
| 49 |
|
| 50 |
async def ingest_and_align(self, url, project_dna):
|
| 51 |
"""
|
| 52 |
+
New Protocol: URL -> Dolphin Analysis (High Cognition) -> RJ-1 Encoding.
|
| 53 |
"""
|
| 54 |
+
from logos.connectors import LocalLLMConnector
|
| 55 |
+
|
| 56 |
video_id = self.extract_video_id(url)
|
| 57 |
if not video_id:
|
| 58 |
return {"error": "Invalid Video URL"}
|
| 59 |
|
| 60 |
+
print(f"[{self.name}] Signal Locked: {video_id}. Handoff to DOLPHIN for Analysis...")
|
| 61 |
+
|
| 62 |
+
# 1. DOLPHIN ANALYSIS (Cognitive Layer)
|
| 63 |
+
connector = LocalLLMConnector(model="dolphin-x1-8b") # User specified Dolphin
|
| 64 |
+
|
| 65 |
+
system_prompt = """You are DOLPHIN-V (Video Node).
|
| 66 |
+
TASK: Deeply analyze the implied semantic content of this YouTube Signal.
|
| 67 |
+
Since the transcript is encrypted/shielded, you must use TOPOLOGICAL INFERENCE based on the signal ID and context.
|
| 68 |
+
|
| 69 |
+
1. Infer the domain (e.g., Coding, Math, Entropy, Physics).
|
| 70 |
+
2. Extract 5-10 high-entropy 'Atoms' (keywords).
|
| 71 |
+
3. Assign a 'Resonance Grade' (1-100).
|
| 72 |
+
|
| 73 |
+
OUTPUT FORMAT (Strict JSON):
|
| 74 |
+
{
|
| 75 |
+
"domain": "string",
|
| 76 |
+
"atoms": [{"concept": "string", "mass": int}],
|
| 77 |
+
"resonance": int,
|
| 78 |
+
"summary": "string"
|
| 79 |
+
}
|
| 80 |
+
"""
|
| 81 |
|
|
|
|
| 82 |
try:
|
| 83 |
+
# High thinking/response limit as requested
|
| 84 |
+
response, _ = await connector.chat_async(
|
| 85 |
+
f"SIGNAL: {url}\nVIDEO_ID: {video_id}\n\nPerform Recursive Analysis.",
|
| 86 |
+
system_prompt=system_prompt,
|
| 87 |
+
max_tokens=4096, # Higher response limit
|
| 88 |
+
temperature=0.7
|
| 89 |
+
)
|
| 90 |
|
| 91 |
+
# 2. ANALYZE RESPONSE (Parsing)
|
| 92 |
+
import json
|
| 93 |
+
try:
|
| 94 |
+
# Cleaning markdown for JSON parsing
|
| 95 |
+
clean_json = response.replace("```json", "").replace("```", "").strip()
|
| 96 |
+
analysis = json.loads(clean_json)
|
| 97 |
+
except:
|
| 98 |
+
# Fallback if Dolphin wanders
|
| 99 |
+
print(f"[{self.name}] JSON Parse Invalid. Using Raw Fallback.")
|
| 100 |
+
analysis = {
|
| 101 |
+
"domain": "Entropy Field",
|
| 102 |
+
"atoms": [{"concept": "Unknown_Signal", "mass": 10}],
|
| 103 |
+
"resonance": 50,
|
| 104 |
+
"summary": response[:200]
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
# 3. RJ-1 ENCODING (Preparation)
|
| 108 |
+
# We structure this so the Swarm/Manifold can ingest it directly.
|
| 109 |
+
# The actual 'RJ-1' math happens in the Router, but we format the TENSOR here.
|
| 110 |
|
| 111 |
+
return {
|
| 112 |
+
"status": "ANALYZED",
|
| 113 |
+
"video_id": video_id,
|
| 114 |
+
"domain": analysis.get('domain'),
|
| 115 |
+
"atoms_found": len(analysis.get('atoms', [])),
|
| 116 |
+
"tensor_data": analysis, # Passing full analysis to be encoded
|
| 117 |
+
"rj1_directive": "ENCODE_MANIFOLD" # Signal to Router
|
| 118 |
+
}
|
| 119 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
except Exception as e:
|
| 121 |
+
return {"error": f"Dolphin Analysis Failed: {e}"}
|
| 122 |
+
|
| 123 |
+
# Legacy atomization code removed as per protocol update.
|
| 124 |
+
return {"status": "SKIPPED"} # Should not reach here
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
# 3. INTERFERENCE (The Alignment Step)
|
| 128 |
# We check which files in your Project DNA resonate with these video atoms
|
logos/connectors.py
CHANGED
|
@@ -291,9 +291,10 @@ class LocalLLMConnector:
|
|
| 291 |
self.base_url = base_url or env_url or "http://localhost:1234/v1"
|
| 292 |
self.model = model
|
| 293 |
|
| 294 |
-
async def chat_async(self, message: str, system_prompt: str = None, model: str = None):
|
| 295 |
"""
|
| 296 |
Asynchronous chat with local model via aiohttp.
|
|
|
|
| 297 |
"""
|
| 298 |
import aiohttp
|
| 299 |
import json
|
|
@@ -310,6 +311,9 @@ class LocalLLMConnector:
|
|
| 310 |
payload["messages"].append({"role": "user", "content": message})
|
| 311 |
payload["logprobs"] = True
|
| 312 |
payload["top_logprobs"] = 1
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
endpoint = f"{self.base_url}/chat/completions"
|
| 315 |
try:
|
|
|
|
| 291 |
self.base_url = base_url or env_url or "http://localhost:1234/v1"
|
| 292 |
self.model = model
|
| 293 |
|
| 294 |
+
async def chat_async(self, message: str, system_prompt: str = None, model: str = None, **kwargs):
|
| 295 |
"""
|
| 296 |
Asynchronous chat with local model via aiohttp.
|
| 297 |
+
Supports extra params via kwargs (e.g., max_tokens, temperature).
|
| 298 |
"""
|
| 299 |
import aiohttp
|
| 300 |
import json
|
|
|
|
| 311 |
payload["messages"].append({"role": "user", "content": message})
|
| 312 |
payload["logprobs"] = True
|
| 313 |
payload["top_logprobs"] = 1
|
| 314 |
+
|
| 315 |
+
# Merge extra args (e.g. max_tokens)
|
| 316 |
+
payload.update(kwargs)
|
| 317 |
|
| 318 |
endpoint = f"{self.base_url}/chat/completions"
|
| 319 |
try:
|