使用 Microsoft Entra ID 创建自定义模型 - 本主题概述了在 AI Agent Studio 中为自定义模型定义配置 Microsoft Entra ID(前身为 Azure AD)身份验证的步骤,从而实现您的模型与 Automation 360 的无缝集成。

Automation 360

本主题概述了在 AI Agent Studio 中为自定义模型定义配置 Microsoft Entra ID(前身为 Azure AD)身份验证的步骤,从而实现您的模型与 Automation 360 的无缝集成。

关于此任务

仅通过 OAuth2 身份验证支持 Entra ID,当与要求基于 Entra 的访问令牌的 Microsoft 托管模型集成时,必须使用此方法。
  • 当目标模型供应商仅支持 OAuth2 身份验证时,请使用 Entra ID。
  • 当无法将 API 密钥身份验证与 OAuth2 并行使用时,Azure 托管服务通常会出现这种情况。
  • 例如,Azure OpenAI 模型默认采用 API 密钥身份验证,但如果您的安全要求通过 Entra ID 强制执行 OAuth2,则必须通过自定义模型定义路径配置该模型。

要下载并使用 Postman 集合(Entra ID 示例),请单击此链接 Postman 集合 - Entra ID 示例。

开始之前

为什么要使用自定义模型和 Entra ID?

Azure OpenAI 在用户界面中支持 API 密钥身份验证;如果需要 OAuth2/Entra ID,请通过 Custom Model API 进行定义,因为每个供应商在用户界面中一次只能公开一种身份验证机制。

过程

  1. 一旦建立 OAuth 连接,您可以使用 创建自定义模型 API 创建自定义模型定义。 此 API 需要一个 JSON 负载架构,用于描述您的模型,包括供应商名称、模型名称、身份验证协议以及 API 端点的详细信息。
  2. 使用以下 authAction 块,通过已配置的 Entra ID 创建自定义模型连接。 请注意以下关键身份验证参数:
    "authAction": {
      "authType": "OAUTH2",
      "oAuth": {
        "location": "header",
        "keyName": "Authorization",
        "prefix": "Bearer "
      }
    }
    
    • authType:必须为 OAUTH2
    • 位置:header
    • keyName: 授权
    • 前缀: Bearer,包含令牌(在 Bearer 后添加一个空格)
  3. 发送请求。 该请求将在下方示例中进行说明。 成功后,将创建自定义模型定义,并且在您在 AI Agent Studio 中创建 模型连接 时可以选择。

使用 Entra ID 的自定义模型定义

以下是针对 Azure OpenAI GPT-4.1 mini 部署,使用 Entra OAuth2 的简化示例:

POST https:/{{ControlRoomURL}}/gai/prompttools/v1/custommodel
请求正文:
{
	"name": "AAI Docs Example - Entra",
	"version": "0",
	"authAction": {
		"authType": "OAUTH2",
		"oAuth": {
			"location": "header",
			"keyName": "Authorization",
			"prefix": "Bearer "
		}
	},
	"apiType": "REST",
	"actions": [
		{
			"name": "gpt-4.1-mini",
			"displayName": "GPT-4.1 mini",
			"description": "GPT-4.1 mini provides a balance between intelligence, speed, and cost that makes it an attractive model for many use cases.",
			"method": "POST",
			"uri": "https://{resourceName}.openai.azure.com/openai/deployments/{deployment}/chat/completions?api-version={apiVersion}",
			"params": [
				{
					"type": "PATH_PARAM",
					"attribute": [
						{
							"name": "resourceName",
							"label": "Resource Name",
							"value": {
								"type": "TEXT",
								"string": "genaitemplateplatformeastca"
							}
						}
					]
				},
				{
					"type": "PATH_PARAM",
					"attribute": [
						{
							"name": "deployment",
							"label": "Deployment",
							"value": {
								"type": "TEXT",
								"string": "deploy-gpt-4.1"
							}
						}
					]
				},
				{
					"type": "PATH_PARAM",
					"attribute": [
						{
							"name": "apiVersion",
							"label": "API Version",
							"value": {
								"type": "TEXT",
								"string": "2025-01-01-preview"
							}
						}
					]
				}
			],
			"request": {
				"raw": {
					"body": "{\"model\": \"gpt-4.1\",\"messages\":[{\"role\":\"system\",\"content\":\"system prompt\"},{\"role\":\"user\",\"content\":\"some prompt query\"}],\"max_completion_tokens\":500}",
					"variables": [
						{
							"path": "$.max_completion_tokens",
							"attribute": {
								"name": "max_completion_tokens",
								"label": "Max tokens",
								"value": {
									"type": "INTEGER",
									"number": "2048"
								},
								"annotations": [
									"MODEL_PARAMETER"
								],
								"canonicalName": "choices[0].completionTokens"
							}
						},
						{
							"path": "$.messages[1].content",
							"attribute": {
								"name": "prompt",
								"label": "prompt",
								"value": {
									"type": "TEXT"
								},
								"annotations": [
									"PROMPT_QUERY"
								]
							}
						},
						{
							"path": "$.messages[0].content",
							"attribute": {
								"name": "systemPrompt",
								"label": "System Prompt",
								"value": {
									"type": "TEXT"
								},
								"annotations": [
									"SYSTEM_PROMPT_MESSAGE"
								]
							}
						}
					]
				}
			},
			"response": {
				"body": "{\n    \"id\": \"chatcmpl-APwQdLa9WCQAdZg0dO5OjGr2ER4sX\",\n    \"object\": \"chat.completion\",\n    \"created\": 1730746163,\n    \"model\": \"o3-mini-2025-01-31\",\n    \"choices\": [\n        {\n            \"index\": 0,\n            \"message\": {\n                \"role\": \"assistant\",\n                \"content\": \"Sure! They are one of the most mysterious and exciting objects in space.\",\n                \"refusal\": null\n            },\n            \"finish_reason\": \"stop\"\n        }\n    ],\n    \"usage\": {\n        \"prompt_tokens\": 17,\n        \"completion_tokens\": 959,\n        \"total_tokens\": 976,\n        \"prompt_tokens_details\": {\n            \"cached_tokens\": 0\n        },\n        \"completion_tokens_details\": {\n            \"reasoning_tokens\": 64\n        }\n    },\n    \"system_fingerprint\": \"fp_35c19d48ca\"\n}",
				"variables": [
					{
						"path": "$.usage.completion_tokens",
						"attribute": {
							"name": "completion_tokens",
							"label": "completion_tokens",
							"value": {
								"type": "INTEGER"
							},
							"annotations": [
								"RESPONSE_PARAMETER"
							],
							"canonicalName": "choices[0].completionTokens"
						}
					},
					{
						"path": "$.choices[0].message.content",
						"attribute": {
							"name": "content",
							"label": "content",
							"value": {
								"type": "TEXT",
								"string": "Some response from LLM"
							},
							"annotations": [
								"RESPONSE_PARAMETER"
							],
							"canonicalName": "choices[0].value"
						}
					},
					{
						"path": "$.model",
						"attribute": {
							"name": "model",
							"label": "model",
							"value": {
								"type": "TEXT"
							},
							"annotations": [
								"RESPONSE_PARAMETER"
							],
							"canonicalName": "model_name"
						}
					},
					{
						"path": "$.usage.prompt_tokens",
						"attribute": {
							"name": "prompt_tokens",
							"label": "prompt_tokens",
							"value": {
								"type": "INTEGER"
							},
							"annotations": [
								"RESPONSE_PARAMETER"
							],
							"canonicalName": "choices[0].promptTokens"
						}
					},
					{
						"path": "$.usage.total_tokens",
						"attribute": {
							"name": "total_tokens",
							"label": "total_tokens",
							"value": {
								"type": "INTEGER"
							},
							"annotations": [
								"RESPONSE_PARAMETER"
							],
							"canonicalName": "choices[0].totalTokens"
						}
					}
				]
			}
		}
	]
}