Skip to content

Personal AI, On Personal Devices

Python

Addinig initial lemonade support

Eddie Richterf3d122e9c12e
diff --git a/src/openjarvis/cli/compose_cmd.py b/src/openjarvis/cli/compose_cmd.py
index c3509c5a..ac8bcfca 100644
--- a/src/openjarvis/cli/compose_cmd.py
+++ b/src/openjarvis/cli/compose_cmd.py
@@ -197,8 +197,6 @@ def compose_run(name: str, query: tuple[str, ...], output_json: bool) -> None:
agent_kwargs = {}
if kwargs.get("system_prompt"):
agent_kwargs["system_prompt"] = kwargs["system_prompt"]
- if kwargs.get("max_turns"):
- agent_kwargs["max_turns"] = kwargs["max_turns"]
if kwargs.get("temperature"):
agent_kwargs["temperature"] = kwargs["temperature"]
@@ -206,8 +204,9 @@ def compose_run(name: str, query: tuple[str, ...], output_json: bool) -> None:
if output_json:
import json as json_mod
-
- if isinstance(result, str):
+ if isinstance(result, dict):
+ click.echo(json_mod.dumps(result, indent=2, default=str))
+ elif isinstance(result, str):
click.echo(json_mod.dumps({"content": result}, indent=2))
else:
click.echo(
@@ -220,7 +219,12 @@ def compose_run(name: str, query: tuple[str, ...], output_json: bool) -> None:
)
)
else:
- content = result if isinstance(result, str) else result.content
+ if isinstance(result, dict):
+ content = result.get("content", "")
+ elif isinstance(result, str):
+ content = result
+ else:
+ content = result.content
click.echo(content)
finally:
system.close()
diff --git a/src/openjarvis/cli/init_cmd.py b/src/openjarvis/cli/init_cmd.py
index 98b9da85..b5e46557 100644
--- a/src/openjarvis/cli/init_cmd.py
+++ b/src/openjarvis/cli/init_cmd.py
@@ -160,6 +160,15 @@ def _next_steps_text(engine: str, model: str = "") -> str:
' jarvis ask "Hello"\n\n'
" Run `jarvis doctor` to verify your setup."
),
+ "lemonade": (
+ "Next steps:\n\n"
+ " 1. Install and start Lemonade:\n"
+ " pip install lemonade-server\n"
+ " lemonade-server\n\n"
+ " 2. Try it out:\n"
+ ' jarvis ask "Hello"\n\n'
+ " Run `jarvis doctor` to verify your setup."
+ ),
}
return steps.get(engine, steps["ollama"])
diff --git a/src/openjarvis/core/config.py b/src/openjarvis/core/config.py
index dea8ab2c..86dca2f0 100644
--- a/src/openjarvis/core/config.py
+++ b/src/openjarvis/core/config.py
@@ -220,7 +220,11 @@ def recommend_engine(hw: HardwareInfo) -> str:
return "vllm"
return "ollama"
if gpu.vendor == "amd":
- return "vllm"
+ # Datacenter cards (MI300, MI325, MI350, MI355) → vllm; consumer → lemonade
+ amd_datacenter_keywords = ("MI300", "MI325", "MI350", "MI355")
+ if any(kw in gpu.name for kw in amd_datacenter_keywords):
+ return "vllm"
+ return "lemonade"
return "llamacpp"
@@ -354,6 +358,13 @@ class GemmaCppEngineConfig:
num_threads: int = 0
+@dataclass(slots=True)
+class LemonadeEngineConfig:
+ """Per-engine config for Lemonade."""
+
+ host: str = "http://localhost:8000"
+
+
@dataclass
class EngineConfig:
"""Inference engine settings with nested per-engine configs."""
@@ -370,6 +381,7 @@ class EngineConfig:
uzu: UzuEngineConfig = field(default_factory=UzuEngineConfig)
apple_fm: AppleFmEngineConfig = field(default_factory=AppleFmEngineConfig)
gemma_cpp: GemmaCppEngineConfig = field(default_factory=GemmaCppEngineConfig)
+ lemonade: LemonadeEngineConfig = field(default_factory=LemonadeEngineConfig)
# Backward-compat properties for old flat attribute names
@property
@@ -471,6 +483,15 @@ class EngineConfig:
def apple_fm_host(self, value: str) -> None:
self.apple_fm.host = value
+ @property
+ def lemonade_host(self) -> str:
+ """Deprecated: use ``engine.lemonade.host``."""
+ return self.lemonade.host
+
+ @lemonade_host.setter
+ def lemonade_host(self, value: str) -> None:
+ self.lemonade.host = value
+
@dataclass(slots=True)
class IntelligenceConfig:
diff --git a/src/openjarvis/engine/_discovery.py b/src/openjarvis/engine/_discovery.py
index 83021858..fa926704 100644
--- a/src/openjarvis/engine/_discovery.py
+++ b/src/openjarvis/engine/_discovery.py
@@ -23,6 +23,7 @@ _HOST_MAP: Dict[str, str | None] = {
"nexa": "nexa_host",
"uzu": "uzu_host",
"apple_fm": "apple_fm_host",
+ "lemonade": "lemonade_host",
"cloud": None,
"litellm": None,
"gemma_cpp": None,
diff --git a/src/openjarvis/engine/openai_compat_engines.py b/src/openjarvis/engine/openai_compat_engines.py
index 904c115e..a5827d3d 100644
--- a/src/openjarvis/engine/openai_compat_engines.py
+++ b/src/openjarvis/engine/openai_compat_engines.py
@@ -13,6 +13,7 @@ _ENGINES = {
"nexa": ("NexaEngine", "http://localhost:18181", "/v1"),
"uzu": ("UzuEngine", "http://localhost:8000", ""),
"apple_fm": ("AppleFmEngine", "http://localhost:8079", "/v1"),
+ "lemonade": ("LemonadeEngine", "http://localhost:8000", "/api/v0"),
}
for _key, (_cls_name, _default_host, _api_prefix) in _ENGINES.items():
diff --git a/src/openjarvis/intelligence/model_catalog.py b/src/openjarvis/intelligence/model_catalog.py
index 9aed067a..c98dd781 100644
--- a/src/openjarvis/intelligence/model_catalog.py
+++ b/src/openjarvis/intelligence/model_catalog.py
@@ -16,7 +16,7 @@ BUILTIN_MODELS: List[ModelSpec] = [
name="Qwen3 8B",
parameter_count_b=8.2,
context_length=32768,
- supported_engines=("vllm", "ollama", "llamacpp", "sglang"),
+ supported_engines=("vllm", "ollama", "llamacpp", "sglang", "lemonade"),
provider="alibaba",
metadata={
"architecture": "dense",
diff --git a/src/openjarvis/recipes/data/coding_assistant.toml b/src/openjarvis/recipes/data/coding_assistant.toml
index 5cfbe11b..818efdf5 100644
--- a/src/openjarvis/recipes/data/coding_assistant.toml
+++ b/src/openjarvis/recipes/data/coding_assistant.toml
@@ -4,11 +4,10 @@ description = "Code generation, review, and debugging with ReAct agent"
version = "0.1.0"
[intelligence]
-model = "qwen3:8b"
-quantization = "q4_K_M"
+model = "Qwen3-Coder-30B-A3B-Instruct-GGUF"
[engine]
-key = "ollama"
+key = "lemonade"
[agent]
type = "native_react"
diff --git a/src/openjarvis/recipes/data/general_assistant.toml b/src/openjarvis/recipes/data/general_assistant.toml
index 4e59eadb..ee4d8cb3 100644
--- a/src/openjarvis/recipes/data/general_assistant.toml
+++ b/src/openjarvis/recipes/data/general_assistant.toml
@@ -4,10 +4,10 @@ description = "Balanced general-purpose assistant"
version = "0.1.0"
[intelligence]
-model = "qwen3:8b"
+model = "Qwen3-Coder-30B-A3B-Instruct-GGUF"
[engine]
-key = "ollama"
+key = "lemonade"
[agent]
type = "orchestrator"
diff --git a/tests/engine/test_engine_model_matrix.py b/tests/engine/test_engine_model_matrix.py
index a8ad1554..312cc522 100644
--- a/tests/engine/test_engine_model_matrix.py
+++ b/tests/engine/test_engine_model_matrix.py
@@ -12,6 +12,7 @@ from openjarvis.engine.ollama import OllamaEngine
from openjarvis.engine.openai_compat_engines import (
AppleFmEngine,
ExoEngine,
+ LemonadeEngine,
LlamaCppEngine,
LMStudioEngine,
MLXEngine,
@@ -31,13 +32,16 @@ _OPENAI_COMPAT_ENGINES = [
("nexa", "http://testhost:18181", NexaEngine),
("uzu", "http://testhost:8000", UzuEngine),
("apple_fm", "http://testhost:8079", AppleFmEngine),
+ ("lemonade", "http://testhost:8000", LemonadeEngine),
]
def _api_prefix(engine_key: str) -> str:
- """Return the API prefix for an engine (Uzu uses no prefix)."""
+ """Return the API prefix for an engine."""
if engine_key == "uzu":
return ""
+ if engine_key == "lemonade":
+ return "/api/v0"
return "/v1"
diff --git a/tests/engine/test_lemonade.py b/tests/engine/test_lemonade.py
new file mode 100644
index 00000000..d882455c
--- /dev/null
+++ b/tests/engine/test_lemonade.py
@@ -0,0 +1,110 @@
+"""Tests for the Lemonade engine backend.
+
+Validates that the ``/api/v0`` prefix is used correctly for models listing
+and chat completions.
+"""
+
+from __future__ import annotations
+
+import httpx
+import pytest
+import respx
+
+from openjarvis.core.registry import EngineRegistry
+from openjarvis.core.types import Message, Role
+from openjarvis.engine._base import EngineConnectionError
+from openjarvis.engine.openai_compat_engines import LemonadeEngine
+
+
+def engine() -> LemonadeEngine:
+ EngineRegistry.register_value("lemonade", LemonadeEngine)
+ return LemonadeEngine(host="http://testhost:8000")
+
+
+class TestLemonadeEngineBasics:
+ def test_engine_id(self) -> None:
+ assert LemonadeEngine.engine_id == "lemonade"
+
+ def test_default_host(self) -> None:
+ assert LemonadeEngine._default_host == "http://localhost:8000"
+
+ def test_api_prefix(self) -> None:
+ assert LemonadeEngine._api_prefix == "/api/v0"
+
+ def test_registry_registration(self) -> None:
+ EngineRegistry.register_value("lemonade", LemonadeEngine)
+ assert EngineRegistry.get("lemonade") is LemonadeEngine
+
+
+class TestLemonadeGenerate:
+ def test_generate_uses_api_v0_prefix(self, engine: LemonadeEngine) -> None:
+ with respx.mock:
+ respx.post("http://testhost:8000/api/v0/chat/completions").mock(
+ return_value=httpx.Response(
+ 200,
+ json={
+ "choices": [
+ {
+ "message": {"content": "Hello!"},
+ "finish_reason": "stop",
+ }
+ ],
+ "usage": {
+ "prompt_tokens": 5,
+ "completion_tokens": 2,
+ "total_tokens": 7,
+ },
+ "model": "Qwen3-4B-Instruct",
+ },
+ )
+ )
+ result = engine.generate(
+ [Message(role=Role.USER, content="Hi")], model="Qwen3-4B-Instruct"
+ )
+ assert result["content"] == "Hello!"
+ assert result["usage"]["total_tokens"] == 7
+
+ def test_generate_connection_error(self, engine: LemonadeEngine) -> None:
+ with respx.mock:
+ respx.post("http://testhost:8000/api/v0/chat/completions").mock(
+ side_effect=httpx.ConnectError("refused")
+ )
+ with pytest.raises(EngineConnectionError):
+ engine.generate(
+ [Message(role=Role.USER, content="Hi")],
+ model="Qwen3-4B-Instruct",
+ )
+
+
+class TestLemonadeHealth:
+ def test_health_true(self, engine: LemonadeEngine) -> None:
+ with respx.mock:
+ respx.get("http://testhost:8000/api/v0/models").mock(
+ return_value=httpx.Response(200, json={"data": []})
+ )
+ assert engine.health() is True
+
+ def test_health_false(self, engine: LemonadeEngine) -> None:
+ with respx.mock:
+ respx.get("http://testhost:8000/api/v0/models").mock(
+ side_effect=httpx.ConnectError("refused")
+ )
+ assert engine.health() is False
+
+
+class TestLemonadeListModels:
+ def test_list_models_uses_api_v0_prefix(self, engine: LemonadeEngine) -> None:
+ with respx.mock:
+ respx.get("http://testhost:8000/api/v0/models").mock(
+ return_value=httpx.Response(
+ 200,
+ json={
+ "data": [
+ {"id": "Qwen3-4B-Instruct"},
+ {"id": "Llama-3.1-8B"},
+ ]
+ },
+ )
+ )
+ assert engine.list_models() == ["Qwen3-4B-Instruct", "Llama-3.1-8B"]
diff --git a/tests/hardware/test_amd.py b/tests/hardware/test_amd.py
index 3eecdae8..6e04dc2e 100644
--- a/tests/hardware/test_amd.py
+++ b/tests/hardware/test_amd.py
@@ -131,7 +131,7 @@ class TestAMDDetection:
class TestAMDEngineRecommendation:
- """Tests that AMD cards map to vllm."""
+ """Tests that AMD datacenter cards map to vllm, consumer cards to lemonade."""
def test_mi300x_recommends_vllm(self):
hw = HardwareInfo(
@@ -148,7 +148,30 @@ class TestAMDEngineRecommendation:
)
assert recommend_engine(hw) == "vllm"
- def test_amd_generic_recommends_vllm(self):
+ def test_mi350_recommends_vllm(self):
+ hw = HardwareInfo(
+ platform="linux",
+ cpu_brand="AMD EPYC 9654",
+ cpu_count=96,
+ ram_gb=768.0,
+ gpu=GpuInfo(
+ vendor="amd", name="AMD Instinct MI350X",
+ vram_gb=288.0, count=1,
+ ),
+ )
+ assert recommend_engine(hw) == "vllm"
+
+ def test_amd_consumer_recommends_lemonade(self):
+ hw = HardwareInfo(
+ platform="linux",
+ cpu_brand="AMD Ryzen 9 7950X",
+ cpu_count=32,
+ ram_gb=64.0,
+ gpu=GpuInfo(vendor="amd", name="AMD Radeon RX 7900 XTX", vram_gb=24.0, count=1),
+ )
+ assert recommend_engine(hw) == "lemonade"
+
+ def test_amd_generic_recommends_lemonade(self):
hw = HardwareInfo(
platform="linux",
cpu_brand="AMD EPYC",
@@ -156,7 +179,7 @@ class TestAMDEngineRecommendation:
ram_gb=256.0,
gpu=GpuInfo(vendor="amd", name="AMD GPU", vram_gb=0.0, count=1),
)
- assert recommend_engine(hw) == "vllm"
+ assert recommend_engine(hw) == "lemonade"
def test_amd_multi_gpu_recommends_vllm(self):
hw = HardwareInfo(