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

Update clarifai model predict CLI with SDK new changes for pythonic models

Open Copilot opened this issue 8 months ago • 0 comments

This PR updates the clarifai model predict CLI command to support the new pythonic models with method signatures, while maintaining full backward compatibility with traditional models.

🚀 Key Features Added

1. Method Selection for Pythonic Models

  • Added --method option to specify which method to call (predict, generate, stream, etc.)
  • Supports all methods defined in pythonic model signatures

2. Input Validation Against Model Signatures

  • Added --model_path option for local model signature validation
  • Validates method exists and shows available methods if invalid
  • Checks required parameters and provides clear error messages
  • Basic type validation for parameters (str, int, float, list)

3. JSON Input Parameters

  • Added --inputs option for structured JSON input parameters
  • Supports complex parameter combinations
  • Provides clear JSON parsing error messages

📝 Usage Examples

Traditional models (unchanged)

clarifai model predict --model_url <url> --file_path image.jpg
clarifai model predict --model_id <id> --user_id <uid> --app_id <aid> --url https://example.com/image.jpg

Pythonic models (new)

# Basic prediction
clarifai model predict --model_url <url> --inputs '{"prompt": "Hello world"}'

# With method selection
clarifai model predict --model_url <url> --method generate --inputs '{"prompt": "Tell me a story", "max_tokens": 100}'

# With local validation
clarifai model predict --model_url <url> --model_path ./my_model --method predict --inputs '{"prompt": "Hello"}'

🔍 Validation Features

The CLI now validates inputs against model signatures when --model_path is provided:

# Shows available methods if invalid
$ clarifai model predict --model_path ./model --method invalid_method --inputs '{}'
Error: Method 'invalid_method' not found in model. Available methods: ['predict', 'generate']

# Validates required parameters
$ clarifai model predict --model_path ./model --method predict --inputs '{"max_tokens": 100}'
Error: Missing required parameters for method 'predict': ['prompt']

🧪 Testing

  • Added comprehensive test suite in tests/cli/test_model_predict.py
  • All 14 tests pass, covering new functionality, validation, error cases, and backward compatibility
  • Verified existing model prediction functionality remains unchanged

🔄 Backward Compatibility

  • Traditional models continue to work with existing options (--file_path, --url, --bytes)
  • No breaking changes to existing functionality
  • Graceful fallback for edge cases

Fixes #653.


💬 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 29 '25 10:06 Copilot