Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

`app.py`、局域网模式和 `scripts/browser_bridge.py` 仍保留为本地开发、可信局域网和兼容调试入口,但都不是在线版的前置依赖。

### 连接已经运行的 Strata

本机 Streamlit 版选择 **Strata**,默认直接连接 `http://127.0.0.1:8080/v1`。
网页版选择 **Strata**,通过已有的受限本机桥接连接它:

```powershell
.\.venv\Scripts\python.exe scripts\browser_bridge.py --port 1234 --upstream http://127.0.0.1:8080/v1
```

然后打开 `http://127.0.0.1:1234/?provider=strata`,或在在线版模型中心选择 Strata。
1234 是网站安全策略已允许的本机模型端口;若 LM Studio 正在使用它,请先解决端口冲突,
不要覆盖现有服务。桥接只监听回环地址,限制来源和 API 路径;提示词和代码不经过网站服务器。
这不会下载模型或启动第二份推理实例。OllamaForge 的后台入口可让桥接在登录时无终端启动。

## 最快启动

先安装 Python 3.10+。Ollama 本体和模型都可以随后在 LeetTutor 页面内安装。
Expand Down
9 changes: 9 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# LeetTutor — JARVIS Learning System

To reuse an existing Strata server, select **Strata** in the local application
(direct endpoint `http://127.0.0.1:8080/v1`). For the browser application, run
`.venv\Scripts\python.exe scripts\browser_bridge.py --port 1234 --upstream http://127.0.0.1:8080/v1`
and open `http://127.0.0.1:1234/?provider=strata`, or select Strata on the hosted
site. Port 1234 is already permitted by the site's browser policy; refuse a
conflict with an existing LM Studio service. The existing bridge retains its
loopback bind, origin checks and bounded API. No weights are downloaded, no
second inference server is started, and model traffic stays on the PC.

[中文说明](README.md)

LeetTutor is a local-first AI learning workspace for LeetCode and system design. Its JARVIS mentor chooses the next exercise from your weak areas, reads the live problem/code/test context, and teaches through short Socratic prompts instead of dumping an answer. You can run Python solutions in the browser, use either local or cloud models, and continue on a phone through a trusted home-network host.
Expand Down
5 changes: 5 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
from leettutor.providers import (
GEMINI_PROVIDER,
OPENAI_PROVIDER,
STRATA_PROVIDER,
default_endpoints,
default_models,
is_cloud_provider,
Expand Down Expand Up @@ -130,6 +131,7 @@
PROVIDER_ENDPOINT_KEYS = {
"Ollama": "endpoint_ollama",
"LM Studio": "endpoint_lm_studio",
STRATA_PROVIDER: "endpoint_strata",
AMD_METAL_PROVIDER: "endpoint_amd_metal",
OPENAI_PROVIDER: "endpoint_openai",
GEMINI_PROVIDER: "endpoint_gemini",
Expand Down Expand Up @@ -4250,6 +4252,9 @@ def render_model_center(
) -> None:
"""Show hardware-aware recommendations and provider-specific installation."""

if provider == STRATA_PROVIDER:
st.info(_ui("Strata 复用已经启动的本机模型;这里不下载权重。", "Strata uses an already-running local model; this page does not download weights."))
return
if is_cloud_provider(provider):
with st.expander(
_ui("云端 API 设置", "Cloud API setup"),
Expand Down
2 changes: 2 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"endpoints": {
"Ollama": "http://localhost:11434",
"LM Studio": "http://localhost:1234/v1",
"Strata": "http://127.0.0.1:8080/v1",
"AMD Metal(Intel Mac)": "http://127.0.0.1:11435/v1",
"OpenAI API": "https://api.openai.com/v1",
"Gemini API": "https://generativelanguage.googleapis.com/v1beta/openai"
Expand All @@ -11,6 +12,7 @@
"models": {
"Ollama": "qwen3.5:9b",
"LM Studio": "",
"Strata": "qwen3.8-flash-next-iq3_s",
"AMD Metal(Intel Mac)": "qwen3.5:9b",
"OpenAI API": "gpt-5.6-terra",
"Gemini API": "gemini-3.6-flash"
Expand Down
4 changes: 4 additions & 0 deletions leettutor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .providers import (
GEMINI_PROVIDER,
OPENAI_PROVIDER,
STRATA_PROVIDER,
default_endpoints,
default_models,
is_cloud_provider,
Expand Down Expand Up @@ -229,6 +230,9 @@ def load_config(
config.endpoints["LM Studio"] = os.getenv(
"LEETTUTOR_LM_STUDIO_URL", config.endpoints["LM Studio"]
)
config.endpoints[STRATA_PROVIDER] = os.getenv(
"LEETTUTOR_STRATA_URL", config.endpoints[STRATA_PROVIDER]
)
config.endpoints[AMD_METAL_PROVIDER] = os.getenv(
"LEETTUTOR_AMD_METAL_URL", config.endpoints[AMD_METAL_PROVIDER]
)
Expand Down
5 changes: 4 additions & 1 deletion leettutor/llm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)

from .metal_runtime import AMD_METAL_API_KEY, AMD_METAL_PROVIDER
from .providers import GEMINI_PROVIDER, OPENAI_PROVIDER, is_cloud_provider
from .providers import GEMINI_PROVIDER, OPENAI_PROVIDER, STRATA_PROVIDER, is_cloud_provider


class LocalLLMError(RuntimeError):
Expand Down Expand Up @@ -89,6 +89,8 @@ def __init__(
default_key = AMD_METAL_API_KEY
elif settings.provider == "LM Studio":
default_key = "lm-studio"
elif settings.provider == STRATA_PROVIDER:
default_key = "local-strata"
else:
default_key = settings.api_key
self._client = client_factory(
Expand Down Expand Up @@ -162,6 +164,7 @@ def stream_chat(
request["reasoning_effort"] = reasoning_effort
if "qwen3" in folded_model and self.settings.provider in {
"LM Studio",
STRATA_PROVIDER,
AMD_METAL_PROVIDER,
}:
# Qwen 3.x chat templates expose a boolean thinking switch.
Expand Down
4 changes: 4 additions & 0 deletions leettutor/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

OPENAI_PROVIDER = "OpenAI API"
GEMINI_PROVIDER = "Gemini API"
STRATA_PROVIDER = "Strata"
STRATA_MODEL = "qwen3.8-flash-next-iq3_s"


def default_endpoints() -> dict[str, str]:
return {
"Ollama": "http://localhost:11434",
"LM Studio": "http://localhost:1234/v1",
STRATA_PROVIDER: "http://127.0.0.1:8080/v1",
AMD_METAL_PROVIDER: AMD_METAL_ENDPOINT,
OPENAI_PROVIDER: "https://api.openai.com/v1",
GEMINI_PROVIDER: "https://generativelanguage.googleapis.com/v1beta/openai",
Expand All @@ -25,6 +28,7 @@ def default_models() -> dict[str, str]:
return {
"Ollama": "",
"LM Studio": "",
STRATA_PROVIDER: STRATA_MODEL,
AMD_METAL_PROVIDER: "qwen3.5:9b",
OPENAI_PROVIDER: "gpt-5.6-terra",
GEMINI_PROVIDER: "gemini-3.6-flash",
Expand Down
13 changes: 12 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
from pathlib import Path

from leettutor.config import AppConfig, load_config, save_config, save_secrets
from leettutor.providers import GEMINI_PROVIDER, OPENAI_PROVIDER
from leettutor.providers import GEMINI_PROVIDER, OPENAI_PROVIDER, STRATA_PROVIDER, STRATA_MODEL


def test_strata_configuration_preserves_other_providers(tmp_path: Path, monkeypatch) -> None:
monkeypatch.setenv("LEETTUTOR_STRATA_URL", "http://127.0.0.1:8080/v1")
path = tmp_path / "config.json"
save_config(AppConfig(provider=STRATA_PROVIDER, model=STRATA_MODEL), path)
configured = load_config(path)
assert configured.provider == STRATA_PROVIDER
assert configured.models[STRATA_PROVIDER] == STRATA_MODEL
assert configured.endpoints["Ollama"] == "http://localhost:11434"
assert configured.endpoints[STRATA_PROVIDER] == "http://127.0.0.1:8080/v1"


def test_config_round_trip(tmp_path: Path, monkeypatch) -> None:
Expand Down
13 changes: 8 additions & 5 deletions tests/test_llm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
normalize_base_url,
)
from leettutor.metal_runtime import AMD_METAL_API_KEY, AMD_METAL_PROVIDER
from leettutor.providers import GEMINI_PROVIDER, OPENAI_PROVIDER
from leettutor.providers import GEMINI_PROVIDER, OPENAI_PROVIDER, STRATA_PROVIDER


@pytest.mark.parametrize(
Expand All @@ -19,6 +19,7 @@
("Ollama", "http://localhost:11434", "http://localhost:11434/v1"),
("Ollama", "localhost:11434/", "http://localhost:11434/v1"),
("LM Studio", "http://localhost:1234/v1/", "http://localhost:1234/v1"),
(STRATA_PROVIDER, "http://127.0.0.1:8080", "http://127.0.0.1:8080/v1"),
(AMD_METAL_PROVIDER, "http://127.0.0.1:11435", "http://127.0.0.1:11435/v1"),
(OPENAI_PROVIDER, "https://api.openai.com/v1/", "https://api.openai.com/v1"),
(
Expand All @@ -32,7 +33,8 @@ def test_normalize_base_url(provider: str, raw: str, expected: str) -> None:
assert normalize_base_url(provider, raw) == expected


def test_list_and_stream_with_openai_compatible_shape() -> None:
@pytest.mark.parametrize("provider", ["LM Studio", STRATA_PROVIDER])
def test_list_and_stream_with_openai_compatible_shape(provider: str) -> None:
class Value:
def __init__(self, **values):
self.__dict__.update(values)
Expand All @@ -46,7 +48,7 @@ def __init__(self) -> None:
)

client = LocalLLMClient(
ProviderSettings("LM Studio", "http://localhost:1234/v1"),
ProviderSettings(provider, "http://localhost:1234/v1"),
client_factory=lambda **_kwargs: FakeClient(),
)
assert client.list_models() == ["a", "z"]
Expand All @@ -60,7 +62,8 @@ def __init__(self) -> None:
) == [ChatDelta("content", "hi")]


def test_lm_studio_receives_qwen_thinking_controls() -> None:
@pytest.mark.parametrize("provider", ["LM Studio", STRATA_PROVIDER])
def test_local_provider_receives_qwen_thinking_controls(provider: str) -> None:
class Value:
def __init__(self, **values):
self.__dict__.update(values)
Expand All @@ -77,7 +80,7 @@ def __init__(self) -> None:
)

client = LocalLLMClient(
ProviderSettings("LM Studio", "http://localhost:1234/v1"),
ProviderSettings(provider, "http://localhost:1234/v1"),
client_factory=lambda **_kwargs: FakeClient(),
)
list(
Expand Down
13 changes: 12 additions & 1 deletion web-demo/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h2 data-copy="modelService">Model service</h2>
<select id="provider-select">
<option value="ollama">Ollama</option>
<option value="lmstudio">LM Studio</option>
<option value="strata">Strata</option>
<option value="amdmetal">AMD Metal (Intel Mac)</option>
<option value="openai">OpenAI</option>
<option value="gemini">Google Gemini</option>
Expand Down
Loading