Skip to content

Conversation

Copy link

Copilot AI commented Sep 26, 2025

Problem

The deepaas-cli command would fail with an AttributeError when trying to access AI models that only implement prediction functionality (missing get_train_args()) or only training functionality (missing get_predict_args()).

For example, with a prediction-only model:

$ deepaas-cli predict --help
Traceback (most recent call last):
  ...
  train_args = _fields_to_dict(model_obj.get_train_args())
                                ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'my_model.api' has no attribute 'get_train_args'. Did you mean: 'get_predict_args'?

This issue prevented users from using the CLI with models that legitimately only provide one type of functionality.

Root Cause

The CLI module in deepaas/cmd/cli.py was loading models directly and immediately calling both get_predict_args() and get_train_args() without any error handling, even though the ModelWrapper class already existed with proper exception handling for missing methods.

Solution

Enabled the use of ModelWrapper in the CLI module by uncommenting the wrapper instantiation. The ModelWrapper class already handles missing methods gracefully by catching AttributeError and NotImplementedError, returning empty dictionaries for missing methods.

# Before (commented out):
# model_obj = v2_wrapper.ModelWrapper(name=model_name, model_obj=model_obj)

# After (enabled):
model_obj = v2_wrapper.ModelWrapper(name=model_name, model_obj=model_obj)

Impact

  • deepaas-cli predict --help now works for training-only models
  • deepaas-cli train --help now works for prediction-only models
  • ✅ Both commands work for models missing either method
  • ✅ Existing functionality for complete models is preserved
  • ✅ No breaking changes or additional dependencies required

Testing

Added comprehensive test coverage in deepaas/tests/test_cli_fix.py covering:

  • Predict-only models (missing get_train_args)
  • Train-only models (missing get_predict_args)
  • Minimal models (missing both methods)
  • Validation that the original problem existed with direct model access

This minimal change resolves the GitHub issue while maintaining full backward compatibility with existing models.

Fixes #XXX

Original prompt

This section details on the original issue you should resolve

<issue_title>deepaas-cli always expects get_predict_args() and get_train_args()</issue_title>
<issue_description>### Description

Some AI models provide only prediction, therefore "get_train_args()" function does not exist. It does not cause an error in deepaas-run but deepaas-cli by default always expects both of the "get_train_args()" and "get_predict_args()" to be present.

Steps to Reproduce

  1. in a AI module comment "get_train_args()"
  2. call deepaas-cli predict --help
  3. see error as e.g.
train_args = _fields_to_dict(model_obj.get_train_args())
                                ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'zooprocess_multiple_separator.api' has no attribute 'get_train_args'. Did you mean: 'get_predict_args'?

Expected behavior:

deepaas-cli is able to deal with cases when only predict() or train() is available

Versions

DEEPaaS API 2.5.2 and earlier
</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #189

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

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
72.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copilot AI changed the title [WIP] deepaas-cli always expects get_predict_args() and get_train_args() Fix deepaas-cli to handle models missing get_train_args() or get_predict_args() Sep 26, 2025
Copilot AI requested a review from alvarolopez September 26, 2025 11:05
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.

2 participants