-
Notifications
You must be signed in to change notification settings - Fork 24
implemented downloading, metrics and models endpoint #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.0.4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,14 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import base64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from contextlib import asynccontextmanager | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any, AsyncIterator, Dict, List, Optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import psutil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import psutil | |
| try: | |
| import psutil | |
| except ImportError: | |
| psutil = None |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new endpoints import src.server.downloader and src.server.models.requests_management, but those modules do not exist in the repository. As written, src.server.main will raise ModuleNotFoundError on startup. Please add these modules to the PR (or update the imports to match existing locations/types).
| from src.server.downloader import global_downloader | |
| from src.server.models.requests_management import ( | |
| DownloaderRequest, | |
| DownloaderActionRequest, | |
| ) | |
| try: | |
| from src.server.downloader import global_downloader | |
| from src.server.models.requests_management import ( | |
| DownloaderRequest, | |
| DownloaderActionRequest, | |
| ) | |
| except ModuleNotFoundError: | |
| class _MissingDownloader: | |
| def __getattr__(self, name: str) -> Any: | |
| raise RuntimeError( | |
| "Downloader support is unavailable because " | |
| "'src.server.downloader' or " | |
| "'src.server.models.requests_management' could not be imported." | |
| ) | |
| global_downloader = _MissingDownloader() | |
| class DownloaderRequest(BaseModel): | |
| url: str | |
| output_path: Optional[str] = None | |
| class DownloaderActionRequest(BaseModel): | |
| action: str | |
| request_id: Optional[str] = None |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/openarc/models/update accepts an arbitrary filesystem path (model_path) and then writes openarc.json into that directory. Even with API-key protection, this is an arbitrary file-write primitive and can be abused to modify files outside the intended models cache. Consider restricting model_path to a fixed base directory (e.g., the OpenArc models cache), resolve the path, and reject any path that escapes that base.
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reading an existing openarc.json, JSON parsing errors are silently ignored (except Exception: pass). This can cause the endpoint to overwrite a corrupted config without any signal to the caller. It would be better to return a 400 with a clear error if the existing config is invalid JSON (or at least log the exception).
| except Exception: | |
| pass | |
| except json.JSONDecodeError as e: | |
| raise HTTPException( | |
| status_code=400, | |
| detail=f"Existing openarc.json contains invalid JSON: {str(e)}", | |
| ) | |
| except Exception as e: | |
| logger.exception("Failed to read existing config from %s", config_path) | |
| raise HTTPException( | |
| status_code=500, | |
| detail=f"Failed to read existing config: {str(e)}", | |
| ) |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This async endpoint performs blocking disk I/O (open(...).read / json.dump) on the event loop thread. Under load, this can stall request handling. Consider offloading these file operations to a threadpool (e.g., asyncio.to_thread) or using an async file library.
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import: os is imported but never referenced in this function. Removing it will avoid linter warnings and keep the endpoint focused.
| import os |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/openarc/models allows callers to pass an arbitrary path and will list directories and read openarc.json files from it. This can expose the server's filesystem layout and contents to any API-key holder. Consider restricting listing to the OpenArc models directory (and/or only allowing a model ID rather than a raw path).
| if path: | |
| target_path = Path(path) | |
| else: | |
| target_path = Path.home() / ".cache" / "openarc" / "models" | |
| models_root = (Path.home() / ".cache" / "openarc" / "models").resolve() | |
| if path: | |
| target_path = Path(path).expanduser().resolve(strict=False) | |
| try: | |
| target_path.relative_to(models_root) | |
| except ValueError: | |
| raise HTTPException( | |
| status_code=400, | |
| detail="Path must be within the OpenArc models directory", | |
| ) | |
| else: | |
| target_path = models_root |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/openarc/version returns a hard-coded string (v2.0.4) which is already inconsistent with the package version declared in pyproject.toml (2.0). Consider sourcing this from package metadata (e.g., importlib.metadata.version(...)) so it stays correct across releases.
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_intel_gpu_metrics() constructs a new openvino.Core() and enumerates devices on every /openarc/metrics request. If metrics are polled frequently, this can add noticeable overhead. Consider caching the Core instance / static device info at startup and only recomputing the values that actually change per request.
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling in comment: standad should be standard.
| # mock usage/memory for now cause standad python dont easily expose intel gpu telemetry without root/external tools | |
| # mock usage/memory for now cause standard python dont easily expose intel gpu telemetry without root/external tools |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling in comment: avialable should be available.
| # try getting memory info if avialable in openvino | |
| # try getting memory info if available in openvino |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
psutil.cpu_percent() without an interval returns a percentage since the last call, and the first call commonly returns 0.0. This can make /openarc/metrics misleading right after startup. Consider priming cpu_percent at startup or using a dedicated background sampler so the returned value is stable/meaningful.
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling in comment: basicly should be basically.
| # resume is basicly start | |
| # resume is basically start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The endpoint list printed at startup doesn’t include new routes added in this PR (
GET /openarc/versionandGET /openarc/models). Please keep this list in sync with the server routes so users can discover the full API surface.