Skip to main content

Summary generation

This topic describes the syntax and examples of the Tongyi ZoneWit API for summary generation.

Request syntax

POST /zhiwen-chat/summary HTTP/1.1

Request parameters

Name

Type

Required

Description

Example

capabilityType

string

Yes

The capability type.

Summary generation:

SUMMARY_GEN

SUMMARY_GEN

userPrompt

string

Yes

The prompt.

You are an AI assistant that specializes in Named Entity Recognition (NER). Your task is to accurately extract all person names, place names, and organization names from the given text and organize them in the specified dictionary format.

fileIdList

array

Yes

A list of document IDs.

[

"file_zhiwen_XXX"

]

stream

boolean

Yes

Specifies whether to return the response in a streaming format.

true

Response parameters

Name

Type

Description

output

object

-choices

array

-finishReason

string

Termination Reason

-message

object

The message body.

-role

string

The role.

-content

string

The message content.

requestId

string

The request ID.

usage

object

The token usage information.

-inputTokens

int

The number of input tokens.

-outputTokens

int

The number of output tokens.

-totalTokens

int

The total number of tokens.

Examples

Call examples

import os
import requests

'''
API name: Summary generation
API path: https://dashscope.aliyuncs.com/api/v2/apps/zhiwen-chat/summary
Environment requirements: Python >= 3.7
'''

url = "https://dashscope.aliyuncs.com/api/v2/apps/zhiwen-chat/summary"
request_headers = {
    "Authorization": os.environ.get("DASHSCOPE_API_KEY"),  # If you have not configured the environment variable, replace your API key here.
    "Content-Type": "application/json"
}
# Summary generation: SUMMARY_GEN
request_body = {
    "capabilityType": "SUMMARY_GEN",
    "userPrompt": "What are these documents about? Summarize them in Markdown format.",
    "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": "Summary of the document 'XXX.pdf': The generated summary result."
      }
    }]
  },
  "requestId": "1e016036-ac87-9afa-b603-7443f9d4e093",
  "usage": {
    "inputTokens": 100,
    "outputTokens": 100,
    "totalTokens": 200
  }
}

Error codes

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