mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-19 09:15:04 +02:00
ui : mark llama-app-reusable code with a LLAMA-APP-REUSE tag
Tag the pure-logic files and functions that llama.app (llama-pages) can reuse as-is: model id parsing, HF name and quant conventions, hardware compatibility estimation, chat-template capability detectors, and the HF formatting and metadata helpers. App-specific code is left unmarked. The LLAMA-APP-REUSE prefix makes the reusable surface greppable and distinguishable from regular comments: grep -rn LLAMA-APP-REUSE. Assisted-by: pi
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* URLs, parsing regexes and formatting units for the HuggingFaceService.
|
||||
* Reference: https://huggingface.co/docs/huggingface_hub/package_reference/hf_api
|
||||
*/
|
||||
// LLAMA-APP-REUSE: HF Hub endpoints and filename conventions
|
||||
|
||||
// API endpoints
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Parsing of `org/ModelName[-tag][:quant]` style model IDs.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: model id grammar: sidecars, quants, segments
|
||||
|
||||
import { ModelAuxSidecar, ModelDraftSidecar } from '$lib/enums';
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* (https://huggingface.co/docs/huggingface_hub/package_reference/hf_api)
|
||||
* so they can be sent and compared directly.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: HF sort and sidecar-form enums
|
||||
|
||||
/** Sort field for /api/models search queries. */
|
||||
export enum HfModelSort {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// LLAMA-APP-REUSE: model modality / capability / sidecar enums
|
||||
export enum ModelModality {
|
||||
AUDIO = 'AUDIO',
|
||||
TEXT = 'TEXT',
|
||||
|
||||
@@ -13,14 +13,14 @@ export enum ServerRole {
|
||||
* Used as the `value` field in the status object from /models endpoint
|
||||
*/
|
||||
export enum ServerModelStatus {
|
||||
DOWNLOAD_FAILED = 'download_failed',
|
||||
DOWNLOAD_FINISHED = 'download_finished',
|
||||
DOWNLOADED = 'downloaded',
|
||||
DOWNLOADING = 'downloading',
|
||||
FAILED = 'failed',
|
||||
LOADED = 'loaded',
|
||||
LOADING = 'loading',
|
||||
SLEEPING = 'sleeping',
|
||||
DOWNLOADED = 'downloaded',
|
||||
DOWNLOADING = 'downloading',
|
||||
DOWNLOAD_FAILED = 'download_failed',
|
||||
DOWNLOAD_FINISHED = 'download_finished',
|
||||
UNLOADED = 'unloaded'
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ export class HuggingFaceService {
|
||||
* quant. Non-sharded files pass through unchanged. Downloads are tag-based
|
||||
* (`repo:quant`), so the first shard is enough to represent the set.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: shard-set collapsing
|
||||
static collapseGgufShards(siblings: HfModelSibling[]): HfModelSibling[] {
|
||||
const sizeByPath = new Map(siblings.map((f) => [f.path, f.size ?? 0]));
|
||||
const result: HfModelSibling[] = [];
|
||||
@@ -175,6 +176,7 @@ export class HuggingFaceService {
|
||||
* (e.g. `*-BF16.gguf`); `sidecar` is `null` if no sidecar flag is present.
|
||||
* Returns `null` only when the filename doesn't end in `.gguf`.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: quant + sidecar filename parser
|
||||
static extractQuantMeta(filename: string): {
|
||||
quant: string | null;
|
||||
sidecar: ModelSidecar | null;
|
||||
@@ -231,6 +233,7 @@ export class HuggingFaceService {
|
||||
/**
|
||||
* Filter raw siblings by file extension and sort by size descending.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: sibling filtering
|
||||
static filterByExtension(siblings: HfModelSibling[], ext: string): HfModelSibling[] {
|
||||
return siblings
|
||||
.filter((f) => f.path.toLowerCase().endsWith(ext.toLowerCase()) && (f.size ?? 0) > 0)
|
||||
@@ -240,6 +243,7 @@ export class HuggingFaceService {
|
||||
/**
|
||||
* Format model downloads count with K/M/B suffix
|
||||
*/
|
||||
// LLAMA-APP-REUSE: compact download counts
|
||||
static formatDownloads(downloads: number): string {
|
||||
if (downloads >= MEGABYTE) {
|
||||
return `${(downloads / MEGABYTE).toFixed(1)}${MEGA_LABEL}`;
|
||||
@@ -255,6 +259,7 @@ export class HuggingFaceService {
|
||||
/**
|
||||
* Format file size in bytes to human-readable string
|
||||
*/
|
||||
// LLAMA-APP-REUSE: human-readable file sizes
|
||||
static formatFileSize(bytes: number): string {
|
||||
if (bytes >= GIGABYTE) {
|
||||
return `${(bytes / GIGABYTE).toFixed(1)} ${GIGABYTE_LABEL}`;
|
||||
@@ -274,6 +279,7 @@ export class HuggingFaceService {
|
||||
/**
|
||||
* Format likes count with K suffix if applicable
|
||||
*/
|
||||
// LLAMA-APP-REUSE: compact like counts
|
||||
static formatLikes(likes: number): string {
|
||||
if (likes >= KILOBYTE) {
|
||||
return `${(likes / KILOBYTE).toFixed(1)}${KILO_LABEL}`;
|
||||
@@ -285,6 +291,7 @@ export class HuggingFaceService {
|
||||
/**
|
||||
* Format timestamp to relative time
|
||||
*/
|
||||
// LLAMA-APP-REUSE: relative timestamps
|
||||
static formatRelativeTime(timestamp: string): string {
|
||||
const date = new Date(timestamp);
|
||||
const now = new Date();
|
||||
@@ -312,6 +319,7 @@ export class HuggingFaceService {
|
||||
* Format a min-max size range with a single shared unit and no spaces
|
||||
* around the dash, e.g. `19.0-28.6 GB`.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: min-max size ranges
|
||||
static formatSizeRange(min: number, max: number): string {
|
||||
const unit =
|
||||
max >= GIGABYTE
|
||||
@@ -398,6 +406,7 @@ export class HuggingFaceService {
|
||||
* Look up the average bit-depth for a known GGUF quantization.
|
||||
* Returns `null` for unrecognized tokens.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: quant bit depths
|
||||
static getBitDepth(quant: string): number | null {
|
||||
// Strip a leading `UD-` (Unsloth Dynamic) prefix before lookup.
|
||||
const base = quant.replace(HF_UD_QUANT_PREFIX_REGEX, '');
|
||||
@@ -581,6 +590,7 @@ export class HuggingFaceService {
|
||||
* `Qwen3.8-27B-GGUF` or `300M` from `embeddinggemma-300M-GGUF`. Returns null
|
||||
* when no size token is present.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: parameter-count parsing
|
||||
static parseParamCount(name: string): string | null {
|
||||
const match = HF_PARAM_COUNT_REGEX.exec(name);
|
||||
|
||||
@@ -592,6 +602,7 @@ export class HuggingFaceService {
|
||||
/**
|
||||
* Parse model tags to extract useful information
|
||||
*/
|
||||
// LLAMA-APP-REUSE: tag parsing
|
||||
static parseTags(tags: string[]): {
|
||||
license: string | null;
|
||||
isGated: boolean;
|
||||
|
||||
@@ -33,6 +33,7 @@ export class ModelsService {
|
||||
* @param sidecar - Sidecar type, uppercased into the tag (e.g. `MTP`)
|
||||
* @returns Repo id possibly suffixed with `:tag`
|
||||
*/
|
||||
// LLAMA-APP-REUSE: repo:tag id builder
|
||||
static buildDownloadTag(
|
||||
repoId: string,
|
||||
quant: string | null,
|
||||
@@ -154,6 +155,7 @@ export class ModelsService {
|
||||
* @param modelId - Raw model identifier string
|
||||
* @returns Structured {@link ParsedModelId} with all detected fields
|
||||
*/
|
||||
// LLAMA-APP-REUSE: model id parser
|
||||
static parseModelId(modelId: string): ParsedModelId {
|
||||
const result: ParsedModelId = {
|
||||
activatedParams: null,
|
||||
|
||||
+1
@@ -4,6 +4,7 @@
|
||||
* Types for the HuggingFace REST API (/api/models)
|
||||
* Reference: https://huggingface.co/docs/huggingface_hub/package_reference/hf_api
|
||||
*/
|
||||
// LLAMA-APP-REUSE: HF API response shapes
|
||||
|
||||
// Search Options
|
||||
|
||||
|
||||
Vendored
+1
@@ -45,6 +45,7 @@ export interface ModelDownloadProgress {
|
||||
totalBytes: number;
|
||||
}
|
||||
|
||||
// LLAMA-APP-REUSE: parsed model id shape
|
||||
export interface ParsedModelId {
|
||||
raw: string;
|
||||
orgName: string | null;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* 2. Thinking-control Jinja2 conditionals === template-native on/off logic
|
||||
* 3. Paired thinking-content tag pairs === models that output special tags
|
||||
*/
|
||||
// LLAMA-APP-REUSE: thinking-support detection from a chat template
|
||||
|
||||
const THINKING_KWARG_VARS = ['enable_thinking', 'reasoning_effort', 'thinking_budget'];
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* template. A template that accepts a `tools` array or emits tool-call tokens
|
||||
* is treated as tool-capable.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: tool-use support detection from a chat template
|
||||
|
||||
/** Tool-call tokens emitted by the template for assistant tool calls. */
|
||||
const TOOL_CALL_TOKENS = [
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* device-specific budgets are deliberately ignored - callers present the
|
||||
* requirement and let the user judge.
|
||||
*/
|
||||
// LLAMA-APP-REUSE: hardware compatibility estimation
|
||||
|
||||
/** Overhead multiplier applied to the file size when estimating weight memory. */
|
||||
const WEIGHT_OVERHEAD_MULTIPLIER = 1.05;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// LLAMA-APP-REUSE: model name / HF repo path normalization
|
||||
import { FILE_PATH_SEPARATOR_REGEX } from '$lib/constants';
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user