RunChatResultGeneration
Generates chat responses. You can select a model for the conversation and choose streaming or non-streaming output.
Operation description
Make sure that you fully understand the billing method and pricing of Tongyi Dianjin before you use this API.
Prerequisites- Alibaba Cloud Model Studio and Tongyi Dianjin are activated.
- You have obtained the workspaceId: Obtain the workspace identifier.
Debugging
You can run this API directly in OpenAPI Explorer, which saves you the trouble of calculating signatures. After the operation succeeds, OpenAPI Explorer can automatically generate SDK code examples.
RAM authorization
The following table describes the authorization information of the API. You can use it in the Action element of RAM policy statements to grant RAM users or RAM roles the permission to call this API. For details:
-
Operation: the specific permission point.
-
Access level: the access level of each operation. Valid values: Write, Read, and List.
-
Resource type: the resource types that support authorization in the operation. For details:
- Required resource types are marked with a leading asterisk (*).
- For operations that do not support resource-level authorization,
All resourcesis used.
-
Condition key: the condition keys defined by the cloud service itself.
-
Dependent operation: other permissions required to successfully perform the operation. The caller must also have the permissions of the dependent operations for the operation to succeed.
| Operation | Access level | Resource type | Condition key | Dependent operation |
|---|---|---|---|---|
| dianjin:RunChatResultGeneration | none | *All resources * |
| None |
Request syntax
POST /{workspaceId}/api/run/chat/generation HTTP/1.1
Request parameters
| Name | Type | Required | Description | Example |
|---|---|---|---|---|
| workspaceId | string | Yes | Path parameter. The ID of the workspace. | llm-xxxxx |
| body | object | No | Request body parameters. | |
| inferenceParameters | object | No | Hyperparameters used for inference. | {"topP": 0.8} |
| messages | array<object> | Yes | Messages input to the model. | |
| Message | object | No | ||
| content | string | No | Message content. | You are an information processing expert |
| role | string | No | Message role. | user |
| modelId | string | Yes | The model service type. Obtain it from the /api/app/config API. The corresponding field is llmHelperTypeList. | qwen-max |
| sessionId | string | No | The sessionId, which can be used to mark a conversation. | 237645726354 |
| stream | boolean | No | Whether to stream: true returns answers in streaming mode; false returns answers in full. If not specified, the default is false. | false |
| tools | array<object> | No | Tool information to input. Used to specify the list of tools that the model can call. When multiple tools are input, the model selects one of them to generate the result. | |
| Tool | object | No | Tool information. | |
| function | object | No | An object whose keys include name, description, and parameters. | |
| description | string | No | A string that describes the tool function, which helps the model decide when and how to call it. | Description of the tool function |
| name | string | No | A string that represents the name of the tool function. It must contain only letters and digits and can include underscores and hyphens, with a maximum length of 64. | get_time |
| parameters | object | No | An object that describes the tool parameters. It must be a valid JSON Schema. | |
| properties | object | No | Properties. | { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": [ "celsius", "fahrenheit" ] } } |
| type | string | No | Type. | object |
| required | array | No | List of required parameters. | |
| Required | string | No | Required parameter. | location |
| type | string | No | A string that indicates the type of tools. Currently, only function is supported. | function |
Response parameters
| Name | Type | Description | Example |
|---|---|---|---|
| object | |||
| choices | array<object> | Details of the model-generated content. | |
| choice | object | Details of the model-generated content. | |
| finishReason | string | Three possible cases:
| null |
| index | integer | Sequence number of the generated result. Default is 0. | 0 |
| message | object | Chat message. | |
| content | string | Message content. | Who are you |
| role | string | Role. | user |
| toolCalls | array<object> | List of tool calls. | |
| toolCall | object | Tool call. | { "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"location\": \"Changsha\", \"unit\": \"celsius\"}" }, "id": "" } |
| created | long | Creation time. | 1720602203 |
| id | string | Request identifier. | eb2b6139-ddf1-91a0-a47f-df7617ae9032 |
| modelId | string | Large model ID. | qwen-max |
| requestId | string | Request ID. | eb2b6139-ddf1-91a0-a47f-df7617ae9032 |
| time | string | Timestamp. | 2024-04-24 11:54:34 |
| totalTokens | integer | Total tokens. | 500 |
| usage | object | Usage. | |
| imageCount | integer | Number of images, returned by models such as wanx. | 0 |
| imageTokens | integer | Image tokens, returned by models such as qwen-vl. | 0 |
| inputTokens | integer | Input tokens. | 200 |
| outputTokens | integer | Output tokens. | 300 |
| totalTokens | integer | Total tokens. | 500 |
Examples
Success response
JSON format
{
"choices": [
{
"finishReason": null,
"index": 0,
"message": {
"content": "你是谁",
"role": "user",
"toolCalls": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"arguments": {
"location": "长沙",
"unit": "celsius"
}
},
"id": ""
}
]
}
}
],
"created": 1720602203,
"id": "eb2b6139-ddf1-91a0-a47f-df7617ae9032",
"modelId": "qwen-max",
"requestId": "eb2b6139-ddf1-91a0-a47f-df7617ae9032\n",
"time": "2024-04-24 11:54:34",
"totalTokens": 500,
"usage": {
"imageCount": 0,
"imageTokens": 0,
"inputTokens": 200,
"outputTokens": 300,
"totalTokens": 500
}
}
Error codes
Visit the Error Center to view more error codes.