IntelliMod / src /intellimod_bridge.py
J-Barrert's picture
Upload folder using huggingface_hub
6e02dfb verified
Raw
History Blame Contribute Delete
2.88 kB
import os
import json
import re
class IntelliModBridge:
def __init__(self, repo_root="intellimod"):
# 1. Point to the root system folder
# (We removed the 'content' layer)
self.root = os.path.join(os.path.dirname(__file__), "intellimod_system")
# 2. Point to the registry
# (It is now directly inside the system folder)
self.registry_path = os.path.join(
self.root,
"system-reference/tig-routing-cards/tig-routing-registry.md"
)
self.registry_data = self._load_registry()
def _load_registry(self):
"""
Reads the Markdown file, extracts the JSON block, and loads it.
"""
if not os.path.exists(self.registry_path):
print(f"[!] IntelliMod Registry not found at: {self.registry_path}")
return {}
with open(self.registry_path, "r", encoding="utf-8") as f:
content = f.read()
# Regex to find the JSON block inside the Markdown
match = re.search(r"```json\s*(\{.*?\})\s*```", content, re.DOTALL)
if match:
try:
return json.loads(match.group(1))
except json.JSONDecodeError as e:
print(f"[!] Registry JSON Error: {e}")
return {}
return {}
def get_tig_recommendation(self, intent):
"""
Maps a TIG Intent (e.g., 'coding') to a file path from your Registry.
"""
target_category = None
target_keyword = None
# 1. Map Intent to Registry Category
if intent == "coding":
target_category = "Anthropic"
target_keyword = "sonnet"
elif intent == "creative_text":
target_category = "Open AI"
target_keyword = "gpt-5"
elif intent == "research":
target_category = "Google"
target_keyword = "gemini"
elif intent == "visual_image":
target_category = "Tool Cards"
target_keyword = "image"
if not target_category:
return None
# 2. Find the file in the JSON list
file_list = self.registry_data.get(target_category, [])
best_match = None
for file_path in file_list:
if target_keyword and target_keyword in file_path.lower():
best_match = file_path
break
# If no keyword match, just take the first one
if not best_match and file_list:
best_match = file_list[0]
if best_match:
return {
"intent": intent,
"category": target_category,
"card_name": os.path.basename(best_match),
"full_path": os.path.join(self.root, best_match)
}
return None