Skip to main content

Tag categorization

This topic describes the syntax and provides examples for the tag categorization feature of the Tongyi Data Mining API.

Request syntax

POST /zhiwen-chat/tagging HTTP/1.1

Request parameters

Name

Type

Required

Description

Example value

capabilityType

string

Yes

The type of capability.

Tag classification: TAG_CLASSIFY

TAG_CLASSIFY

userPrompt

string

Yes

The prompt.

Analyze the business scope of a company, extract key information, and provide the output in a structured format. Stop after the output is complete and do not add new content.

fileIdList

array

Yes

A list of document IDs.

[

"file_zhiwen_XXX"

]

stream

boolean

Yes

Specifies whether to return the response in a stream.

true

Response parameters

Name

Type

Description

output

object

-choices

array

-finishReason

string

The reason the process finished.

-message

object

The message body.

-role

string

The role.

-content

string

The message content.

requestId

string

The request ID.

usage

object

Information about token usage.

-inputTokens

int

The number of input tokens.

-outputTokens

int

The number of output tokens.

-totalTokens

int

The total number of tokens.

Examples

Request example

import os
import requests

'''
API name: Tag Categorization
API path: https://dashscope.aliyuncs.com/api/v2/apps/zhiwen-chat/tagging
Environment requirements: Python >= 3.7
'''

url = "https://dashscope.aliyuncs.com/api/v2/apps/zhiwen-chat/tagging"
request_headers = {
    "Authorization": os.environ.get("DASHSCOPE_API_KEY"),  # If you have not configured the environment variable, replace this with your API key.
    "Content-Type": "application/json"
}
# Tag categorization: TAG_CLASSIFY
request_body = {
    "capabilityType": "TAG_CLASSIFY",
    "userPrompt": "Analyze the business scope of a company, extract key information, and provide the output in a structured format. Stop after the output is complete and do not add new content.",
    "stream": True,
    "fileIdList": [
        "file_zhiwen_XXX"  # Replace this with your document ID.
    ]
}

with requests.post(url, json=request_body, headers=request_headers) as response:
    if request_body["stream"]:
        for line in response.iter_lines():
            if line:
                line = line.decode('utf-8')
                if line.startswith('data:'):
                    print("Received:", line[5:].strip())
    else:
        print("Received:", response.json())

Successful response example

JSON format
{
  "output": {
    "choices": [{
      "finishReason": "stop",
      "message": {
        "role": "assistant",
        "content": "The business scope includes: tag categorization results."
      }
    }]
  },
  "requestId": "e1b36ec0-225e-9b0a-9851-f5ea0f1fa5d4",
  "usage": {
    "inputTokens": 100,
    "outputTokens": 100,
    "totalTokens": 200
  }
}

Error codes

For more information, see Error codes for Tongyi Data Mining.
Agent Development
Agent Context
Agent Governance & Evolution
Store
Application Marketplace