Exposed Python Function as an API not passing parameters from test query

Options
samanthamarkley
samanthamarkley Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 6 Partner
edited July 16 in Using Dataiku

I am trying to test exposing a python function as an API but it seems there is a bug in the test query passing parameters to the function. The function is extremely simple and I am currently just trying to print the test parameters but it seems the query is passing through as empty. I have tried many different possible configurations of the test query syntax with no success and can not track down a clear cause from the logs. Below is the function and test query as well a screen shot of the result when run:

#Code
def api_py_function(**kwargs):
    return kwargs


#Test Query
{
   "paramNameToReplace": "paramValueToReplace"
}

Screenshot 2023-11-22 at 3.15.36 PM.png

Best Answer

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,717 Neuron
    edited 4:21PM
    Options

    Hi, don't use **kwargs or *args, just use standard function parameters:

    #Code
    def api_py_function(param1):
        return param1

  • samanthamarkley
    samanthamarkley Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 6 Partner
    Options

    I have also tried that and receive an error message: Failed: Failed to run function : <class 'TypeError'> : api_py_function() missing 1 required positional argument: 'param1'

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,717 Neuron
    Options

    The test query also needs to call the parameter param1. These are named parameters on a REST API backend, they can't be guessed by position.

  • samanthamarkley
    samanthamarkley Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 6 Partner
    Options
  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,717 Neuron
    Options

    What Dataiku version are you on?

  • samanthamarkley
    samanthamarkley Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 6 Partner
    Options
  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,717 Neuron
    edited 4:21PM
    Options

    When you create a Python Function endpoint the function snipped is this:

    # Insert here initialization code
    
    # This function is the entry point for your Python function API
    # You can call this function with passing "param1", "param2",
    # "param3" as arguments to the API call
    # (see REST API documentation)
    def api_py_function(param1, param2, param3):
        return param1 + param2 * param3

    I then go to the Test queries and click on ADD QUERIES and add this as a test query:

    {
       "param1": 1,
       "param2": 2,
       "param3": 3
    }

    And when I test this is what I get:

    Screenshot 2023-11-22 at 21.24.56.png

Setup Info
    Tags
      Help me…