Migrating Python functions

After migrating your assets, you must manually modify the score() of Python functions to be compatible with V4 APIs. The is because the input for the score function is the scoring payload data and the schema of v4 API's scoring payload is changed from the format used in the v3 APIs. Similarly, you must update the output of the score response to be in V4's scoring response format.

Follow these steps to update your Python function.

  1. Migrate the Python function from a V3 to V4 asset

  2. Download the Python function content from the Watson Machine Language repository

  3. Modify the Python function code related to score().

  4. Re-package the function and upload the attachment back to the corresponding /v4/functions asset.

  5. Deploy the Python function.

Updating the scoring payload

Update the scoring payload using these examples as a guide to the new format.

Input: V3 scoring payload example

          {
            "fields": ["GENDER", "AGE", "PROFESSION"],
            "values": [
              ["M", 27, "Professional"],
              ["F", 56, "Hospitality"]
            ]
          }

Input: V4 scoring input payload example:

        {
           "input_data": [{
                            "fields": [ "GENDER", "age", "PROFESSION"],
                            "values": [
                                        ["M", 23, "student"],
                                        ["F", 33, "engineer"]
                                      ]
                        }]
         }

Output: V3 scoring payload example

          {
            "fields": ["prediction", "predicted_label"],
            "values": [
              [0, "Camping Equipment"],
              [0, "Camping Equipment"]
            ]
          }

Output: V4 scoring input payload example

        {
           "predictions": [{
                              {
                                "fields": ["prediction", "predicted_label"],
                                "values": [
                                  [0, "Camping Equipment"],
                                  [0, "Camping Equipment"]
                                ]
                              }
                        }]
         }