clarifai-python icon indicating copy to clipboard operation
clarifai-python copied to clipboard

Use Configuration contexts in Model Upload CLI

Open Copilot opened this issue 8 months ago β€’ 1 comments

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.

Copilot avatar Jun 25 '25 10:06 Copilot

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%

github-actions[bot] avatar Jun 27 '25 07:06 github-actions[bot]

looks good to me.

ackizilkale avatar Jul 02 '25 18:07 ackizilkale