All Products
Search
Document Center

Alibaba Cloud Model Studio:Get started

Last Updated:Nov 06, 2024

Models

Note

Supported fields or tasks: Artificial Intelligence Generated Content (AIGC)

Qwen1.5

Qwen1.5 is the next version of the open source Qwen series. Compared with earlier versions, Qwen1.5 significantly improves the consistency between chat models and human preferences, provides improved multilingual capabilities, and gains strong link capability to external systems. The chat versions of the new Qwen models provide API services in Alibaba Cloud Model Studio and show great improvement in chat capabilities. Qwen1.5-Chat series achieves excellent performance even in MT-Bench.

The Qwen1.5-7B, Qwen1.5-14B, Qwen1.5-32B, Qwen1.5-72B, and Qwen1.5-110B models available in Alibaba Cloud Model Studio are specifically optimized for inference performance based on the corresponding open source Qwen1.5 versions. These models provide developers with convenient API services. For more information about the corresponding open source versions, visit ModelScope Qwen1.5. To switch ModelScope to English, click the image icon in the top navigation bar.

Get started

Prerequisites

Sample code

The following sample code shows how to call a Qwen 72B model by using the SDK and API operations. To call another open source Qwen model, replace qwen1.5-72b-chat in the code with the name of the model. For more information about available model names, see the Model overview section in API reference.

Note

Replace YOUR_DASHSCOPE_API_KEY with your API key.

Specify API key

export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY

from http import HTTPStatus
import dashscope
# If the environment variable is not set, please add the following line of code:
# dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

def call_with_messages():
    messages = [
        {'role': 'user', 'content': 'How to cook potatos?'}]
    response = dashscope.Generation.call(
        'qwen1.5-72b-chat',
        messages=messages,
        result_format='message',  # set the result is message format.
    )
    if response.status_code == HTTPStatus.OK:
        print(response)
    else:
        print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
            response.request_id, response.status_code,
            response.code, response.message
        ))


if __name__ == '__main__':
    call_with_messages()
// Copyright (c) Alibaba, Inc. and its affiliates.

import java.util.Arrays;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;



public class Main {
  public static void callWithMessage()
      throws NoApiKeyException, ApiException, InputRequiredException {
    Generation gen = new Generation();
    Message userMsg = Message.builder().role(Role.USER.getValue()).content("How to cook potatos?").build();
    QwenParam param =
        QwenParam.builder().model("qwen1.5-72b-chat").messages(Arrays.asList(userMsg))
            .resultFormat(QwenParam.ResultFormat.MESSAGE)
            .topP(0.8)
            .build();
    GenerationResult result = gen.call(param);
    System.out.println(result);
  }


  public static void main(String[] args){
        try {
          callWithMessage();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
          System.out.println(e.getMessage());
        }
        System.exit(0);
  }
}

Sample resonse for Python:

{
    "status_code": 200,
    "request_id": "b347ab16-a562-90f3-bc01-b356e935e7ae",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": There are many ways to cook potatoes, but here's a simple method for boiling them:\n\n1. Wash and peel the potatoes if desired. If you prefer the skin on, you can skip this step.\n2. Cut the potatoes into equal-sized chunks to ensure even cooking. This is especially important if you're using different types or sizes of potatoes.\n3. Place the potato chunks in a large pot and add enough water to cover them by about an inch.\n4. Add a pinch of salt to the water for flavor (optional).\n5. Place the pot on the stove and turn the heat to high. Bring the water to a boil.\n6. Once the water is boiling, reduce the heat to medium or medium-low to maintain a gentle simmer. Cover the pot partially to allow steam to escape.\n7. Cook the potatoes for about 15-20 minutes or until they are tender when pierced with a fork. The cooking time may vary depending on the size of the potato pieces.\n8. Drain the potatoes in a colander and return them to the pot (off the heat) to let any excess steam escape.\n9. Season the potatoes as desired. You can serve them plain, with butter, herbs, sour cream, or any other toppings of your choice.\n\nAlternatively, you can roast, bake, fry, or microwave potatoes. Each method has its own unique flavors and textures. Experiment to find your favorite way to enjoy potatoes!"
                }
            }
        ]
    },
    "usage": {
        "input_tokens": 14,
        "output_tokens": 291
    }
}

Reference

For more information about how to call the API operations of Qwen 1.8B, 7B, 14B, and 72B models, see API details.

For more information about the throttling thresholds of different models and how to apply for higher quotas, see Billing.