logoComputeVault
User GuideAPI ReferenceHelp & SupportBusiness Cooperation

Qwen Chat Format (Text Generation)

Qwen Chat Format (Text Generation)

Official Documentation

📝 Introduction

Given a list of messages comprising a conversation, the model will return a response. Qwen is a large-scale language model independently developed by the Tongyi Lab under Alibaba Group, supporting multilingual conversations, text generation, code generation, and more.

🤖 Supported Models

Currently supported models include:

ModelDescription
qwen-turboQwen Turbo chat model
qwen-plusQwen Plus chat model
qwen-maxQwen Max chat model

💡 Request Examples

Basic Text Chat ✅

curl --location "https://computevault.unodetech.xyz/api/v1/services/aigc/text-generation/generation" \
  --header "Authorization: Bearer $API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "model": "qwen-plus",
    "input": {
      "messages": [
        {
          "role": "system",
          "content": "You are a helpful assistant."
        },
        {
          "role": "user",
          "content": "Who are you?"
        }
      ]
    }
  }'

Response Example:

{
  "output": {
    "text": "",
    "finish_reason": "",
    "choices": [
      {
        "finish_reason": "stop",
        "message": {
          "content": "Hello! I'm Qwen, a large-scale language model independently developed by the Tongyi Lab under Alibaba Group. I can answer questions, create text such as stories, official documents, emails, scripts, perform logical reasoning, coding, and more. I can also express opinions and play games. I support 100 languages, including but not limited to Chinese, English, German, French, Spanish, etc., meeting international usage needs. If you have any questions or need assistance, feel free to let me know anytime!",
          "role": "assistant"
        }
      }
    ]
  },
  "usage": {
    "input_tokens": 23,
    "output_tokens": 106,
    "total_tokens": 129
  },
  "code": "",
  "message": "",
  "request_id": ""
}

📮 Request

Endpoint

POST /api/v1/services/aigc/text-generation/generation

Create a model response for a given chat conversation.

Authentication Method

Include the following in the request headers for API key authentication:

Authorization: Bearer $API_KEY

Where $API_KEY is your API key.

Request Body Parameters

model

  • Type: String
  • Required: Yes

The ID of the model to use. For example: qwen-plus, qwen-turbo, etc.

input

  • Type: Object
  • Required: Yes

An object containing input messages.

input Properties:

PropertyTypeRequiredDescription
messagesArrayYesA list of messages comprising the conversation.

input.messages

  • Type: Array
  • Required: Yes

The list of messages comprising the conversation so far.

Message Types:

Message TypeDescription
System messageSystem message used to set the assistant's behavior and role.
User messageMessages sent by the terminal user, containing prompts or additional context information.
Assistant messageMessages sent by the model in response to user messages.

System message Properties:

PropertyTypeRequiredDescription
roleStringYesThe role of the message author, here "system".
contentStringYesThe content of the system message.

User message Properties:

PropertyTypeRequiredDescription
roleStringYesThe role of the message author, here "user".
contentStringYesThe content of the user message.

Assistant message Properties:

PropertyTypeRequiredDescription
roleStringYesThe role of the message author, here "assistant".
contentStringNoThe content of the assistant message.

parameters

  • Type: Object
  • Required: No

Configuration for generation parameters.

parameters Properties:

PropertyTypeRequiredDescription
result_formatStringNoResponse format. Optional values: message, text. Default is message.
temperatureNumberNoSampling temperature, controlling the randomness of the output. Typically ranges from 0 to 2.
top_pNumberNoNucleus sampling parameter, controlling the probability mass for sampling.
max_tokensIntegerNoMaximum number of tokens to generate.
stopString or ArrayNoStop sequences, when the model generates these sequences, it stops generating.

📥 Response

Text Generation Object

Returns a text generation object.

output

  • Type: Object
  • Description: Output object containing the generated text and choices.

output Properties:

PropertyTypeDescription
textStringThe generated text content.
finish_reasonStringThe reason for completion.
choicesArrayA list of generated choices.

output.choices

  • Type: Array
  • Description: A list of generated response options.

choice Properties:

PropertyTypeDescription
finish_reasonStringThe reason the model stopped generating tokens. Possible values: stop (natural stop), length (reached maximum length), etc.
messageObjectThe message generated by the model.
message.roleStringThe role of the message author, usually "assistant".
message.contentStringThe content of the message.

usage

  • Type: Object
  • Description: Usage statistics for the completion request.

usage Properties:

PropertyTypeDescription
input_tokensIntegerThe number of tokens in the input.
output_tokensIntegerThe number of tokens in the generated completion.
total_tokensIntegerThe total number of tokens used in the request (input + output).

code

  • Type: String
  • Description: Response code, usually an empty string indicating success.

message

  • Type: String
  • Description: Response message, usually an empty string indicating success.

request_id

  • Type: String
  • Description: The unique identifier for the request.

Text Generation Object Response Example

{
  "output": {
    "text": "",
    "finish_reason": "",
    "choices": [
      {
        "finish_reason": "stop",
        "message": {
          "content": "Hello! I'm Qwen, a large-scale language model independently developed by the Tongyi Lab under Alibaba Group. I can answer questions, create text such as stories, official documents, emails, scripts, perform logical reasoning, coding, and more. I can also express opinions and play games. I support 100 languages, including but not limited to Chinese, English, German, French, Spanish, etc., meeting international usage needs. If you have any questions or need assistance, feel free to let me know anytime!",
          "role": "assistant"
        }
      }
    ]
  },
  "usage": {
    "input_tokens": 23,
    "output_tokens": 106,
    "total_tokens": 129
  },
  "code": "",
  "message": "",
  "request_id": ""
}

How is this guide?

Last updated on