Skip to content

Conversation

srikanthbachala20
Copy link
Contributor

This pull request introduces several improvements and refactors to the model initialization and checkpoint download workflows, focusing on better logging, user interaction, and code maintainability. The main changes include enhanced feedback during GitHub-based model initialization, improved reporting of files to be downloaded, more informative logging during Hugging Face checkpoint downloads, and code refactoring for file listing and validation logic.

Model Initialization and GitHub Download Workflow:

  • Added interactive prompts and detailed logging to the GitHub-based model initialization process in clarifai/cli/model.py, including a preview of files to be downloaded and next-step instructions for the user. [1] [2] [3]
  • Introduced the get_list_of_files_to_download utility in clarifai/utils/misc.py to recursively list files in a GitHub folder, improving transparency about which files will be downloaded.
  • Updated imports in clarifai/cli/model.py to include the new utility function.

Hugging Face Checkpoint Download Improvements:

  • Enhanced logging in clarifai/runners/utils/loader.py to show the total download size (in MB) and a clear message before downloading model checkpoints.
  • Refactored the checkpoint file listing and validation logic into a separate method (get_repo_files_list), and updated the download size calculation to allow filtering by specific files. [1] [2] [3] [4]

General Logging and Minor Fixes:

  • Improved success messages to include download paths in clarifai/runners/models/model_builder.py.
  • Fixed context usage for PAT retrieval in model listing (clarifai/cli/model.py).
  • Updated argument passing style for the serve function in clarifai/runners/server.py for clarity and maintainability.
  • Updated environment variable usage in command construction in clarifai/cli/base.py for consistency.

@srikanthbachala20 srikanthbachala20 requested review from Copilot, mogith-pn and luv-bansal and removed request for Copilot August 12, 2025 10:42
Copy link
Contributor

@Copilot 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 pull request improves the UX of the Model CLI by enhancing user feedback during model initialization and checkpoint downloads. The changes focus on providing better visibility into download operations and improving code maintainability through refactoring.

  • Enhanced GitHub-based model initialization with file preview and interactive prompts
  • Improved Hugging Face checkpoint download logging with size information and progress messages
  • Code refactoring for better maintainability and clearer parameter passing

Reviewed Changes

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

Show a summary per file
File Description
clarifai/utils/misc.py Added recursive file listing function for GitHub repositories
clarifai/runners/utils/loader.py Enhanced checkpoint download logging and refactored file listing logic
clarifai/runners/server.py Updated function call to use named parameters for clarity
clarifai/runners/models/model_builder.py Improved success message to include download path
clarifai/cli/model.py Enhanced GitHub initialization workflow with file preview and user prompts
clarifai/cli/base.py Fixed environment variable reference in command construction

depth=(depth - 1),
)
else:
files_to_download.append(point['path'])
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

Files are being added to the list regardless of their type when depth is 0 or when the item is not a directory. This will include directories in the files list when depth reaches 0, which could lead to incorrect file listings.

Suggested change
files_to_download.append(point['path'])
if point['type'] == 'file':
files_to_download.append(point['path'])

Copilot uses AI. Check for mistakes.

@@ -278,8 +278,8 @@ def view(ctx, output_format):
def run(ctx, script, context=None):
"""Execute a script with the current context's environment"""
context = ctx.obj.current if not context else context
cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.base_url} CLARIFAI_PAT={context.pat} '
cmd += ' '.join([f'{k}={v}' for k, v in context.env.items()])
cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.api_base} CLARIFAI_PAT={context.pat} '
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

The change from context.base_url to context.api_base may be incorrect if the context object doesn't have an api_base attribute. This could cause an AttributeError at runtime.

Suggested change
cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.api_base} CLARIFAI_PAT={context.pat} '
api_base = getattr(context, "api_base", getattr(context, "base_url", ""))
cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={api_base} CLARIFAI_PAT={context.pat} '

Copilot uses AI. Check for mistakes.

Copy link

Code Coverage

Package Line Rate Health
clarifai 43%
clarifai.cli 42%
clarifai.cli.templates 28%
clarifai.client 67%
clarifai.client.auth 67%
clarifai.constants 100%
clarifai.datasets 100%
clarifai.datasets.export 80%
clarifai.datasets.upload 75%
clarifai.datasets.upload.loaders 37%
clarifai.models 100%
clarifai.modules 0%
clarifai.rag 72%
clarifai.runners 9%
clarifai.runners.models 59%
clarifai.runners.pipeline_steps 45%
clarifai.runners.pipelines 80%
clarifai.runners.utils 63%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 60%
clarifai.utils 52%
clarifai.utils.evaluation 67%
clarifai.workflows 95%
Summary 61% (7507 / 12258)

Minimum allowed line rate is 50%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant