Text Generation
Introduction
This API is used to generate text based on the document and input data.
Before using this API, customize a document. For more details, see Text Generation in the Natural Language Processing User Guide.
URI
- URI format
POST /v1/{project_id}/nlg/data2doc/document/generation - Parameter description
Table 1 URI parameters Parameter
Mandatory
Description
project_id
Yes
Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.
Request
Table 2 describes the request parameters.
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| group_name | Yes | String | Name of a project. The value contains 2 to 50 characters and only letters, digits, underscores (_), and hyphens (-) are allowed. A project must contain valid documents on the text generation console. |
| document_name | Yes | String | Name of a document in a project. The value contains 2 to 50 characters and only letters, digits, underscores (_), and hyphens (-) are allowed. A document must be valid and customized on the text generation console. |
| data | Yes | Json | Data you enter for generating text. It must be in JSON format. The data must be consistent with the data item in the custom document. |
Response
Table 3 describes the response parameters.
| Parameter | Type | Description |
|---|---|---|
| title | String | Title of the generated text |
| content | String | Content of the generated text |
| error_code | String | Error code when the API fails to be called. For details, see Error Code. The parameter is not included when the API call succeeds. |
| error_msg | String | Error message returned when the API fails to be called. The parameter is not included when the API call succeeds. |
Example
This following example shows how to generate text.
- Example request
POST https://{endpoint}/v1/{project_id}/nlg/data2doc/document/generation Request Header: Content-Type: application/json X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... Request Body: { "group_name": "Project 01", "document_name": "Document 01", "data": { "date": "2019-12-1", "max_temperature": "16°", "min_temperatrue": "3°" } } - Example response
- Successful example response
{ "title": "Weather forecast", "content": "Today is December 1, 2019. The highest temperature is 16°C and the lowest temperature is 3°C. Today's temperature is suitable for travel." } - Failed example response
{ "error_code": "NLP.3201", "error_msg": "group project 01 does not exist." }
- Successful example response
Status Code
For details about status codes, see Status Code.
Error Code
For details about error codes, see Error Code.
Last Article: Poem Generation
Next Article: LU APIs
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.