RunChatResultGeneration

Updated at:

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.

Try it now

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 resources is 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.

OperationAccess levelResource typeCondition keyDependent operation
dianjin:RunChatResultGenerationnone
*All resources
*
    None
None

Request syntax

POST /{workspaceId}/api/run/chat/generation HTTP/1.1

Request parameters

NameTypeRequiredDescriptionExample
workspaceIdstringYes

Path parameter. The ID of the workspace.

llm-xxxxx
bodyobjectNo

Request body parameters.

inferenceParametersobjectNo

Hyperparameters used for inference.

{"topP": 0.8}
messagesarray<object>Yes

Messages input to the model.

MessageobjectNo
contentstringNo

Message content.

You are an information processing expert
rolestringNo

Message role.

user
modelIdstringYes

The model service type. Obtain it from the /api/app/config API. The corresponding field is llmHelperTypeList.

qwen-max
sessionIdstringNo

The sessionId, which can be used to mark a conversation.

237645726354
streambooleanNo

Whether to stream: true returns answers in streaming mode; false returns answers in full. If not specified, the default is false.

false
toolsarray<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.

ToolobjectNo

Tool information.

functionobjectNo

An object whose keys include name, description, and parameters.

descriptionstringNo

A string that describes the tool function, which helps the model decide when and how to call it.

Description of the tool function
namestringNo

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
parametersobjectNo

An object that describes the tool parameters. It must be a valid JSON Schema.

propertiesobjectNo

Properties.

{ "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": [ "celsius", "fahrenheit" ] } }
typestringNo

Type.

object
requiredarrayNo

List of required parameters.

RequiredstringNo

Required parameter.

location
typestringNo

A string that indicates the type of tools. Currently, only function is supported.

function

Response parameters

NameTypeDescriptionExample
object
choicesarray<object>

Details of the model-generated content.

choiceobject

Details of the model-generated content.

finishReasonstring

Three possible cases:

  • null while the content is being generated;

  • stop if generation ends because a stop condition in the input parameters is triggered;

  • length if generation ends because the generated content is too long.

null
indexinteger

Sequence number of the generated result. Default is 0.

0
messageobject

Chat message.

contentstring

Message content.

Who are you
rolestring

Role.

user
toolCallsarray<object>

List of tool calls.

toolCallobject

Tool call.

{ "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"location\": \"Changsha\", \"unit\": \"celsius\"}" }, "id": "" }
createdlong

Creation time.

1720602203
idstring

Request identifier.

eb2b6139-ddf1-91a0-a47f-df7617ae9032
modelIdstring

Large model ID.

qwen-max
requestIdstring

Request ID.

eb2b6139-ddf1-91a0-a47f-df7617ae9032
timestring

Timestamp.

2024-04-24 11:54:34
totalTokensinteger

Total tokens.

500
usageobject

Usage.

imageCountinteger

Number of images, returned by models such as wanx.

0
imageTokensinteger

Image tokens, returned by models such as qwen-vl.

0
inputTokensinteger

Input tokens.

200
outputTokensinteger

Output tokens.

300
totalTokensinteger

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.