Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 29, 2025

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 AI and others added 2 commits June 29, 2025 10:23
…dation

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

Co-authored-by: srikanthbachala20 <170492893+srikanthbachala20@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Update clarifai model predict CLI with SDK new changes Update clarifai model predict CLI with SDK new changes for pythonic models Jun 29, 2025
Copilot finished work on behalf of srikanthbachala20 June 29, 2025 10:30
@Copilot Copilot AI requested a review from srikanthbachala20 June 29, 2025 10:30
@srikanthbachala20
Copy link
Contributor

  • Update the _predict_pythonic_model & _validate_inputs_against_signature functions docscript
  • Revert the feature Input Validation Against Model Signatures
  • Remove the feature Method Selection for Pythonic Models. Only use the predict method for pythonic models

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

Copilot AI commented Jul 2, 2025

  • Update the _predict_pythonic_model & _validate_inputs_against_signature functions docscript
  • Revert the feature Input Validation Against Model Signatures
  • Remove the feature `Method Select...

All requested changes have been implemented in commit 67330e9:

  1. Updated docstrings for _predict_pythonic_model function
  2. Removed the Input Validation Against Model Signatures feature entirely (removed _validate_inputs_against_signature and _validate_parameter_type functions)
  3. Removed Method Selection for Pythonic Models feature (removed --method option and hardcoded to use only 'predict' method)
  4. Removed the --model_path CLI option
  5. Removed the test file that was added for these features

The CLI now supports a simplified pythonic model prediction using only the --inputs option with the predict method hardcoded.

@srikanthbachala20
Copy link
Contributor

Use the predict method instead of traditional method for pythonic models

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

Copilot AI commented Jul 2, 2025

Use the predict method instead of traditional method for pythonic models

Updated the implementation to use the predict method directly for pythonic models instead of fallback to traditional methods. The _predict_pythonic_model function now calls model.predict() with the JSON inputs and removed all traditional prediction fallback logic. Commit 08f2214.

Copilot finished work on behalf of srikanthbachala20 July 2, 2025 10:42
@srikanthbachala20
Copy link
Contributor

Try optimizing the predict command code and update its docstring

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

Copilot AI commented Jul 2, 2025

Try optimizing the predict command code and update its docstring

Optimized the predict command code and updated its docstring with comprehensive improvements:

Code Structure:

  • Extracted helper functions for JSON parsing, input processing, and validation
  • Simplified main function logic and improved readability
  • Enhanced error handling with clearer messages

Documentation:

  • Updated docstring with detailed parameter descriptions and examples
  • Added usage patterns for different model types and compute options
  • Improved CLI help text organization

Technical Improvements:

  • Fixed potential undefined variable bug
  • Centralized validation logic
  • Better multimodal input processing
  • Maintained full backward compatibility

Commit 8257f93.

Copilot finished work on behalf of srikanthbachala20 July 2, 2025 11:33
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.

Update clarifai model predict CLI with SDK new changes
2 participants