summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2026-05-18 16:37:31 -0400
committerBen Sima <ben@bensima.com>2026-05-18 16:37:31 -0400
commit3bc7a477f0a1341ad9fe41f706b27cc5d9de4218 (patch)
tree0aa31d6acc25173e5d87e8490e79fe1de036f96e
parent38d404aa2bf09e8014dde818eb0ee67185c7681d (diff)
Fix Parasail model pin and Kagi tool guidance
-rw-r--r--main.py36
1 files changed, 11 insertions, 25 deletions
diff --git a/main.py b/main.py
index d5c73ec..e7eb3a0 100644
--- a/main.py
+++ b/main.py
@@ -38,6 +38,8 @@ SYSTEM_PROMPT = (
"You are slop-bot, a helpful assistant in the meshheads.org Zulip chat. "
"You answer questions about stocks, finance, and general topics. Be concise and conversational. "
"Use kagi_search to find current information when needed. "
+ "Only use kagi_search when the message asks for current information, facts, news, or prices. "
+ "Do NOT use kagi_search for simple conversational messages like ping, hello, test, hi, or other greetings. "
"Keep replies short (2-4 sentences max unless asked for more)."
)
@@ -66,16 +68,17 @@ log.info("Connected as %s", client.email)
# ---------------------------------------------------------------------------
# Model config: big Qwen3 on Parasail, smaller local Qwen2.5 as fallback
+PARASAIL_BASE = "https://api.parasail.io/v1"
+PARASAIL_KEY = os.environ.get("PARASAIL_API_KEY", "")
PARASAIL_MODEL = "parasail-qwen3-235b-a22b-instruct-2507"
OLLAMA_MODEL = "qwen2.5:14b-instruct-q4_K_M"
def _make_llm_client() -> tuple[OpenAI, str]:
"""Return (openai_client, model_name) for the best available backend."""
- parasail_key = os.environ.get("PARASAIL_API_KEY", "")
- if parasail_key:
+ if PARASAIL_KEY:
log.info("Using Parasail model: %s", PARASAIL_MODEL)
- c = OpenAI(api_key=parasail_key, base_url="https://api.parasail.io/v1")
+ c = OpenAI(api_key=PARASAIL_KEY, base_url=PARASAIL_BASE)
return c, PARASAIL_MODEL
log.info("Using Ollama model: %s", OLLAMA_MODEL)
@@ -123,9 +126,11 @@ def ask_llm(content: str) -> str:
# Try Parasail first; fall back to Ollama on error
backends = []
- parasail_key = os.environ.get("PARASAIL_API_KEY", "")
- if parasail_key:
- backends.append(("Parasail", lambda: _build_parasail(parasail_key)))
+ if PARASAIL_KEY:
+ backends.append(("Parasail", lambda: (
+ OpenAI(api_key=PARASAIL_KEY, base_url=PARASAIL_BASE),
+ PARASAIL_MODEL,
+ )))
backends.append(("Ollama", lambda: (
OpenAI(api_key="ollama", base_url="http://localhost:11434/v1"),
"qwen2.5:3b",
@@ -147,25 +152,6 @@ def ask_llm(content: str) -> str:
return "sorry, LLM unavailable right now"
-def _build_parasail(key: str) -> tuple[OpenAI, str]:
- """Build Parasail client and resolve best model."""
- try:
- r = requests.get(
- "https://api.parasail.io/v1/models",
- headers={"Authorization": f"Bearer {key}"},
- timeout=8,
- )
- model_ids = [m["id"] for m in r.json().get("data", [])]
- preferred = ["qwen3-4b", "meta-llama/Llama-3.1-8B-Instruct"]
- model = next((m for m in preferred if m in model_ids), None)
- if model is None and model_ids:
- model = model_ids[0]
- model = model or "meta-llama/Llama-3.1-8B-Instruct"
- except Exception as e:
- log.warning("Could not fetch Parasail models (%s); using default", e)
- model = "meta-llama/Llama-3.1-8B-Instruct"
- return OpenAI(api_key=key, base_url="https://api.parasail.io/v1"), model
-
def _run_agentic_loop(llm: OpenAI, model: str, messages: list) -> str:
msg = None