59c9cb837d
- Intent classifier: task phrases now checked before query to prevent
"add task X" mis-routing; "job item"/"job ticket"/"work order" added
to TASK_PHRASES; "please add + project keyword" fallback added;
substring match bug fixed ("in" inside "incident" triggered query)
- brain.py: routes planning fallback to Hermes cloud (claude-sonnet-4-6)
via HERMES_URL/HERMES_API_KEY env vars; falls back to local Ollama
if Hermes is unavailable
- main.py: rolling 50-run log written to logs/jon-snow/runs.jsonl
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import logging
|
|
import os
|
|
|
|
import litellm
|
|
|
|
logger = logging.getLogger("jon-snow.brain")
|
|
litellm.set_verbose = False
|
|
|
|
FAST_MODEL = os.getenv("FAST_MODEL", "ollama/gemma4")
|
|
SMART_MODEL = os.getenv("SMART_MODEL", "ollama/gemma4")
|
|
OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "http://172.27.40.20:11434")
|
|
HERMES_URL = os.getenv("HERMES_URL", "")
|
|
HERMES_API_KEY = os.getenv("HERMES_API_KEY", "none")
|
|
|
|
|
|
async def stream_completion(messages: list[dict], use_smart: bool = False):
|
|
if HERMES_URL:
|
|
logger.info("Brain: routing to Hermes cloud (claude-sonnet-4-6)")
|
|
return await litellm.acompletion(
|
|
model="openai/hermes-agent",
|
|
messages=messages,
|
|
stream=True,
|
|
api_base=HERMES_URL,
|
|
api_key=HERMES_API_KEY,
|
|
)
|
|
|
|
model = SMART_MODEL if use_smart else FAST_MODEL
|
|
logger.info(f"Brain: model={model} smart={use_smart}")
|
|
try:
|
|
return await litellm.acompletion(
|
|
model=model,
|
|
messages=messages,
|
|
stream=True,
|
|
api_base=OLLAMA_BASE_URL if model.startswith("ollama/") else None,
|
|
)
|
|
except Exception as e:
|
|
logger.error(f"Brain error ({model}): {e}")
|
|
if use_smart and model != FAST_MODEL:
|
|
logger.info("Falling back to FAST_MODEL")
|
|
return await litellm.acompletion(
|
|
model=FAST_MODEL,
|
|
messages=messages,
|
|
stream=True,
|
|
api_base=OLLAMA_BASE_URL if FAST_MODEL.startswith("ollama/") else None,
|
|
)
|
|
raise
|