Skip to content

Use Configuration contexts in Model Upload CLI#649

Merged
srikanthbachala20 merged 3 commits intomasterfrom
copilot/fix-648
Jul 1, 2025
Merged

Use Configuration contexts in Model Upload CLI#649
srikanthbachala20 merged 3 commits intomasterfrom
copilot/fix-648

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 25, 2025

The Model Upload CLI (clarifai model upload .) now uses Configuration contexts instead of relying solely on environment variables like CLARIFAI_PAT.

Problem

Previously, the model upload command required users to set environment variables directly:

export CLARIFAI_PAT="your-token"
clarifai model upload .

This approach was inconsistent with other CLI commands like clarifai model local-dev which properly use the configuration context system.

Solution

The upload command now integrates with the configuration context system:

# Set up configuration context (one time)
clarifai config use-context production

# Upload using context (no env vars needed)
clarifai model upload .

Changes Made

  1. CLI Integration: Added @click.pass_context and validate_context(ctx) to the upload command
  2. Context Parameter Passing: Upload command now passes ctx.obj.current.pat and ctx.obj.current.api_base to the backend
  3. ModelBuilder Enhancement: Added optional pat and base_url parameters to constructor
  4. Smart Authentication: Uses context parameters when provided, falls back to environment variables for backward compatibility

Backward Compatibility

Fully maintained - existing code using environment variables continues to work unchanged:

# Still works for backward compatibility
export CLARIFAI_PAT="your-token"
clarifai model upload .

Testing

  • ✅ Context parameter usage verification
  • ✅ Backward compatibility with environment variables
  • ✅ CLI integration testing
  • ✅ Error handling and validation
  • ✅ Other ModelBuilder commands (download-checkpoints, signatures) remain unaffected

Fixes #648.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • samples.clarifai.com
    • Triggering command: python -m pytest tests/REDACTEDs/test_model_signatures.py -xvs --tb=short (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: srikanthbachala20 <170492893+srikanthbachala20@users.noreply.github.com>
Copilot AI changed the title [WIP] Use Config contexts in Model Upload CLI Use Configuration contexts in Model Upload CLI Jun 25, 2025
Copilot AI requested a review from srikanthbachala20 June 25, 2025 11:02
@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Health
clarifai 43%
clarifai.cli 45%
clarifai.cli.templates 28%
clarifai.client 69%
clarifai.client.auth 66%
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 12%
clarifai.runners.models 58%
clarifai.runners.pipeline_steps 0%
clarifai.runners.pipelines 85%
clarifai.runners.utils 61%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 58%
clarifai.utils 73%
clarifai.utils.evaluation 67%
clarifai.workflows 95%
Summary 62% (6955 / 11130)

Minimum allowed line rate is 50%

@srikanthbachala20 srikanthbachala20 marked this pull request as ready for review June 27, 2025 07:35
@srikanthbachala20 srikanthbachala20 requested review from ackizilkale, luv-bansal, mogith-pn and zeiler and removed request for srikanthbachala20 June 27, 2025 07:35
Copy link
Copy Markdown
Contributor

@mogith-pn mogith-pn left a comment

Choose a reason for hiding this comment

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

LGTM. Let's merge this for now, but we may have to write a test for validating config /context before upload.

@srikanthbachala20 srikanthbachala20 merged commit 52421ff into master Jul 1, 2025
9 checks passed
@srikanthbachala20 srikanthbachala20 deleted the copilot/fix-648 branch July 1, 2025 07:44
@ackizilkale
Copy link
Copy Markdown
Contributor

looks good to me.

srikanthbachala20 added a commit that referenced this pull request Jul 29, 2025
* Initial plan

* Implement config contexts support in Model Upload CLI

Co-authored-by: srikanthbachala20 <170492893+srikanthbachala20@users.noreply.github.com>

* Fix Linting

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: srikanthbachala20 <170492893+srikanthbachala20@users.noreply.github.com>
Co-authored-by: Srikanth Bachala <srikanth.bachala@clarifai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Config contexts in Model Upload CLI

4 participants