gemma-sage / oracle_bridge.py
neuralworm's picture
feat: Agentic Oracle, Multi-Message Bubbles, Filtering, and UI Fixes
8ab43a3
Raw
History Blame
3.29 kB
import os
import sys
import json
import logging
from datetime import datetime
# Setup absolute paths for the API directory
API_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "book-of-souls-json-api"))
sys.path.append(API_DIR)
# Configure logging to suppress verbose API logs if needed
api_logger = logging.getLogger("book_of_souls_api")
api_logger.setLevel(logging.WARNING)
# Global imports from the API
try:
original_cwd = os.getcwd()
os.chdir(API_DIR)
from gematria import calculate_gematria
from utils import translate_date_to_words
import torah
import bible
from deep_translator import GoogleTranslator
os.chdir(original_cwd)
except Exception as e:
print(f"Error importing modules: {e}")
calculate_gematria = None
translate_date_to_words = None
def get_oracle_data(name_or_topic: str):
"""
Queries the Book of Souls logic for a specific name/topic.
"""
if not calculate_gematria:
return {"error": "Oracle modules not properly initialized."}
original_cwd = os.getcwd()
os.chdir(API_DIR)
try:
date_obj = datetime.now()
date_words = translate_date_to_words(date_obj)
# Calculate Gematria Sum (Step)
gematria_sum = calculate_gematria(name_or_topic)
if gematria_sum < 2:
gematria_sum = 42
step = gematria_sum
rounds = "1,-1"
length = 200
tlang = "de"
strip_spaces = True
strip_in_braces = True
strip_diacritics_chk = True
translate = True # Enable automated translation
results = []
# Torah: start 1, end 5
res_torah = torah.process_json_files(1, 5, step, rounds, length, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, translate)
if res_torah: results.extend(res_torah)
# Bible: start 40, end 45
res_bible = bible.process_json_files(40, 45, step, rounds, length, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, translate)
if res_bible: results.extend(res_bible)
return {
"search_phrase": f"{date_words} {name_or_topic}",
"gematria_step": step,
"results": results[:5]
}
finally:
os.chdir(original_cwd)
def format_oracle_response(data: dict, topic: str) -> str:
"""Formats the JSON result into a prophetic response."""
if not data or "error" in data:
return f"Das Orakel ist getrübt: {data.get('error', 'Keine Verbindung zum Buch der Seelen.')}"
results = data.get("results", [])
if not results:
return f"Das Schicksalsbuch schweigt zum Thema '{topic}'. Die Sterne verweigern im Moment die Antwort."
header = f"🔮 **Prophezeiung des Orakels für: {topic}**\n\n"
header += f"*Der Gematria-Schlüssel liegt bei {data['gematria_step']}.*\n\n"
content = ""
for i, res in enumerate(results, 1):
text = res.get("translated_text") or res.get("result_text") or "..."
book = res.get("book", "Unbekannte Quelle")
content += f"**Vision {i} ({book}):**\n> \"{text}\"\n\n"
footer = "Deute diese Zeichen weise. Das Buch der Seelen hat gesprochen."
return header + content + footer