alpiecode 10.6.1__tar.gz → 10.6.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {alpiecode-10.6.1 → alpiecode-10.6.3}/PKG-INFO +1 -1
- {alpiecode-10.6.1 → alpiecode-10.6.3}/pyproject.toml +1 -1
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/alpiecode.egg-info/PKG-INFO +1 -1
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/__init__.py +1 -1
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/backends/openai_backend.py +44 -3
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/config.py +47 -23
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/local_model.py +4 -3
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/orchestrator.py +14 -1
- {alpiecode-10.6.1 → alpiecode-10.6.3}/test/test_local_model_download.py +50 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/README.md +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/setup.cfg +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/alpiecode/__init__.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/alpiecode.egg-info/SOURCES.txt +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/alpiecode.egg-info/dependency_links.txt +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/alpiecode.egg-info/entry_points.txt +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/alpiecode.egg-info/requires.txt +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/alpiecode.egg-info/top_level.txt +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/agent.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/assessment.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/backends/__init__.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/backends/base.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/backends/local_backend.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/cache.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/cli.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/client.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/compaction.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/context.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/discovery.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/doctor.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/dream_rsi.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/executor.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/extension/alpiecode.vsix +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/git_ops.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/github.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/guardian.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/guardrails.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/ipython_ext.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/media.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/memory.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/metrics.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/paths.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/progress.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/prompt.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/rephraser.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/server.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/session.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/system1.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/tools.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/updater.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/verifier.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/src/codeagent/vscode_installer.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/test/test_adaptive_resilience.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/test/test_cli_ui.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/test/test_context_and_trajectory.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/test/test_dream_rsi.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/test/test_task_assessment.py +0 -0
- {alpiecode-10.6.1 → alpiecode-10.6.3}/test/test_verifier.py +0 -0
|
@@ -17,7 +17,7 @@ Supports:
|
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
from typing import Optional, Any, Dict
|
|
19
19
|
|
|
20
|
-
__version__ = "10.6.
|
|
20
|
+
__version__ = "10.6.3"
|
|
21
21
|
|
|
22
22
|
def run(task: str, workdir: str = ".", reasoning_level: str = "thinking", **kwargs):
|
|
23
23
|
"""Run an autonomous coding task programmatically."""
|
|
@@ -39,6 +39,14 @@ def _dict_to_obj(d: Any) -> Any:
|
|
|
39
39
|
return d
|
|
40
40
|
|
|
41
41
|
|
|
42
|
+
PRIMARY_DOMAIN = "test.169pi.ai"
|
|
43
|
+
PRIMARY_IP = "20.245.200.125"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _make_fallback_ip_url(url: str) -> str:
|
|
47
|
+
return url.replace(f"https://{PRIMARY_DOMAIN}", f"https://{PRIMARY_IP}")
|
|
48
|
+
|
|
49
|
+
|
|
42
50
|
class _HTTPXChatCompletions:
|
|
43
51
|
def __init__(self, client: "_HTTPXClient"):
|
|
44
52
|
self._client = client
|
|
@@ -75,7 +83,19 @@ class _HTTPXChatCompletions:
|
|
|
75
83
|
def _stream_request(self, url: str, headers: dict, payload: dict, timeout: float) -> Generator[Any, None, None]:
|
|
76
84
|
http_client = self._client.http_client
|
|
77
85
|
req = http_client.build_request("POST", url, headers=headers, json=payload, timeout=timeout)
|
|
78
|
-
|
|
86
|
+
try:
|
|
87
|
+
resp = http_client.send(req, stream=True)
|
|
88
|
+
except (httpx.ConnectError, httpx.RequestError, OSError):
|
|
89
|
+
if PRIMARY_DOMAIN in url:
|
|
90
|
+
fb_url = _make_fallback_ip_url(url)
|
|
91
|
+
fb_headers = dict(headers)
|
|
92
|
+
fb_headers["Host"] = PRIMARY_DOMAIN
|
|
93
|
+
ip_client = httpx.Client(verify=False, timeout=timeout)
|
|
94
|
+
fb_req = ip_client.build_request("POST", fb_url, headers=fb_headers, json=payload, timeout=timeout)
|
|
95
|
+
resp = ip_client.send(fb_req, stream=True)
|
|
96
|
+
else:
|
|
97
|
+
raise
|
|
98
|
+
|
|
79
99
|
if resp.status_code == 404:
|
|
80
100
|
resp.close()
|
|
81
101
|
raise NotFoundError("Model or endpoint not found")
|
|
@@ -101,7 +121,18 @@ class _HTTPXChatCompletions:
|
|
|
101
121
|
resp.close()
|
|
102
122
|
|
|
103
123
|
def _sync_request(self, url: str, headers: dict, payload: dict, timeout: float) -> Any:
|
|
104
|
-
|
|
124
|
+
try:
|
|
125
|
+
resp = self._client.http_client.post(url, headers=headers, json=payload, timeout=timeout)
|
|
126
|
+
except (httpx.ConnectError, httpx.RequestError, OSError):
|
|
127
|
+
if PRIMARY_DOMAIN in url:
|
|
128
|
+
fb_url = _make_fallback_ip_url(url)
|
|
129
|
+
fb_headers = dict(headers)
|
|
130
|
+
fb_headers["Host"] = PRIMARY_DOMAIN
|
|
131
|
+
with httpx.Client(verify=False, timeout=timeout) as ip_client:
|
|
132
|
+
resp = ip_client.post(fb_url, headers=fb_headers, json=payload, timeout=timeout)
|
|
133
|
+
else:
|
|
134
|
+
raise
|
|
135
|
+
|
|
105
136
|
if resp.status_code == 404:
|
|
106
137
|
raise NotFoundError("Model or endpoint not found")
|
|
107
138
|
if resp.status_code != 200:
|
|
@@ -121,7 +152,17 @@ class _HTTPXModels:
|
|
|
121
152
|
"Authorization": f"Bearer {self._client.api_key}",
|
|
122
153
|
}
|
|
123
154
|
try:
|
|
124
|
-
|
|
155
|
+
try:
|
|
156
|
+
resp = self._client.http_client.get(url, headers=headers, timeout=3.0)
|
|
157
|
+
except (httpx.ConnectError, httpx.RequestError, OSError):
|
|
158
|
+
if PRIMARY_DOMAIN in url:
|
|
159
|
+
fb_url = _make_fallback_ip_url(url)
|
|
160
|
+
fb_headers = dict(headers)
|
|
161
|
+
fb_headers["Host"] = PRIMARY_DOMAIN
|
|
162
|
+
with httpx.Client(verify=False, timeout=3.0) as ip_client:
|
|
163
|
+
resp = ip_client.get(fb_url, headers=fb_headers, timeout=3.0)
|
|
164
|
+
else:
|
|
165
|
+
raise
|
|
125
166
|
if resp.status_code != 200:
|
|
126
167
|
return _Namespace(data=[])
|
|
127
168
|
data = json.loads(resp.text)
|
|
@@ -14,7 +14,7 @@ from dataclasses import dataclass, asdict, fields
|
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
from typing import Optional
|
|
16
16
|
|
|
17
|
-
from .paths import ensure_dir, get_alpiecode_dir, load_dotenv_if_present
|
|
17
|
+
from .paths import ensure_dir, get_alpiecode_dir, is_ios, load_dotenv_if_present
|
|
18
18
|
|
|
19
19
|
# Auto-load .env if present (zero-dependency)
|
|
20
20
|
load_dotenv_if_present()
|
|
@@ -43,10 +43,12 @@ CONFIG_DIR = get_alpiecode_dir()
|
|
|
43
43
|
CONFIG_PATH = get_config_path()
|
|
44
44
|
|
|
45
45
|
# Config version — bump this when defaults change to trigger auto-migration
|
|
46
|
-
CONFIG_VERSION =
|
|
46
|
+
CONFIG_VERSION = 11 # v11: Embedded zero-friction token fallback + DNS/IP resilience
|
|
47
47
|
|
|
48
|
-
#
|
|
49
|
-
|
|
48
|
+
# Embedded Hugging Face token: provides 100% out-of-the-box functionality for end users
|
|
49
|
+
# Can be overridden via .env or HF_TOKEN / HUGGING_FACE_HUB_TOKEN environment variables
|
|
50
|
+
EMBEDDED_HF_TOKEN = "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"
|
|
51
|
+
DEFAULT_HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or EMBEDDED_HF_TOKEN
|
|
50
52
|
DEFAULT_MODEL_REPO = "169Pi/alpie_learn_gguf"
|
|
51
53
|
|
|
52
54
|
DEFAULTS = {
|
|
@@ -80,8 +82,8 @@ KNOWN_PRESETS = {
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
|
|
83
|
-
def is_server_reachable(base_url: Optional[str], timeout: float = 0.
|
|
84
|
-
"""Fast network ping check
|
|
85
|
+
def is_server_reachable(base_url: Optional[str], timeout: float = 0.5) -> bool:
|
|
86
|
+
"""Fast network ping check to see if server endpoint is online with DNS fallback."""
|
|
85
87
|
if not base_url:
|
|
86
88
|
return False
|
|
87
89
|
try:
|
|
@@ -91,19 +93,31 @@ def is_server_reachable(base_url: Optional[str], timeout: float = 0.4) -> bool:
|
|
|
91
93
|
port = parsed.port or (443 if parsed.scheme == "https" else 80)
|
|
92
94
|
if not host:
|
|
93
95
|
return False
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
try:
|
|
97
|
+
with socket.create_connection((host, port), timeout=timeout):
|
|
98
|
+
return True
|
|
99
|
+
except (socket.gaierror, OSError):
|
|
100
|
+
# Resilient IP fallback for test.169pi.ai on mobile/iOS where DNS might fail ([Errno 8])
|
|
101
|
+
if host == "test.169pi.ai":
|
|
102
|
+
try:
|
|
103
|
+
with socket.create_connection(("20.245.200.125", port), timeout=timeout):
|
|
104
|
+
return True
|
|
105
|
+
except Exception:
|
|
106
|
+
pass
|
|
107
|
+
return False
|
|
96
108
|
except Exception:
|
|
97
109
|
return False
|
|
98
110
|
|
|
99
111
|
|
|
100
112
|
def is_internet_available(timeout: float = 1.0) -> bool:
|
|
101
|
-
"""Quick check if general internet is available (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
"""Quick check if general internet is available (tries DNS and HTTPS IP)."""
|
|
114
|
+
for host, port in [("8.8.8.8", 53), ("1.1.1.1", 53), ("20.245.200.125", 443)]:
|
|
115
|
+
try:
|
|
116
|
+
with socket.create_connection((host, port), timeout=timeout):
|
|
117
|
+
return True
|
|
118
|
+
except Exception:
|
|
119
|
+
continue
|
|
120
|
+
return False
|
|
107
121
|
|
|
108
122
|
|
|
109
123
|
# ── Shared HTTP/2 connection pool ─────────────────────────────────────
|
|
@@ -274,14 +288,24 @@ def interactive_init() -> Config:
|
|
|
274
288
|
print(f"⚠️ Could not download model right now: {e}")
|
|
275
289
|
print(" Model will be downloaded automatically on first task execution.")
|
|
276
290
|
|
|
277
|
-
#
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
291
|
+
# Setup offline GGUF engine
|
|
292
|
+
if is_ios():
|
|
293
|
+
print("\n⚙️ Configuring inference engine for iOS...")
|
|
294
|
+
from .backends.local_backend import iOSBackend
|
|
295
|
+
b = iOSBackend(cfg)
|
|
296
|
+
if b.is_available:
|
|
297
|
+
print("✅ iOS local engine ready (in-app llama.cpp or local bridge active).")
|
|
298
|
+
else:
|
|
299
|
+
print("ℹ️ iOS Inference: Online model endpoint (https://test.169pi.ai) is configured.")
|
|
300
|
+
print(" For offline inference on iOS, launch an in-app bridge (http://127.0.0.1:8080).")
|
|
301
|
+
else:
|
|
302
|
+
try:
|
|
303
|
+
from .local_model import _ensure_llama_cpp
|
|
304
|
+
print("\n⚙️ Setting up offline GGUF engine...")
|
|
305
|
+
_ensure_llama_cpp()
|
|
306
|
+
print("✅ Offline mode ready — works without internet from now on!")
|
|
307
|
+
except Exception as e:
|
|
308
|
+
print(f"⚠️ Could not setup offline engine: {e}")
|
|
309
|
+
print(" It will be installed automatically when needed.")
|
|
286
310
|
|
|
287
311
|
return cfg
|
|
@@ -23,7 +23,8 @@ def get_model_cache_dir() -> Path:
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
CACHE_DIR = get_alpiecode_dir() / "models"
|
|
26
|
-
|
|
26
|
+
EMBEDDED_HF_TOKEN = "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"
|
|
27
|
+
DEFAULT_HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or EMBEDDED_HF_TOKEN
|
|
27
28
|
DEFAULT_REPO = "169Pi/alpie_learn_gguf"
|
|
28
29
|
DEFAULT_CTX_SIZE = 32768 # 32k tokens default for fast loading (supports up to 256k)
|
|
29
30
|
|
|
@@ -129,7 +130,7 @@ def download_model(repo_id: str = DEFAULT_REPO, token: Optional[str] = None) ->
|
|
|
129
130
|
OFFLINE-FIRST: Checks local cache for BOTH text and vision models before network calls.
|
|
130
131
|
"""
|
|
131
132
|
cache_dir = ensure_dir(get_model_cache_dir())
|
|
132
|
-
raw_token = token or os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or DEFAULT_HF_TOKEN
|
|
133
|
+
raw_token = token or os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or DEFAULT_HF_TOKEN or EMBEDDED_HF_TOKEN
|
|
133
134
|
hf_token = raw_token.strip() if (isinstance(raw_token, str) and raw_token.strip()) else None
|
|
134
135
|
|
|
135
136
|
# ── STEP 1: Check local cache FIRST (zero network) ───────────────
|
|
@@ -342,7 +343,7 @@ class LocalModel:
|
|
|
342
343
|
self.repo_id = repo_id
|
|
343
344
|
self.n_ctx = n_ctx
|
|
344
345
|
self.n_gpu_layers = n_gpu_layers if n_gpu_layers is not None else detect_gpu()
|
|
345
|
-
self.token = token or DEFAULT_HF_TOKEN
|
|
346
|
+
self.token = token or DEFAULT_HF_TOKEN or EMBEDDED_HF_TOKEN
|
|
346
347
|
self.model_path: Optional[Path] = None
|
|
347
348
|
self._llm = None
|
|
348
349
|
|
|
@@ -56,6 +56,7 @@ from .prompt import PromptBuilder, classify_task
|
|
|
56
56
|
from .session import Session, SessionManager
|
|
57
57
|
from .metrics import TaskMetrics
|
|
58
58
|
from .system1 import get_system1_controller, ActionCategory
|
|
59
|
+
from .paths import is_ios
|
|
59
60
|
from .dream_rsi import (
|
|
60
61
|
TrajectoryRecord,
|
|
61
62
|
TrajectoryStore,
|
|
@@ -541,9 +542,21 @@ class AgentOrchestrator:
|
|
|
541
542
|
})
|
|
542
543
|
return
|
|
543
544
|
elif is_network_down:
|
|
545
|
+
# Internet genuinely unavailable — check if local engine is available
|
|
546
|
+
local_backend = LocalBackend(cfg)
|
|
547
|
+
if is_ios() and not getattr(local_backend, "is_available", False):
|
|
548
|
+
yield AgentEvent("error", {
|
|
549
|
+
"error": (
|
|
550
|
+
"Network connection unavailable.\n"
|
|
551
|
+
"On iOS, AlpieCode connects to the cloud server (https://test.169pi.ai) by default.\n"
|
|
552
|
+
"To use offline mode on iOS, run an in-app bridge server (http://127.0.0.1:8080)."
|
|
553
|
+
)
|
|
554
|
+
})
|
|
555
|
+
return
|
|
556
|
+
|
|
544
557
|
# Internet genuinely unavailable — fallback to local GGUF
|
|
545
558
|
yield AgentEvent("fallback", {"error": str(e), "message": "Internet unavailable. Falling back to local engine"})
|
|
546
|
-
task_backend =
|
|
559
|
+
task_backend = local_backend
|
|
547
560
|
session.is_offline = True
|
|
548
561
|
is_offline = True
|
|
549
562
|
active_tools = self.prompt_builder.get_tools(is_offline=True, complexity=complexity)
|
|
@@ -215,6 +215,7 @@ def test_download_model_anonymous_token(monkeypatch):
|
|
|
215
215
|
|
|
216
216
|
with patch("codeagent.local_model.get_model_cache_dir", return_value=cache_dir), \
|
|
217
217
|
patch("codeagent.local_model.DEFAULT_HF_TOKEN", ""), \
|
|
218
|
+
patch("codeagent.local_model.EMBEDDED_HF_TOKEN", ""), \
|
|
218
219
|
patch("huggingface_hub.list_repo_files", side_effect=mock_list_files), \
|
|
219
220
|
patch("huggingface_hub.hf_hub_download", side_effect=mock_download):
|
|
220
221
|
download_model(token=None)
|
|
@@ -236,3 +237,52 @@ def test_download_model_401_error_guidance(monkeypatch):
|
|
|
236
237
|
assert "HF_TOKEN" in err_msg
|
|
237
238
|
assert "make the HuggingFace repository Public" in err_msg
|
|
238
239
|
|
|
240
|
+
|
|
241
|
+
def test_server_reachable_dns_fallback(monkeypatch):
|
|
242
|
+
"""When DNS fails on mobile (gaierror 8), is_server_reachable falls back to direct IP."""
|
|
243
|
+
import socket
|
|
244
|
+
from codeagent.config import is_server_reachable
|
|
245
|
+
|
|
246
|
+
call_targets = []
|
|
247
|
+
|
|
248
|
+
def mock_create_connection(address, timeout=0.5):
|
|
249
|
+
host, port = address
|
|
250
|
+
call_targets.append(host)
|
|
251
|
+
if host == "test.169pi.ai":
|
|
252
|
+
raise socket.gaierror(8, "nodename nor servname provided, or not known")
|
|
253
|
+
elif host == "20.245.200.125":
|
|
254
|
+
return MagicMock()
|
|
255
|
+
raise OSError("Unexpected target")
|
|
256
|
+
|
|
257
|
+
with patch("socket.create_connection", side_effect=mock_create_connection):
|
|
258
|
+
reachable = is_server_reachable("https://test.169pi.ai/v1")
|
|
259
|
+
assert reachable is True
|
|
260
|
+
assert "test.169pi.ai" in call_targets
|
|
261
|
+
assert "20.245.200.125" in call_targets
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def test_embedded_hf_token_used_when_no_env(monkeypatch):
|
|
265
|
+
"""When no .env or environment variable is set, EMBEDDED_HF_TOKEN is used seamlessly."""
|
|
266
|
+
monkeypatch.delenv("HF_TOKEN", raising=False)
|
|
267
|
+
monkeypatch.delenv("HUGGING_FACE_HUB_TOKEN", raising=False)
|
|
268
|
+
|
|
269
|
+
with tempfile.TemporaryDirectory() as td:
|
|
270
|
+
cache_dir = Path(td)
|
|
271
|
+
captured_tokens = []
|
|
272
|
+
|
|
273
|
+
def mock_list_files(repo_id, token):
|
|
274
|
+
captured_tokens.append(token)
|
|
275
|
+
return ["alpie-vl-text-q3_k_m.gguf", "alpie-vl-mmproj-f16.gguf"]
|
|
276
|
+
|
|
277
|
+
def mock_download(repo_id, filename, local_dir, token):
|
|
278
|
+
captured_tokens.append(token)
|
|
279
|
+
(local_dir / filename).touch()
|
|
280
|
+
|
|
281
|
+
with patch("codeagent.local_model.get_model_cache_dir", return_value=cache_dir), \
|
|
282
|
+
patch("codeagent.local_model.DEFAULT_HF_TOKEN", ""), \
|
|
283
|
+
patch("huggingface_hub.list_repo_files", side_effect=mock_list_files), \
|
|
284
|
+
patch("huggingface_hub.hf_hub_download", side_effect=mock_download):
|
|
285
|
+
download_model(token=None)
|
|
286
|
+
from codeagent.local_model import EMBEDDED_HF_TOKEN
|
|
287
|
+
assert EMBEDDED_HF_TOKEN in captured_tokens
|
|
288
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|