0

This is algorithmia_utils.py file with Class AlgorithmiaUtils

class AlgorithmiaUtils:

def __init__(self, api_key, username, algo_name, local_dir):
    self.api_key = api_key
    self.username = username
    self.algo_name = algo_name
    self.local_dir = local_dir

    self.algo_namespace = f"{self.username}/{self.algo_name}"
    self.algo_script_path = "{}/{}/src/{}.py".format(
        self.local_dir, algo_name, algo_name
    )
    self.dependency_file_path = "{}/{}/{}".format(
        self.local_dir, algo_name, "requirements.txt"
    )

    self.algo_client = Algorithmia.client(self.api_key)

def upload_model_to_algorithmia(
    self, local_path, algorithmia_data_path, model_name
):
    if not self.algo_client.dir(algorithmia_data_path).exists():
        self.algo_client.dir(algorithmia_data_path).create()
    algorithmia_path = "{}/{}".format(algorithmia_data_path, model_name)
    result = self.algo_client.file(algorithmia_path).putFile(local_path)

I want to use the function upload_model_to_algorithmia from another script.

Thus, I'm trying:

import Algorithmia
import algorithmia_utils as algo_utility

And to call the function:

algo_utility.AlgorithmiaUtils.upload_model_to_algorithmia(
    local_path = local_path, 
    algorithmia_data_path = algorithmia_data_path, 
    model_name = model_name)

Which is returning the error:

TypeError: upload_model_to_algorithmia() missing 1 required positional argument: 'self'

Am I supposed to add an additional argument or have I not imported the file correctly, and how to fix this?

Thanks!

EDIT:

This looks very easy, but so far no solution.

import Algorithmia
import algorithmia_utils as algo_utility
from algorithmia_utils import AlgorithmiaUtils as xpto

And:

xpto.upload_model_to_algorithmia(
    local_path = local_path, 
    algorithmia_data_path = algorithmia_data_path, 
    model_name = model_name)

Return the error:

TypeError: upload_model_to_algorithmia() missing 1 required positional argument: 'self'
3
  • 3
    That's an instance method, not a function. You need an instance of AlgorithmiaUtils to call it. Commented Aug 26, 2021 at 14:35
  • Ok @chepner but could you elaborate? I'm trying to understand this Commented Aug 26, 2021 at 14:37
  • I refer you to the Python tutorial, especially this section on classes. Commented Aug 26, 2021 at 14:39

1 Answer 1

0

do this,

from algorithmia_utils import AlgorithmiaUtils

First create the class object,

algoutil = AlgorithmiaUtils(api_key = api_key, 
    username = username, 
    algo_name = algo_name,
    local_dir = local_dir,)

Now you have created an object called algoutil which is of the class AlgorithmiaUtils, it has all the methods available to that class.

Then you do this to run your function,

algoutil.upload_model_to_algorithmia(local_path = local_path, 
    algorithmia_data_path = algorithmia_data_path, 
    model_name = model_name
)

You need to replace the arguments in quotes after the equal signs with the required information.

I think you have gotten code from https://github.com/algorithmiaio/model-deployment/blob/master/xgboost_notebook_to_algorithmia/algorithmia_utils.py but the main service is hosted by algorithmia over here, https://algorithmia.com/developers/clients/python if i am not wrong, you need to go there and make an account and obtain an api key and insert it into the code. For example, it would look something like this,

from algorithmia_utils import AlgorithmiaUtils

algoutil = AlgorithmiaUtils(api_key = '8hf81qhg3t8h12f', 
    username = 'unstuck', 
    algo_name = 'algo1',
    local_dir = '/home/docs/whatever',)

algoutil.upload_model_to_algorithmia(local_path = '/home/docs/whatever/algo.csv', 
    algorithmia_data_path = '/path/to/file', 
    model_name = 'model1'
)

I have already answered your question on how to create the object and use it, but you need to key in the proper arguments on how to make it work by reading the documentation, this is a different question altogether.

Sign up to request clarification or add additional context in comments.

12 Comments

Thanks for helping, but I get the same error
it says , (upload_model_to_algorithmia() missing 1 required positional argument: 'self, means you did not instantiate it properly
I get the error: TypeError: __init__() missing 4 required positional arguments: 'api_key', 'username', 'algo_name', and 'local_dir' on the algoutil = AlgorithmiaUtils() line
i cant see your code... you need to include the 4 arguments, 'api_key', 'username', 'algo_name', and 'local_dir', you have only provided, local_path = local_path, algorithmia_data_path = algorithmia_data_path, model_name = model_name
I'm just trying to follow the tutorial that is full of leaks like this one and trying to make some sense, thanks for your help!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.