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

@@ -15,11 +15,36 @@ logger = logging.getLogger(__name__)
REFINER_TEMPERATURE = float(os.getenv("REFINER_TEMPERATURE", "0.3"))
REFINER_MAX_TOKENS = int(os.getenv("REFINER_MAX_TOKENS", "768"))
REFINER_DEBUG = os.getenv("REFINER_DEBUG", "false").lower() == "true"
VERBOSE_DEBUG = os.getenv("VERBOSE_DEBUG", "false").lower() == "true"
# These come from root .env
REFINE_LLM = os.getenv("REFINE_LLM", "").upper()
CORTEX_LLM = os.getenv("CORTEX_LLM", "PRIMARY").upper()
if VERBOSE_DEBUG:
logger.setLevel(logging.DEBUG)
# Console handler
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter(
'%(asctime)s [REFINE] %(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 [REFINE] %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
))
logger.addHandler(file_handler)
logger.debug("VERBOSE_DEBUG mode enabled for refine.py - logging to file")
except Exception as e:
logger.debug(f"VERBOSE_DEBUG mode enabled for refine.py - file logging failed: {e}")
# ===============================================
# Prompt builder
@@ -103,6 +128,15 @@ async def refine_answer(
# backend priority: REFINE_LLM → CORTEX_LLM → PRIMARY
backend = REFINE_LLM or CORTEX_LLM or "PRIMARY"
if VERBOSE_DEBUG:
logger.debug(f"\n{'='*80}")
logger.debug("[REFINE] Full prompt being sent to LLM:")
logger.debug(f"{'='*80}")
logger.debug(prompt)
logger.debug(f"{'='*80}")
logger.debug(f"Backend: {backend}, Temperature: {REFINER_TEMPERATURE}")
logger.debug(f"{'='*80}\n")
try:
refined = await call_llm(
prompt,
@@ -110,6 +144,13 @@ async def refine_answer(
temperature=REFINER_TEMPERATURE,
)
if VERBOSE_DEBUG:
logger.debug(f"\n{'='*80}")
logger.debug("[REFINE] LLM Response received:")
logger.debug(f"{'='*80}")
logger.debug(refined)
logger.debug(f"{'='*80}\n")
return {
"final_output": refined.strip() if refined else draft_output,
"used_backend": backend,
@@ -119,6 +160,9 @@ async def refine_answer(
except Exception as e:
logger.error(f"refine.py backend {backend} failed: {e}")
if VERBOSE_DEBUG:
logger.debug("[REFINE] Falling back to draft output due to error")
return {
"final_output": draft_output,
"used_backend": backend,