You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取LUIS Cognitive编程接口中的所有意图(默认仅返回100个)

Got it, I’ve run into this exact issue before when working with LUIS’s programmatic API! The default 100-intent limit is a common gotcha, but you can easily fetch all your intents using the API’s built-in pagination parameters. Here’s how to do it:

How it works

The LUIS Authoring API's "Get All Intents" endpoint supports two query parameters to handle large result sets:

  • skip: The number of intents to skip before returning results (starts at 0)
  • top: The maximum number of intents to return per request (check the API docs for the upper limit—usually it's 500, which is way better than the default 100)

Step-by-step implementation

  1. Initialize a counter for skip starting at 0, and set a top value to the highest allowed by the API.
  2. Make a request to the endpoint with your current skip and top values.
  3. Add the returned intents to a master list.
  4. If the number of intents returned is less than your top value, you’ve fetched all intents—stop the loop. Otherwise, increment skip by top and repeat the process.

Example code (Python)

Here’s a quick script to demonstrate this logic using the requests library:

import requests

def fetch_all_luis_intents(app_id, auth_key, region):
    # Base URL for LUIS Authoring API (adjust version if needed)
    api_url = f"https://{region}.api.cognitive.microsoft.com/luis/authoring/v3.0-preview/apps/{app_id}/versions/0.1/intents"
    headers = {"Ocp-Apim-Subscription-Key": auth_key}
    
    all_intents = []
    skip = 0
    max_per_page = 500  # Use the maximum allowed by your API version
    
    while True:
        params = {"skip": skip, "top": max_per_page}
        response = requests.get(api_url, headers=headers, params=params)
        response.raise_for_status()  # Throw an error if request fails
        
        current_batch = response.json()
        all_intents.extend(current_batch)
        
        # Exit loop if we got fewer results than the max per page
        if len(current_batch) < max_per_page:
            break
        
        skip += max_per_page
    
    return all_intents

Important notes

  • API Version Check: Double-check the API version you’re using (v2 vs v3) as parameter names or endpoints might differ slightly.
  • Rate Limits: LUIS enforces rate limits on authoring API calls. If you hit a 429 "Too Many Requests" error, add retry logic with exponential backoff to handle it.
  • Permissions: Ensure your authentication key has authoring access to the LUIS app—you can’t fetch intents using a prediction key.

内容的提问来源于stack exchange,提问作者tumblewood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:42:40