Link Search Menu Expand Document Documentation Menu

更新模型

2.12 版本引入

根据 model_ID 更新模型。

有关此 API 的用户访问信息,请参阅模型访问控制注意事项

端点

PUT /_plugins/_ml/models/<model_id>

请求正文字段

下表列出了可更新的字段。并非所有请求字段都适用于所有模型。要确定该字段是否适用于您的模型类型,请参阅注册模型 API

字段 数据类型 描述
连接器 对象 包含托管在第三方平台上的模型的连接器规范。有关更多信息,请参阅为特定模型创建连接器。有关连接器中可更新字段的信息,请参阅更新连接器 API 请求字段
连接器 ID 可选 托管在第三方平台上的模型的独立连接器的连接器 ID。有关更多信息,请参阅独立连接器。要更新独立连接器,您必须取消部署模型,更新连接器,然后重新部署模型。
描述 字符串 模型描述。
is_enabled 布尔型 指定模型是否启用。禁用模型会使其无法用于 Predict API 请求,无论模型的部署状态如何。默认为 true
model_config 对象 模型的配置,包括 model_typeembedding_dimensionframework_typeall_config 是一个可选的 JSON 字符串,包含所有模型配置。有关更多信息,请参阅 model_config 对象
模型组 ID 字符串 要注册此模型的模型组 ID。
名称 字符串 模型名称。
rate_limiter 对象 限制任何用户在模型上调用 Predict API 的次数。有关更多信息,请参阅限制推理调用速率
rate_limiter.limit 整数 任何用户在每个时间单位内对模型调用 Predict API 的最大次数。默认情况下,Predict API 调用次数没有限制。一旦设置了限制,就不能将其重置为无限制。作为替代方案,您可以指定一个较高的限制值和一个较小的时间单位,例如,每纳秒 1 个请求。
rate_limiter.unit 字符串 速率限制器的时间单位。有效值为 DAYSHOURSMICROSECONDSMILLISECONDSMINUTESNANOSECONDSSECONDS
护栏 对象 模型的护栏。
接口 对象 模型的接口。

示例请求:禁用模型

PUT /_plugins/_ml/models/MzcIJX8BA7mbufL6DOwl
{
    "is_enabled": false
}

示例请求:限制模型的推理调用速率

以下请求将您在模型上调用 Predict API 的次数限制为每分钟 4 次 Predict API 调用

PUT /_plugins/_ml/models/T_S-cY0BKCJ3ot9qr0aP
{
  "rate_limiter": {
    "limit": "4",
    "unit": "MINUTES"
  }
}

示例请求:更新护栏

PUT /_plugins/_ml/models/MzcIJX8BA7mbufL6DOwl
{
  "guardrails": {
    "type": "local_regex",
    "input_guardrail": {
      "stop_words": [
        {
          "index_name": "updated_stop_words_input",
          "source_fields": ["updated_title"]
        }
      ],
      "regex": ["updated_regex1", "updated_regex2"]
    },
    "output_guardrail": {
      "stop_words": [
        {
          "index_name": "updated_stop_words_output",
          "source_fields": ["updated_title"]
        }
      ],
      "regex": ["updated_regex1", "updated_regex2"]
    }
  }
}

PUT /_plugins/_ml/models/9uGdCJABjaMXYrp14YRj
{
  "guardrails": {
    "type": "model",
    "input_guardrail": {
      "model_id": "V-G1CJABjaMXYrp1QoUC",
      "response_validation_regex": "^\\s*[Aa]ccept\\s*$"
    },
    "output_guardrail": {
      "model_id": "V-G1CJABjaMXYrp1QoUC",
      "response_validation_regex": "^\\s*[Aa]ccept\\s*$"
    }
  }
}

示例响应

{
  "_index": ".plugins-ml-model",
  "_id": "MzcIJX8BA7mbufL6DOwl",
  "_version": 10,
  "result": "updated",
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 48,
  "_primary_term": 4
}

示例请求:更新模型接口

您可以更新模型的接口以定义输入和输出模式。这对于处理缺乏默认接口或需要自定义的模型很有用。有关模型接口的更多信息,请参阅 Interface 参数

以下示例请求指定了未注册后处理函数的 AI21 Labs Jurassic 模型的输出模式

PUT /_plugins/_ml/models/IMcNB5UB7judm8f45nXo
{
    "interface": {
        "output": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"inference_results\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"output\": {\n            \"type\": \"array\",\n            \"items\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"name\": {\n                  \"type\": \"string\"\n                },\n                \"dataAsMap\": {\n                  \"type\": \"object\",\n                  \"properties\": {\n                    \"id\": {\n                      \"type\": \"number\"\n                    },\n                    \"prompt\": {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"text\": {\n                          \"type\": \"string\"\n                        },\n                        \"tokens\": {\n                          \"type\": \"array\",\n                          \"items\": {\n                            \"type\": \"object\",\n                            \"properties\": {\n                              \"generatedToken\": {\n                                \"type\": \"object\",\n                                \"properties\": {\n                                  \"token\": {\n                                    \"type\": \"string\"\n                                  },\n                                  \"logprob\": {\n                                    \"type\": \"number\"\n                                  },\n                                  \"raw_logprob\": {\n                                    \"type\": \"number\"\n                                  }\n                                }\n                              },\n                              \"textRange\": {\n                                \"type\": \"object\",\n                                \"properties\": {\n                                  \"start\": {\n                                    \"type\": \"number\"\n                                  },\n                                  \"end\": {\n                                    \"type\": \"number\"\n                                  }\n                                }\n                              }\n                            }\n                          }\n                        }\n                      }\n                    },\n                    \"completions\": {\n                      \"type\": \"array\",\n                      \"items\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                          \"data\": {\n                            \"type\": \"object\",\n                            \"properties\": {\n                              \"text\": {\n                                \"type\": \"string\"\n                              },\n                              \"tokens\": {\n                                \"type\": \"array\",\n                                \"items\": {\n                                  \"type\": \"object\",\n                                  \"properties\": {\n                                    \"generatedToken\": {\n                                      \"type\": \"object\",\n                                      \"properties\": {\n                                        \"token\": {\n                                          \"type\": \"string\"\n                                        },\n                                        \"logprob\": {\n                                          \"type\": \"number\"\n                                        },\n                                        \"raw_logprob\": {\n                                          \"type\": \"number\"\n                                        }\n                                      }\n                                    },\n                                    \"textRange\": {\n                                      \"type\": \"object\",\n                                      \"properties\": {\n                                        \"start\": {\n                                          \"type\": \"number\"\n                                        },\n                                        \"end\": {\n                                          \"type\": \"number\"\n                                        }\n                                      }\n                                    }\n                                  }\n                                }\n                              }\n                            }\n                          },\n                          \"finishReason\": {\n                            \"type\": \"object\",\n                            \"properties\": {\n                              \"reason\": {\n                                \"type\": \"string\"\n                              },\n                              \"length\": {\n                                \"type\": \"number\"\n                              }\n                            }\n                          }\n                        }\n                      }\n                    }\n                  }\n                }\n              }\n            }\n          },\n          \"status_code\": {\n            \"type\": \"integer\"\n          }\n        }\n      }\n    }\n  }\n}"
    }
}

如果模型是使用 Amazon Bedrock AI21 Labs Jurassic 蓝图注册的,则会自动应用默认接口。

如果不再需要模型接口,您可以移除输入和输出模式以绕过模型模式验证

PUT /_plugins/_ml/models/IMcNB5UB7judm8f45nXo
{
  "interface": {
    "input": null,
    "output": null
  }
}

示例响应

{
  "_index": ".plugins-ml-model",
  "_id": "IMcNB5UB7judm8f45nXo",
  "_version": 2,
  "result": "updated",
  "_shards": {
    "total": 2,
    "successful": 2,
    "failed": 0
  },
  "_seq_no": 379,
  "_primary_term": 5
}