Copilot Credits ใช้สำหรับสนับสนุนการใช้งานเอเจนต์และ Copilot ที่คุณสร้างด้วย Copilot Studio ในสภาพแวดล้อม Power Platform ทั้งหมดของคุณ ในฐานะผู้ดูแลระบบ คุณจัดสรรเครดิตให้กับสภาพแวดล้อมที่ต้องการและตัดสินใจว่าจะเกิดอะไรขึ้นเมื่อสภาพแวดล้อมวิ่งออกจากเครดิตที่จัดสรร นอกเหนือจากการใช้งาน ศูนย์การจัดการ Power Platform แล้ว คุณยังสามารถจัดการการจัดสรรเครดิตของ Copilot ด้วยโค้ดโดยใช้ Power Platform API และ SDK การดูแลระบบ (Admin) การจัดสรรเครดิตอัตโนมัติมีประโยชน์เมื่อคุณแจกจ่ายความจุในสภาพแวดล้อมจํานวนมาก กําหนดมาตรฐานลักษณะการทํางานเกินมาตรฐาน หรือจัดการการปันส่วนเป็นส่วนหนึ่งของไปป์ไลน์การปรับใช้
ในบทช่วยสอนนี้ เรียนรู้วิธีการ:
- จัดการเครดิต Copilot ในศูนย์ดูแล Power Platform
- การรับรองความถูกต้องโดยใช้ Power Platform API
- ดูเครดิต Copilot ที่สามารถจัดสรรได้
- จัดสรร Copilot เครดิตให้กับสภาพแวดล้อม
- ควบคุมว่าสภาพแวดล้อมใช้ความจุของผู้เช่าหรือไม่
เครดิต Copilot จะแสดงด้วยรหัสสิทธิ์ MCSMessages และได้รับการจัดการผ่านการดำเนินการ licensing/allocationsV2 ของ Power Platform API การดำเนินการ allocationsV2/availability จะรายงานว่ามีความจุที่พร้อมให้จัดสรรอยู่เท่าใด และการดำเนินการ allocationsV2 จะเขียนการจัดสรรของสภาพแวดล้อม ตัวอย่างทางโปรแกรมทั้งหมดในบทความนี้ใช้เวอร์ชัน 2024-10-01API
การจัดสรรสภาพแวดล้อมแต่ละครั้งมีชุด กฎการบังคับใช้ ที่กําหนดสิ่งที่จะเกิดขึ้นเมื่อสภาพแวดล้อมใช้เครดิตที่จัดสรร ตัวเลือก ใช้ความจุที่พร้อมใช้งานในเทนเนนต์ของฉัน ในศูนย์การจัดการสอดคล้องกับ TenantPool กฎการบังคับ: เมื่อเปิดใช้งาน สภาพแวดล้อมจะยังคงใช้ความจุของเทนเนนต์ที่ยังไม่ได้จัดสรรหลังจากใช้การจัดสรรของตนเองจนหมดแล้ว เมื่อปิดใช้งาน สภาพแวดล้อมจะถูกจำกัดไว้ไม่ให้เกินการจัดสรรของตน
คำเตือน
ถ้า กฎกลุ่มสภาพแวดล้อม ที่เผยแพร่ควบคุมการตั้งค่า ใช้จากความจุที่มีอยู่ใน tenant ของฉัน คุณจะไม่สามารถแทนที่การตั้งค่าสำหรับแต่ละสภาพแวดล้อมได้ การอัปเดตผ่านศูนย์การจัดการ Power Platform, Power Platform API หรือ SDK สำหรับการดูแลระบบจะถูกปฏิเสธพร้อมข้อผิดพลาด TenantPoolLockedByPolicy เปลี่ยนและเผยแพร่กฎสําหรับกลุ่มสภาพแวดล้อม ใหม่ หรือลบสภาพแวดล้อมออกจากกลุ่ม เพื่อจัดการการตั้งค่าอย่างอิสระ หลังจากลบสภาพแวดล้อมจะยังคงใช้ค่าล่าสุดโดยกลุ่ม แต่การตั้งค่าจะสามารถแก้ไขได้ สําหรับข้อมูลเพิ่มเติมเกี่ยวกับกฎของกลุ่มที่พร้อมใช้งาน ดูกฎสําหรับกลุ่มสภาพแวดล้อม
Prerequisites
การลงทะเบียนแอปที่กําหนดค่าไว้สําหรับ Power Platform API โปรดสังเกต ID แอปพลิเคชัน (ไคลเอนต์) และ ID ไดเรกทอรี (ผู้เช่า) ของการลงทะเบียนแอป
สิทธิ์ในการจัดการสิทธิ์การใช้งานและความจุ ลงชื่อเข้าใช้ในฐานะผู้ใช้ด้วยบทบาท ผู้ดูแลระบบ Power Platform หรือ ผู้ดูแลระบบส่วนกลาง หรือบทบาทที่เทียบเท่ากันที่สามารถจัดการสิทธิ์การใช้งานและความจุได้
สําหรับตัวอย่าง SDK ให้ติดตั้ง SDK ที่จัดส่งทุกเดือนในแกลเลอรีสาธารณะ:
dotnet add package Microsoft.PowerPlatform.Management
pip install powerplatform-management
จัดการการปันส่วนเครดิต Copilot
ส่วนนี้จะแสดงกระบวนการแบบต้นทางถึงปลายทางเดียวกัน ได้แก่ การตรวจสอบว่ามีอะไรให้ใช้งานได้บ้าง การจัดสรรเครดิตให้กับสภาพแวดล้อม และการควบคุมว่าสภาพแวดล้อมจะดึงจากความจุของผู้เช่าหรือไม่ ทั้งในศูนย์การจัดการ Power Platform และใน SDK แต่ละรายการ ใช้แท็บเพื่อสลับระหว่างศูนย์การจัดการและภาษาที่คุณต้องการ
ลงชื่อเข้าใช้ใน ศูนย์การจัดการ Power Platform
ในบานหน้าต่างนำทาง เลือก การให้สิทธิการใช้งาน
ภายใต้ ผลิตภัณฑ์ เลือก Copilot Studio แล้วเลือก จัดการ Copilot เครดิต
เลือกสภาพแวดล้อมที่คุณต้องการจัดการ ใช้กล่อง ค้นหา เพื่อค้นหาสภาพแวดล้อมตามชื่อ
ภายใต้ จัดสรรความจุ ให้ป้อนจำนวนเครดิต Copilot ที่จะจัดสรรให้กับสภาพแวดล้อม บานหน้าต่างแสดงจํานวนเครดิตที่ใช้ จํานวนที่จัดสรรแล้ว และจํานวนเครดิตที่มีให้จัดสรรจากผู้เช่าของคุณ
ภายใต้ การใช้เกินความจุ เลือกหรือยกเลิกการเลือก ใช้จากความจุที่มีอยู่ในผู้เช่าของฉัน เพื่อกำหนดลักษณะการทำงานเมื่อสภาพแวดล้อมใช้การจัดสรรจนหมด:
-
ถูกเลือก: หลังจากใช้เครดิตที่จัดสรรให้กับสภาพแวดล้อมหมดแล้ว ระบบจะยังคงใช้ความจุที่ไม่ได้จัดสรรของเทนเนนต์ของคุณ
-
จำกัดตามการจัดสรร: สภาพแวดล้อมถูกจำกัดไว้ตามโควต้าที่จัดสรร และจะหยุดใช้ทรัพยากรเมื่อใช้โควต้าที่จัดสรรจนหมด
เลือก บันทึก
ตัวอย่างต่อไปนี้เป็นการลงชื่อเข้าใช้แบบโต้ตอบในฐานะผู้ใช้ปัจจุบัน อ่านจำนวนเครดิต Copilot ที่พร้อมสำหรับการจัดสรร จัดสรรเครดิตให้กับสภาพแวดล้อม และปิดตัวเลือก ใช้จากความจุที่มีอยู่ในผู้เช่าของฉัน เพื่อจำกัดการใช้เครดิตของสภาพแวดล้อมไว้ที่จำนวนเครดิตที่จัดสรร
# Requires the MSAL.PS module: Install-Module MSAL.PS -Scope CurrentUser
Import-Module "MSAL.PS"
$clientId = "<application (client) ID of your app registration>"
$tenantId = "<directory (tenant) ID>"
$environmentId = "<environment ID>"
$apiBaseUrl = "https://api.powerplatform.com"
$apiVersion = "2024-10-01"
# Sign in interactively and request a token for the Power Platform API
$auth = Get-MsalToken -ClientId $clientId -TenantId $tenantId -Scope "https://api.powerplatform.com/.default" -Interactive
$headers = @{ Authorization = "Bearer $($auth.AccessToken)" }
# 1. View the Copilot Credits available to allocate for the environment
$filter = [uri]::EscapeDataString("environmentId eq '$environmentId' and EntitlementId in ('MCSMessages')")
$availability = Invoke-RestMethod -Method Get `
-Uri "$apiBaseUrl/licensing/allocationsV2/availability?api-version=$apiVersion&`$filter=$filter" `
-Headers $headers
$availability.entitlementAllocationsAvailable |
ForEach-Object { Write-Host "$($_.entitlementId): $($_.availableQuantity) available" }
# 2. Allocate Copilot Credits to the environment and turn off tenant capacity draw
$allocationBody = @{
scope = @{ environmentId = $environmentId }
allocatedEntitlements = @(
@{
entitlementId = "MCSMessages"
allocation = @{ quantity = 5000 }
enforcementRules = @(
# Disable TenantPool so the environment is capped at its allocation.
# Set enabled = $true to let the environment draw from tenant capacity.
@{ ruleType = "TenantPool"; enabled = $false }
)
}
)
} | ConvertTo-Json -Depth 10
Invoke-RestMethod -Method Put `
-Uri "$apiBaseUrl/licensing/allocationsV2?api-version=$apiVersion" `
-Headers $headers -ContentType "application/json" -Body $allocationBody
Write-Host "Updated Copilot credit allocation for environment $environmentId"
ตัวอย่างต่อไปนี้จะลงชื่อเข้าใช้แบบโต้ตอบโดยใช้รหัสไคลเอ็นต์ของการลงทะเบียนแอปพลิเคชันของคุณ อ่านเครดิต Copilot ที่พร้อมสำหรับการจัดสรร จัดสรรเครดิตให้กับสภาพแวดล้อม และปิด ดึงจากความจุที่พร้อมใช้งานในผู้เช่าของฉัน เพื่อให้สภาพแวดล้อมถูกจำกัดไว้ไม่ให้เกินจำนวนที่จัดสรร
using Microsoft.PowerPlatform.Management;
using Microsoft.PowerPlatform.Management.Models;
// Create an interactive client using your app registration's client ID.
// A browser window opens for sign-in.
var factory = new ServiceClientFactory();
var client = factory.Create("YOUR_CLIENT_ID");
var environmentId = "<environment ID>";
var apiVersion = "2024-10-01";
// 1. View the Copilot Credits available to allocate for the environment
var availability = await client.Licensing.AllocationsV2.Availability.GetAsync(config =>
{
config.QueryParameters.ApiVersion = apiVersion;
config.QueryParameters.Filter =
$"environmentId eq '{environmentId}' and EntitlementId in (MCSMessages)";
});
foreach (var entitlement in availability.EntitlementAllocationsAvailable)
{
Console.WriteLine($"{entitlement.EntitlementId}: {entitlement.AvailableQuantity} available");
}
// 2. Allocate Copilot Credits to the environment and turn off tenant capacity draw
var request = new AllocationPutRequestModel
{
Scope = new ScopeModel { EnvironmentId = environmentId },
AllocatedEntitlements = new List<EntitlementAllocationModel>
{
new EntitlementAllocationModel
{
EntitlementId = "MCSMessages",
Allocation = new AllocationModel { Quantity = 5000 },
EnforcementRules = new List<AllocationEnforcementRule>
{
// Disable TenantPool so the environment is capped at its allocation.
// Set Enabled = true to let the environment draw from tenant capacity.
new AllocationEnforcementRule
{
RuleType = AllocationEnforcementRuleTypes.TenantPool,
Enabled = false
}
}
}
}
};
await client.Licensing.AllocationsV2.PutAsync(request, config =>
{
config.QueryParameters.ApiVersion = apiVersion;
});
Console.WriteLine($"Updated Copilot credit allocation for environment {environmentId}");
ตัวอย่างต่อไปนี้จะลงชื่อเข้าใช้แบบโต้ตอบโดยใช้รหัสไคลเอ็นต์ของการลงทะเบียนแอปพลิเคชันของคุณ อ่านเครดิต Copilot ที่พร้อมสำหรับการจัดสรร จัดสรรเครดิตให้กับสภาพแวดล้อม และปิด ดึงจากความจุที่พร้อมใช้งานในผู้เช่าของฉัน เพื่อให้สภาพแวดล้อมถูกจำกัดไว้ไม่ให้เกินจำนวนที่จัดสรร
import asyncio
from azure.identity import InteractiveBrowserCredential
from kiota_abstractions.base_request_configuration import RequestConfiguration
from kiota_authentication_azure.azure_identity_authentication_provider import (
AzureIdentityAuthenticationProvider,
)
from kiota_http.httpx_request_adapter import HttpxRequestAdapter
from mspp_management.service_client_base import ServiceClientBase
from mspp_management.licensing.allocations_v2.allocations_v2_request_builder import (
AllocationsV2RequestBuilder,
)
from mspp_management.licensing.allocations_v2.availability.availability_request_builder import (
AvailabilityRequestBuilder,
)
from mspp_management.models.allocation_put_request_model import AllocationPutRequestModel
from mspp_management.models.scope_model import ScopeModel
from mspp_management.models.entitlement_allocation_model import EntitlementAllocationModel
from mspp_management.models.allocation_model import AllocationModel
from mspp_management.models.allocation_enforcement_rule import AllocationEnforcementRule
from mspp_management.models.allocation_enforcement_rule_types import (
AllocationEnforcementRuleTypes,
)
API_VERSION = "2024-10-01"
async def manage_copilot_credits(client: ServiceClientBase, environment_id: str):
# 1. View the Copilot Credits available to allocate for the environment
query_params = AvailabilityRequestBuilder.AvailabilityRequestBuilderGetQueryParameters(
api_version=API_VERSION,
filter=f"environmentId eq '{environment_id}' and EntitlementId in (MCSMessages)",
)
availability = await client.licensing.allocations_v2.availability.get(
request_configuration=RequestConfiguration(query_parameters=query_params)
)
for entitlement in availability.entitlement_allocations_available:
print(f"{entitlement.entitlement_id}: {entitlement.available_quantity} available")
# 2. Allocate Copilot Credits to the environment and turn off tenant capacity draw
# Disable TenantPool so the environment is capped at its allocation.
# Set enabled = True to let the environment draw from tenant capacity.
tenant_pool_rule = AllocationEnforcementRule()
tenant_pool_rule.rule_type = AllocationEnforcementRuleTypes.TenantPool
tenant_pool_rule.enabled = False
entitlement = EntitlementAllocationModel()
entitlement.entitlement_id = "MCSMessages"
entitlement.allocation = AllocationModel()
entitlement.allocation.quantity = 5000
entitlement.enforcement_rules = [tenant_pool_rule]
request = AllocationPutRequestModel()
request.scope = ScopeModel()
request.scope.environment_id = environment_id
request.allocated_entitlements = [entitlement]
put_params = AllocationsV2RequestBuilder.AllocationsV2RequestBuilderPutQueryParameters(
api_version=API_VERSION,
)
await client.licensing.allocations_v2.put(
request, request_configuration=RequestConfiguration(query_parameters=put_params)
)
print(f"Updated Copilot credit allocation for environment {environment_id}")
async def main():
# Sign in interactively using your app registration's client ID.
credential = InteractiveBrowserCredential(client_id="YOUR_CLIENT_ID")
auth_provider = AzureIdentityAuthenticationProvider(
credentials=credential,
scopes=["https://api.powerplatform.com/.default"],
)
adapter = HttpxRequestAdapter(authentication_provider=auth_provider)
client = ServiceClientBase(adapter)
await manage_copilot_credits(client, environment_id="<environment ID>")
asyncio.run(main())