diff --git a/main.py b/main.py index dce5b2b..7c0fbd5 100644 --- a/main.py +++ b/main.py @@ -70,6 +70,22 @@ EMMA_BACKEND = os.environ.get("EMMA_BACKEND", "vertex") EMMA_LOCAL_URL = os.environ.get("EMMA_LOCAL_URL", "http://localhost:8000/generate") EMMA_MODEL = os.environ.get("EMMA_MODEL", "gemini-2.5-pro") +# ── JASON: backend-flagg ──────────────────────────────────────────────────── +JASON_BACKEND = os.environ.get("JASON_BACKEND", "vertex") +JASON_LOCAL_URL = os.environ.get("JASON_LOCAL_URL", "http://34.158.137.245:11434/api/generate") +JASON_MODEL = os.environ.get("JASON_MODEL", "gemma3:4b") + +async def _jason_local(message: str) -> str: + import httpx + async with httpx.AsyncClient(timeout=120.0) as client: + r = await client.post(JASON_LOCAL_URL, json={ + "model": JASON_MODEL, + "prompt": message, + "stream": False + }) + r.raise_for_status() + return r.json().get("response", "") + _WORLD_MD_PATH = pathlib.Path(__file__).parent / "docs" / "gemma" / "world.md" try: _EMMA_SYSTEM_PROMPT = _WORLD_MD_PATH.read_text(encoding="utf-8") @@ -987,8 +1003,11 @@ async def run_agent(req: RunRequest): # ← async def error_msg = None response = None try: - from agent import _run_async # ← importer async-funksjonen - response = await _run_async( # ← await direkte + if JASON_BACKEND == "local": + response = await _jason_local(req.message) + else: + from agent import _run_async # ← importer async-funksjonen + response = await _run_async( # ← await direkte message=req.message, user_id=req.user_id, session_id=req.session_id,