Skip to content

Optimize the commands#31

Merged
InftyAI-Agent merged 2 commits intoInftyAI:mainfrom
kerthcet:cleanup/optimize-jsons
Apr 24, 2026
Merged

Optimize the commands#31
InftyAI-Agent merged 2 commits intoInftyAI:mainfrom
kerthcet:cleanup/optimize-jsons

Conversation

@kerthcet
Copy link
Copy Markdown
Member

What this PR does / why we need it

Which issue(s) this PR fixes

Fixes #

Special notes for your reviewer

Does this PR introduce a user-facing change?


Signed-off-by: kerthcet <kerthcet@gmail.com>
Copilot AI review requested due to automatic review settings April 24, 2026 21:49
@kerthcet
Copy link
Copy Markdown
Member Author

/lgtm
/kind cleanup

@InftyAI-Agent InftyAI-Agent added needs-triage Indicates an issue or PR lacks a label and requires one. needs-priority Indicates a PR lacks a label and requires one. do-not-merge/needs-kind Indicates a PR lacks a label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Looks good to me, indicates that a PR is ready to be merged. cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Apr 24, 2026
@InftyAI-Agent InftyAI-Agent removed the do-not-merge/needs-kind Indicates a PR lacks a label and requires one. label Apr 24, 2026
Signed-off-by: kerthcet <kerthcet@gmail.com>
@kerthcet
Copy link
Copy Markdown
Member Author

/lgtm

@InftyAI-Agent InftyAI-Agent added lgtm Looks good to me, indicates that a PR is ready to be merged. and removed lgtm Looks good to me, indicates that a PR is ready to be merged. labels Apr 24, 2026
@InftyAI-Agent InftyAI-Agent merged commit 255df82 into InftyAI:main Apr 24, 2026
17 checks passed
@kerthcet kerthcet deleted the cleanup/optimize-jsons branch April 24, 2026 21:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors model metadata handling by replacing the prior “architecture” concept with a richer ModelSpec, and updates HuggingFace downloads + CLI inspection output to use the new metadata shape.

Changes:

  • Replace ModelArchitecture/arch with ModelSpec/spec in the model registry.
  • Fetch model metadata from the HuggingFace REST API during download and store it in the registry.
  • Update the inspect command output and associated tests to display spec fields.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/registry/model_registry.rs Introduces ModelSpec and updates ModelInfo to persist spec instead of arch; removes old config-based architecture extraction + related tests.
src/downloader/huggingface.rs Adds a HuggingFace REST API metadata fetch and stores the result as ModelSpec; uses API storage size when available.
src/cli/commands.rs Updates inspect output formatting and tests to read/display the new spec fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +286 to +293
let spec = Some(ModelSpec {
author: author_from_api,
task: task_from_api,
license: license_from_api,
model_type: model_type_from_api,
parameters: parameters_from_api,
context_window,
});
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec is always set to Some(ModelSpec { ... }) even when all fields are None, which will serialize into "spec": {} (since the inner fields are skipped). If the intent is “no metadata”, consider setting spec to None when all extracted fields are missing to avoid storing an empty object and to keep the registry format cleaner.

Suggested change
let spec = Some(ModelSpec {
author: author_from_api,
task: task_from_api,
license: license_from_api,
model_type: model_type_from_api,
parameters: parameters_from_api,
context_window,
});
let model_spec = ModelSpec {
author: author_from_api,
task: task_from_api,
license: license_from_api,
model_type: model_type_from_api,
parameters: parameters_from_api,
context_window,
};
let spec = if model_spec.author.is_some()
|| model_spec.task.is_some()
|| model_spec.license.is_some()
|| model_spec.model_type.is_some()
|| model_spec.parameters.is_some()
|| model_spec.context_window.is_some()
{
Some(model_spec)
} else {
None
};

Copilot uses AI. Check for mistakes.
Comment thread src/cli/commands.rs
spec.author.as_deref().unwrap_or("N/A")
);
println!(
" Task: {}",
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context Window is formatted with format_parameters, which produces abbreviated K/M/B output (e.g., 2048 -> "2.05K"). Context window is a token count and should generally be shown as an exact integer (or with a dedicated formatter) to avoid confusing output.

Copilot uses AI. Check for mistakes.
@@ -102,7 +31,7 @@ pub struct ModelInfo {
pub updated_at: String,
pub cache_path: String,
#[serde(skip_serializing_if = "Option::is_none")]
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming the persisted field from arch to spec means existing models.json entries that already contain arch will deserialize successfully but the metadata will be silently dropped (since arch is now an unknown field). If preserving existing registry metadata across upgrades matters, consider supporting deserialization of the legacy arch shape (e.g., a LegacyModelArchitecture used only for Deserialize) and mapping it into spec, or implementing a custom Deserialize for ModelInfo that accepts either field.

Suggested change
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(skip_serializing_if = "Option::is_none", alias = "arch")]

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +55
let url = format!("https://huggingface.co/api/models/{}", model_name);
let client = reqwest::Client::new();

match client.get(&url).send().await {
Ok(response) => {
if let Ok(json) = response.json::<serde_json::Value>().await {
let author = json
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch_metadata_from_api uses a default reqwest::Client with no timeout and it ignores non-success HTTP statuses. This can cause pull to hang indefinitely on network stalls and silently treat 4xx/5xx responses as “no metadata”. Consider using Client::builder().timeout(...) (or per-request timeout) and calling response.error_for_status() before attempting to parse JSON, returning/logging an error when the API call fails.

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +52
let url = format!("https://huggingface.co/api/models/{}", model_name);
let client = reqwest::Client::new();

match client.get(&url).send().await {
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HuggingFace API URL is built via string concatenation with model_name, but model_name may contain characters that require URL encoding. hf_hub likely handles this internally for downloads, so this extra request can fail even when the snapshot download succeeds. Consider constructing the URL with reqwest::Url (or similar) to ensure proper escaping of the repo id/path segment.

Suggested change
let url = format!("https://huggingface.co/api/models/{}", model_name);
let client = reqwest::Client::new();
match client.get(&url).send().await {
let mut url = match reqwest::Url::parse("https://huggingface.co/") {
Ok(url) => url,
Err(_) => return (None, None, None, None, None, None),
};
if let Ok(mut path_segments) = url.path_segments_mut() {
path_segments.push("api");
path_segments.push("models");
path_segments.push(model_name);
} else {
return (None, None, None, None, None, None);
}
let client = reqwest::Client::new();
match client.get(url).send().await {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Looks good to me, indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a label and requires one. needs-triage Indicates an issue or PR lacks a label and requires one.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants