cortex 0.2.... i think?

This commit is contained in:
serversdwn
2025-11-29 05:14:32 -05:00
parent ebe3e27095
commit cc014d0a73
6 changed files with 338 additions and 4 deletions

View File

@@ -1,10 +1,39 @@
# speak.py
import os
import logging
from llm.llm_router import call_llm
# Module-level backend selection
SPEAK_BACKEND = os.getenv("SPEAK_LLM", "PRIMARY").upper()
SPEAK_TEMPERATURE = float(os.getenv("SPEAK_TEMPERATURE", "0.6"))
VERBOSE_DEBUG = os.getenv("VERBOSE_DEBUG", "false").lower() == "true"
# Logger
logger = logging.getLogger(__name__)
if VERBOSE_DEBUG:
logger.setLevel(logging.DEBUG)
# Console handler
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter(
'%(asctime)s [SPEAK] %(levelname)s: %(message)s',
datefmt='%H:%M:%S'
))
logger.addHandler(console_handler)
# File handler
try:
os.makedirs('/app/logs', exist_ok=True)
file_handler = logging.FileHandler('/app/logs/cortex_verbose_debug.log', mode='a')
file_handler.setFormatter(logging.Formatter(
'%(asctime)s [SPEAK] %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
))
logger.addHandler(file_handler)
logger.debug("VERBOSE_DEBUG mode enabled for speak.py - logging to file")
except Exception as e:
logger.debug(f"VERBOSE_DEBUG mode enabled for speak.py - file logging failed: {e}")
# ============================================================
@@ -68,6 +97,15 @@ async def speak(final_answer: str) -> str:
backend = SPEAK_BACKEND
if VERBOSE_DEBUG:
logger.debug(f"\n{'='*80}")
logger.debug("[SPEAK] Full prompt being sent to LLM:")
logger.debug(f"{'='*80}")
logger.debug(prompt)
logger.debug(f"{'='*80}")
logger.debug(f"Backend: {backend}, Temperature: {SPEAK_TEMPERATURE}")
logger.debug(f"{'='*80}\n")
try:
lyra_output = await call_llm(
prompt,
@@ -75,12 +113,26 @@ async def speak(final_answer: str) -> str:
temperature=SPEAK_TEMPERATURE,
)
if VERBOSE_DEBUG:
logger.debug(f"\n{'='*80}")
logger.debug("[SPEAK] LLM Response received:")
logger.debug(f"{'='*80}")
logger.debug(lyra_output)
logger.debug(f"{'='*80}\n")
if lyra_output:
return lyra_output.strip()
if VERBOSE_DEBUG:
logger.debug("[SPEAK] Empty response, returning neutral answer")
return final_answer
except Exception as e:
# Hard fallback: return neutral answer instead of dying
print(f"[speak.py] Persona backend '{backend}' failed: {e}")
logger.error(f"[speak.py] Persona backend '{backend}' failed: {e}")
if VERBOSE_DEBUG:
logger.debug("[SPEAK] Falling back to neutral answer due to error")
return final_answer