0 / 0
Go back to the English version of the documentation
REST API 示例
Last updated: 2024年12月05日
Decision Optimization REST API 部署

您可以使用watsonx.aiRuntime REST API 部署Decision Optimization模型、创建和监控作业并获取解决方案。

准备工作

您必须拥有IBM Cloud帐户。 请参阅 https://www.ibm.com/cloud/
  1. 登录 IBM Cloud
  2. 创建 API 密钥。 从打开的 "成功创建 API 密钥窗口中复制或下载(关闭该窗口后将无法再次访问)。

  3. 可选:创建watsonx.ai运行时服务
  4. IBM Cloud资源列表视图中的人工智能/机器Machine Learning服务 列表中选择一个watsonx.aiRuntime实例。

    从信息窗格中复制watsonx.aiRuntime实例的名称GUIDCRN。 (要打开信息窗格,请单击watsonx.aiRuntime服务名称旁边行中的任意位置,但不要单击名称本身。 然后在同一窗口中打开信息窗格)

  5. 可选:创建Cloud Object Storage
  6. IBM Cloud资源列表视图中的存储资源列表中选择Cloud Object Storage实例。

    从存储实例的信息窗格中复制名称CRN

  7. 可选:从https://dataplatform.cloud.ibm.com用户界面创建部署空间。 您还可以使用 REST API 创建部署空间。 请参阅使用 REST API 创建部署空间。
  8. 部署列表中选择一个部署空间。

    "管理">"常规 "选项卡复制空间 GUID。 有关更多信息,请参阅部署空间

关于本任务

以下步骤将向您展示如何使用watsonx.aiRuntime REST API 部署Decision Optimization模型。 REST API 示例使用 curl,后者是一个命令行工具和库,用于以 URL 语法传输数据。 您可以在http://curl.haxx.se 下载 curl 并了解更多相关信息。 有关与 Decision Optimization相关的 REST API 的更多信息,请参阅以下部分:

对于 Windows 用户,请将用作多行分隔符的 \ 改为 ^,并在这些代码示例中使用双引号 "。 另外,Windows 用户必须在标题行中至少使用一个空格字符的缩进。

为方便说明,此过程中的某些代码示例已放在 json 文件中,以使命令更容易阅读和使用。

使用 REST API 创建部署后,还可以通过https://dataplatform.cloud.ibm.com用户界面中的 "部署 > 空间"页面查看部署并向其发送作业。

过程

  1. 使用您的IBM CloudAPI 密钥 生成 IAM 令牌,如下所示。
    curl "https://iam.cloud.ibm.com/identity/token" \
      -d "apikey=YOUR_API_KEY_HERE&grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey" \
      -H "Content-Type: application/x-www-form-urlencoded" \
      -H "Authorization: Basic Yng6Yng="
    输出示例:
    {
       "access_token": "****** obtained IAM token ******************************",
       "refresh_token": "**************************************",
       "token_type": "Bearer",
       "expires_in": 3600,
       "expiration": 1554117649,
       "scope": "ibm openid"
    }

    在所有 API 调用中,使用以 Authorization 头中的单词 BearerML-Instance-ID 头中的单词 watsonx.ai Runtime service GUID 为前缀的获取令牌 (access_token 值)。

  2. 可选: 如果未如前所述从用户界面获取 SPACE-ID ,那么可以使用 REST API 创建空间,如下所示。 在所有 API 调用中,使用 Authorization 头中以词 bearer 开头的先前获取的令牌。
    curl --location --request POST \
      "https://api.dataplatform.cloud.ibm.com/v2/spaces" \
      -H "Authorization: Bearer TOKEN-HERE" \
      -H "ML-Instance-ID: MACHINE-LEARNING-SERVICE-GUID-HERE" \
      -H "Content-Type: application/json" \
      --data-raw "{
      "name": "SPACE-NAME-HERE",
      "description": "optional description here",
      "storage": {
          "resource_crn": "COS-CRN-ID-HERE"
      },
      "compute": [{
        "name": "MACHINE-LEARNING-SERVICE-NAME-HERE",
        "crn": "MACHINE-LEARNING-SERVICE-CRN-ID-HERE"
      }]
    }"
    对于 Windows 用户,请将 --data-raw 命令置于一行上,并将此命令中所有的 " 替换为 \",如下所示:
    curl --location --request POST ^
      "https://api.dataplatform.cloud.ibm.com/v2/spaces" ^
      -H "Authorization: Bearer TOKEN-HERE" ^
      -H "ML-Instance-ID: MACHINE-LEARNING-SERVICE-GUID-HERE" ^
      -H "Content-Type: application/json" ^
      --data-raw "{\"name\": "SPACE-NAME-HERE",\"description\": \"optional description here\",\"storage\": {\"resource_crn\": \"COS-CRN-ID-HERE\"  },\"compute\": [{\"name\": "MACHINE-LEARNING-SERVICE-NAME-HERE\",\"crn\": \"MACHINE-LEARNING-SERVICE-CRN-ID-HERE\"  }]}"
    或者,将数据置于单独的文件中。
    SPACE-ID 会在 metadata 小节的 id 字段中返回。

    输出示例:

    {
      "entity": {
        "compute": [
          {
            "crn": "MACHINE-LEARNING-SERVICE-CRN",
            "guid": "MACHINE-LEARNING-SERVICE-GUID",
            "name": "MACHINE-LEARNING-SERVICE-NAME",
            "type": "machine_learning"
          }
        ],
        "description": "string",
        "members": [
          {
            "id": "XXXXXXX",
            "role": "admin",
            "state": "active",
            "type": "user"
          }
        ],
        "name": "name",
        "scope": {
          "bss_account_id": "account_id"
        },
        "status": {
          "state": "active"
        }
      },
      "metadata": {
        "created_at": "2020-07-17T08:36:57.611Z",
        "creator_id": "XXXXXXX",
        "id": "SPACE-ID",
        "url": "/v2/spaces/SPACE-ID"
      }
    }

    您必须等待部署空间状态为 "active",然后再继续。 可以进行轮询以检查状态,如下所示。

    curl --location --request GET "https://api.dataplatform.cloud.ibm.com/v2/spaces/SPACE-ID-HERE" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json"
  3. 创建 Decision Optimization 模型

    所有 API 请求都需要 version 参数,该参数接受格式为 version=YYYY-MM-DD 的日期。 此代码示例会发布一个模型,该模型使用文件 create_model.json。 URL 会根据您为watsonx.aiRuntime服务选择的地区/位置而有所不同。 请参见端点 URL

    curl --location --request POST \
      "https://us-south.ml.cloud.ibm.com/ml/v4/models?version=2020-08-01" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json" \
      -d @create_model.json
    create_model.json 文件包含以下代码:
    {
      "name": "ModelName",
      "description": "ModelDescription",
      "type": "do-docplex_22.1",
      "software_spec": {
        "name": "do_22.1"
      },
      "custom": {
          "decision_optimization": {
            "oaas.docplex.python": "3.11"
          }
      },
      "space_id": "SPACE-ID-HERE"
    }

    此处在 custom 块中显式声明 Python 版本 。 这是可选操作。 如果没有它,您的模型将使用默认版本,当前版本为 Python 3.11 。 由于缺省版本将随时间演变,因此声明 Python 版本显式使您能够在稍后轻松更改该版本,或者在更新缺省版本时继续使用较旧的受支持版本。 目前支持的版本是 3.11 和 3.10 (已废弃)

    如果您希望能够从用户界面针对此模型运行作业,而非只能使用 REST API,那么必须定义输入数据和输出数据的模式。 如果创建模型时未定义模式,那么只能使用 REST API 来运行作业,无法从用户界面运行。

    您还可以使用为优化模型中的输入和输出指定的模式:

    {
      "name": "Diet-Model-schema",
      "description": "Diet",
      "type": "do-docplex_22.1",
      "schemas": {
        "input": [
          {
            "id": "diet_food_nutrients",
            "fields": [
              { "name": "Food",  "type": "string" },
              { "name": "Calories", "type": "double" },
              { "name": "Calcium", "type": "double" },
              { "name": "Iron", "type": "double" },
              { "name": "Vit_A", "type": "double" },
              { "name": "Dietary_Fiber", "type": "double" },
              { "name": "Carbohydrates", "type": "double" },
              { "name": "Protein", "type": "double" }
            ]
          },
          {
            "id": "diet_food",
            "fields": [
              { "name": "name", "type": "string" },
              { "name": "unit_cost", "type": "double" },
              { "name": "qmin", "type": "double" },
              { "name": "qmax", "type": "double" }
            ]
          },
          {
            "id": "diet_nutrients",
            "fields": [
              { "name": "name", "type": "string" },
              { "name": "qmin", "type": "double" },
              { "name": "qmax", "type": "double" }
            ]
          }
        ],
        "output": [
          {
            "id": "solution",
            "fields": [
              { "name": "name", "type": "string" },
              { "name": "value", "type": "double" }
            ]
          }
        ]
      },
      "software_spec": {
        "name": "do_22.1"
      },
      "space_id": "SPACE-ID-HERE"
    }
    
    发布模型时,您需提供信息,指出其模型类型以及所要使用的软件规范
    模型类型可以是以下示例类型:
    • OPL 模型的 do-opl_22.1
    • do-cplex_22.1 (对于 CPLEX 模型)
    • 针对 CP 模型的 do-cpo_22.1
    • do-docplex_22.1 for Python 模型

    版本 20.1 也可用于这些模型类型。

    对于 软件规范,可以使用缺省规范的名称 do_22.1do_20.1。 另请参阅 扩展软件规范笔记本 ,其中显示了如何扩展 Decision Optimization 软件规范 (带有 DOcplex 模型的其他 Python 库的运行时)。

    MODEL-ID 会在 metadataid 字段中返回。

    输出示例:
    {
      "entity": {
        "software_spec": {
          "id": "SOFTWARE-SPEC-ID"
        },
        "type": "do-docplex_20.1"
      },
      "metadata": {
        "created_at": "2020-07-17T08:37:22.992Z",
        "description": "ModelDescription",
        "id": "MODEL-ID",
        "modified_at": "2020-07-17T08:37:22.992Z",
        "name": "ModelName",
        "owner": "***********",
        "space_id": "SPACE-ID"
      }
    }
  4. 上载可供部署的 Decision Optimization 模型阐述
    首先将模型压缩成(tar.gz, .zip or .jar) 文件,然后上传至watsonx.aiRuntime服务进行部署。
    此代码示例上载包含 Python 模型且不含主数据的名为 diet.zip 的模型:
    curl --location --request PUT \
      "https://us-south.ml.cloud.ibm.com/ml/v4/models/MODEL-ID-HERE/content?version=2020-08-01&space_id=SPACE-ID-HERE&content_format=native" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/gzip" \
      --data-binary "@diet.zip"
    您可以从DO-samples 下载此示例和其他模型。 选择相应的产品和版本子文件夹。
  5. 部署模型
    创建模型引用。 请使用 SPACE-ID、您创建准备就绪可供部署的模型时获取的 MODEL-ID,以及硬件规范 例如:
    curl --location --request POST "https://us-south.ml.cloud.ibm.com/ml/v4/deployments?version=2020-08-01" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json" \
      -d @deploy_model.json
    The deploy_model.json file contains the following code:
    {
      "name": "Test-Diet-deploy",
      "space_id": "SPACE-ID-HERE",
      "asset": {
        "id": "MODEL-ID-HERE"
      },
      "hardware_spec": {
        "name": "S"
      },
      "batch": {}
    }
    DEPLOYMENT-ID 会在 metadataid 字段中返回。 输出示例:
    {
      "entity": {
        "asset": {
          "id": "MODEL-ID"
        },
        "custom": {},
        "description": "",
        "hardware_spec": {
          "id": "HARDWARE-SPEC-ID",
          "name": "S",
          "num_nodes": 1
        },
        "name": "Test-Diet-deploy",
        "space_id": "SPACE-ID",
        "status": {
          "state": "ready"
        }
      },
      "metadata": {
        "created_at": "2020-07-17T09:10:50.661Z",
        "description": "",
        "id": "DEPLOYMENT-ID",
        "modified_at": "2020-07-17T09:10:50.661Z",
        "name": "test-Diet-deploy",
        "owner": "**************",
        "space_id": "SPACE-ID"
      }
    }
  6. 部署后,您可以 监视模型的部署状态。 请使用 DEPLOYMENT-ID
    例如:
    curl --location --request GET "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/DEPLOYMENT-ID-HERE?version=2020-08-01&space_id=SPACE-ID-HERE" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json"

    输出示例:

    {
      "entity": {
        "asset": {
          "id": "MODEL-ID"
        },
        "custom": {},
        "description": "",
        "hardware_spec": {
          "id": "HARDWARE-SPEC-ID",
          "name": "S",
          "num_nodes": 1
        },
        "name": "Test-Diet-deploy",
        "space_id": "SPACE-ID",
        "status": {
          "state": "ready"
        }
      },
      "metadata": {
        "created_at": "2020-11-04T16:22:14.442Z",
        "description": "",
        "id": "DEPLOYMENT-ID",
        "modified_at": "2020-11-04T16:22:14.442Z",
        "name": "test-Diet-deploy",
        "owner": "**************",
        "space_id": "SPACE-ID"
      }
    }
  7. 然后,您可以针对定义输入数据和输出 (优化求解的结果) 以及日志文件的已部署模型 提交作业
    例如,以下显示名为 myjob.json 的文件的内容。 其包含(内联)输入数据、一些求解参数,并指定输出将是 .csv 文件。 更多信息,请参阅Decision Optimization批量部署和模型执行
    {
    	"name":"test-job-diet",
    	"space_id": "SPACE-ID-HERE",
    	"deployment": {
    		"id": "DEPLOYMENT-ID-HERE"
    	},
    	"decision_optimization" : {
    		"solve_parameters" : {
    			"oaas.logAttachmentName":"log.txt",
    			"oaas.logTailEnabled":"true"
    		},
    		"input_data": [
    			{
    				"id":"diet_food.csv",
    				"fields" : ["name","unit_cost","qmin","qmax"],
    				"values" : [
    					["Roasted Chicken", 0.84, 0, 10],
    					["Spaghetti W/ Sauce", 0.78, 0, 10],
    					["Tomato,Red,Ripe,Raw", 0.27, 0, 10],
    					["Apple,Raw,W/Skin", 0.24, 0, 10],
    					["Grapes", 0.32, 0, 10],
    					["Chocolate Chip Cookies", 0.03, 0, 10],
    					["Lowfat Milk", 0.23, 0, 10],
    					["Raisin Brn", 0.34, 0, 10],
    					["Hotdog", 0.31, 0, 10]
    				]
    			},
    			{
    				"id":"diet_food_nutrients.csv",
    				"fields" : ["Food","Calories","Calcium","Iron","Vit_A","Dietary_Fiber","Carbohydrates","Protein"],
    				"values" : [
    					["Spaghetti W/ Sauce", 358.2, 80.2, 2.3, 3055.2, 11.6, 58.3, 8.2],
    					["Roasted Chicken", 277.4, 21.9, 1.8, 77.4, 0, 0, 42.2],
    					["Tomato,Red,Ripe,Raw", 25.8, 6.2, 0.6, 766.3, 1.4, 5.7, 1],
    					["Apple,Raw,W/Skin", 81.4, 9.7, 0.2, 73.1, 3.7, 21, 0.3],
    					["Grapes", 15.1, 3.4, 0.1, 24, 0.2, 4.1, 0.2],
    					["Chocolate Chip Cookies", 78.1, 6.2, 0.4, 101.8, 0, 9.3, 0.9],
    					["Lowfat Milk", 121.2, 296.7, 0.1, 500.2, 0, 11.7, 8.1],
    					["Raisin Brn", 115.1, 12.9, 16.8, 1250.2, 4, 27.9, 4],
    					["Hotdog", 242.1, 23.5, 2.3, 0, 0, 18, 10.4]
    				]
    			},
    			{
    				"id":"diet_nutrients.csv",
    				"fields" : ["name","qmin","qmax"],
    				"values" : [
    					["Calories", 2000, 2500],
    					["Calcium", 800, 1600],
    					["Iron", 10, 30],
    					["Vit_A", 5000, 50000],
    					["Dietary_Fiber", 25, 100],
    					["Carbohydrates", 0, 300],
    					["Protein", 50, 100]
    				]
    			}
    		],
    		"output_data": [
    			{
    				"id":".*\\.csv"
    			}
    		]
    	}
    }
    此代码示例发布使用此文件 myjob.json 的作业。
    curl --location --request POST "https://us-south.ml.cloud.ibm.com/ml/v4/deployment_jobs?version=2020-08-01&space_id=SPACE-ID-HERE" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json" \
      -H "cache-control: no-cache" \
      -d @myjob.json
    
    JOB-ID 随即返回。 输出示例:(作业排队)
    {
      "entity": {
        "decision_optimization": {
          "input_data": [{
            "id": "diet_food.csv",
            "fields": ["name", "unit_cost", "qmin", "qmax"],
            "values": [["Roasted Chicken", 0.84, 0, 10], ["Spaghetti W/ Sauce", 0.78, 0, 10], ["Tomato,Red,Ripe,Raw", 0.27, 0, 10], ["Apple,Raw,W/Skin", 0.24, 0, 10], ["Grapes", 0.32, 0, 10], ["Chocolate Chip Cookies", 0.03, 0, 10], ["Lowfat Milk", 0.23, 0, 10], ["Raisin Brn", 0.34, 0, 10], ["Hotdog", 0.31, 0, 10]]
          }, {
            "id": "diet_food_nutrients.csv",
            "fields": ["Food", "Calories", "Calcium", "Iron", "Vit_A", "Dietary_Fiber", "Carbohydrates", "Protein"],
            "values": [["Spaghetti W/ Sauce", 358.2, 80.2, 2.3, 3055.2, 11.6, 58.3, 8.2], ["Roasted Chicken", 277.4, 21.9, 1.8, 77.4, 0, 0, 42.2], ["Tomato,Red,Ripe,Raw", 25.8, 6.2, 0.6, 766.3, 1.4, 5.7, 1], ["Apple,Raw,W/Skin", 81.4, 9.7, 0.2, 73.1, 3.7, 21, 0.3], ["Grapes", 15.1, 3.4, 0.1, 24, 0.2, 4.1, 0.2], ["Chocolate Chip Cookies", 78.1, 6.2, 0.4, 101.8, 0, 9.3, 0.9], ["Lowfat Milk", 121.2, 296.7, 0.1, 500.2, 0, 11.7, 8.1], ["Raisin Brn", 115.1, 12.9, 16.8, 1250.2, 4, 27.9, 4], ["Hotdog", 242.1, 23.5, 2.3, 0, 0, 18, 10.4]]
          }, {
            "id": "diet_nutrients.csv",
            "fields": ["name", "qmin", "qmax"],
            "values": [["Calories", 2000, 2500], ["Calcium", 800, 1600], ["Iron", 10, 30], ["Vit_A", 5000, 50000], ["Dietary_Fiber", 25, 100], ["Carbohydrates", 0, 300], ["Protein", 50, 100]]
          }],
          "output_data": [
            {
              "id": ".*\\.csv"
            }
          ],
          "solve_parameters": {
            "oaas.logAttachmentName": "log.txt",
            "oaas.logTailEnabled": "true"
          },
          "status": {
            "state": "queued"
          }
        },
        "deployment": {
          "id": "DEPLOYMENT-ID"
        },
        "platform_job": {
          "job_id": "",
          "run_id": ""
        }
      },
      "metadata": {
        "created_at": "2020-07-17T10:42:42.783Z",
        "id": "JOB-ID",
        "name": "test-job-diet",
        "space_id": "SPACE-ID"
      }
    }
    
  8. 您还可以 监视作业状态。 请使用 JOB-ID
    例如:
    curl --location --request GET \
      "https://us-south.ml.cloud.ibm.com/ml/v4/deployment_jobs/JOB-ID-HERE?version=2020-08-01&space_id=SPACE-ID-HERE" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json"
    输出示例(该作业已完成):
    {
      "entity": {
        "decision_optimization": {
          "input_data": [{
            "id": "diet_food.csv",
            "fields": ["name", "unit_cost", "qmin", "qmax"],
            "values": [["Roasted Chicken", 0.84, 0, 10], ["Spaghetti W/ Sauce", 0.78, 0, 10], ["Tomato,Red,Ripe,Raw", 0.27, 0, 10], ["Apple,Raw,W/Skin", 0.24, 0, 10], ["Grapes", 0.32, 0, 10], ["Chocolate Chip Cookies", 0.03, 0, 10], ["Lowfat Milk", 0.23, 0, 10], ["Raisin Brn", 0.34, 0, 10], ["Hotdog", 0.31, 0, 10]]
          }, {
            "id": "diet_food_nutrients.csv",
            "fields": ["Food", "Calories", "Calcium", "Iron", "Vit_A", "Dietary_Fiber", "Carbohydrates", "Protein"],
            "values": [["Spaghetti W/ Sauce", 358.2, 80.2, 2.3, 3055.2, 11.6, 58.3, 8.2], ["Roasted Chicken", 277.4, 21.9, 1.8, 77.4, 0, 0, 42.2], ["Tomato,Red,Ripe,Raw", 25.8, 6.2, 0.6, 766.3, 1.4, 5.7, 1], ["Apple,Raw,W/Skin", 81.4, 9.7, 0.2, 73.1, 3.7, 21, 0.3], ["Grapes", 15.1, 3.4, 0.1, 24, 0.2, 4.1, 0.2], ["Chocolate Chip Cookies", 78.1, 6.2, 0.4, 101.8, 0, 9.3, 0.9], ["Lowfat Milk", 121.2, 296.7, 0.1, 500.2, 0, 11.7, 8.1], ["Raisin Brn", 115.1, 12.9, 16.8, 1250.2, 4, 27.9, 4], ["Hotdog", 242.1, 23.5, 2.3, 0, 0, 18, 10.4]]
          }, {
            "id": "diet_nutrients.csv",
            "fields": ["name", "qmin", "qmax"],
            "values": [["Calories", 2000, 2500], ["Calcium", 800, 1600], ["Iron", 10, 30], ["Vit_A", 5000, 50000], ["Dietary_Fiber", 25, 100], ["Carbohydrates", 0, 300], ["Protein", 50, 100]]
          }],
          "output_data": [{
            "fields": ["Name", "Value"],
            "id": "kpis.csv",
            "values": [["Total Calories", 2000], ["Total Calcium", 800.0000000000001], ["Total Iron", 11.278317739831891], ["Total Vit_A", 8518.432542485823], ["Total Dietary_Fiber", 25], ["Total Carbohydrates", 256.80576358904455], ["Total Protein", 51.17372234135308], ["Minimal cost", 2.690409171696264]]
          }, {
            "fields": ["name", "value"],
            "id": "solution.csv",
            "values": [["Spaghetti W/ Sauce", 2.1551724137931036], ["Chocolate Chip Cookies", 10], ["Lowfat Milk", 1.8311671008899097], ["Hotdog", 0.9296975991385925]]
          }],
          "output_data_references": [],
          "solve_parameters": {
            "oaas.logAttachmentName": "log.txt",
            "oaas.logTailEnabled": "true"
          },
          "solve_state": {
            "details": {
              "KPI.Minimal cost": "2.690409171696264",
              "KPI.Total Calcium": "800.0000000000001",
              "KPI.Total Calories": "2000.0",
              "KPI.Total Carbohydrates": "256.80576358904455",
              "KPI.Total Dietary_Fiber": "25.0",
              "KPI.Total Iron": "11.278317739831891",
              "KPI.Total Protein": "51.17372234135308",
              "KPI.Total Vit_A": "8518.432542485823",
              "MODEL_DETAIL_BOOLEAN_VARS": "0",
              "MODEL_DETAIL_CONSTRAINTS": "7",
              "MODEL_DETAIL_CONTINUOUS_VARS": "9",
              "MODEL_DETAIL_INTEGER_VARS": "0",
              "MODEL_DETAIL_KPIS": "[\"Total Calories\", \"Total Calcium\", \"Total Iron\", \"Total Vit_A\", \"Total Dietary_Fiber\", \"Total Carbohydrates\", \"Total Protein\", \"Minimal cost\"]",
              "MODEL_DETAIL_NONZEROS": "57",
              "MODEL_DETAIL_TYPE": "LP",
              "PROGRESS_CURRENT_OBJECTIVE": "2.6904091716962637"
            },
            "latest_engine_activity": [
              "[2020-07-21T16:37:36Z, INFO] Model: diet",
              "[2020-07-21T16:37:36Z, INFO]  - number of variables: 9",
              "[2020-07-21T16:37:36Z, INFO]    - binary=0, integer=0, continuous=9",
              "[2020-07-21T16:37:36Z, INFO]  - number of constraints: 7",
              "[2020-07-21T16:37:36Z, INFO]    - linear=7",
              "[2020-07-21T16:37:36Z, INFO]  - parameters: defaults",
              "[2020-07-21T16:37:36Z, INFO]  - problem type is: LP",
              "[2020-07-21T16:37:36Z, INFO] Warning: Model: \"diet\" is not a MIP problem, progress listeners are disabled",
              "[2020-07-21T16:37:36Z, INFO] objective: 2.690",
              "[2020-07-21T16:37:36Z, INFO]   \"Spaghetti W/ Sauce\"=2.155",
              "[2020-07-21T16:37:36Z, INFO]   \"Chocolate Chip Cookies\"=10.000",
              "[2020-07-21T16:37:36Z, INFO]   \"Lowfat Milk\"=1.831",
              "[2020-07-21T16:37:36Z, INFO]   \"Hotdog\"=0.930",
              "[2020-07-21T16:37:36Z, INFO] solution.csv"
            ],
            "solve_status": "optimal_solution"
          },
          "status": {
            "completed_at": "2020-07-21T16:37:36.989Z",
            "running_at": "2020-07-21T16:37:35.622Z",
            "state": "completed"
          }
        },
        "deployment": {
          "id": "DEPLOYMENT-ID"
        }
      },
      "metadata": {
        "created_at": "2020-07-21T16:37:09.130Z",
        "id": "JOB-ID",
        "modified_at": "2020-07-21T16:37:37.268Z",
        "name": "test-job-diet",
        "space_id": "SPACE-ID"
      }
    }
    
  9. 可选: 您可以 删除作业 ,如下所示:
    curl --location --request DELETE "https://us-south.ml.cloud.ibm.com/ml/v4/deployment_jobs/JOB-ID-HERE?version=2020-08-01&space_id=SPACE-ID-HERE&hard_delete=true" \
      -H "Authorization: bearer TOKEN-HERE" 
    如果使用 API 来删除作业,那么它仍会显示在用户界面中。
  10. 可选: 您可以 删除部署 ,如下所示:
    curl --location --request DELETE "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/DEPLOYMENT-ID-HERE?version=2020-08-01&space_id=SPACE-ID-HERE" \
      -H "Authorization: bearer TOKEN-HERE" 
    如果使用 API 来删除包含作业的部署,那么这些作业仍会显示在用户界面中的部署空间中。

结果

在部署模型并执行作业后,将以内联方式或者在指定的文件和位置中提供解决方案结果,例如,使用 S3 引用。 您可以使用 deployment-ID 发布新作业而无需重新部署模型。

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more