×
Community Blog Tongyi Bailian - Model Studio with Chinese Version of Alibaba Cloud

Tongyi Bailian - Model Studio with Chinese Version of Alibaba Cloud

Model Studio is a repository of various Tongyi large models available for commercial purposes among corporate customers and partners.

Prerequisite: An account with the Chinese Version of Alibaba Cloud www.aliyun.com

Tongyi Bailian (Model Studio – China Edition) is a repository of various Tongyi large models available for commercial purposes among corporate customers and partners. It enables the developers to subscribe the existing large models with an API key and it is Model as a Service (MaaS). In this tutorial we will walk through the demonstration of using Model Studio Interface to create an API connectivity from a PAI-DSW instance or any application which requires the model. For demo purpose we use Tongyi Wanxiang model for model call and Qwen for application creation.
1
The model studio interface has two options: model call and application creation. Model call is used to create applications from a lot of large models available and integrate with the application getting developed. Application creation is a one stop setting where you can use around 3 large models of Qwen and connect with API.

  1. Using Model Call
    Click on to the Model Square on the left pane.

2
Click on Tongyi Wanxiang.
3
For the code snippet we need to refer to "API call examples" link available in the highlighted Tongyi Wanxiang-Text to image. The code snippet requires an API key to be added to get connected with the application to be authorized by model studio. Click on "View my API-KEY".
4
Click on "Create API-KEY" for generating an API key. Since there are three keys already generated, we will click on "Check" option for the first AI-KEY to start using in our code.
5
Copy the code and click "hide". The API key is classified as highly confidential information. Close the API-KEY dialog and then click on "API call Examples" and scroll down to the code snippet. It has python and java example. Keep the python snippet as an example to use with recently copies API key. Open DSW notebook in Platform for AI (PAI). Here to show the application to be anonymous, I open the PAI console from another Alibaba Cloud Account in International Region.
Modify the code in a notebook cell as follows:

from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
import dashscope
from dashscope import ImageSynthesis
dashscope.api_key="Your API Key"
def simple_call():
    prompt = 'Mouse rides elephant'
    rsp = ImageSynthesis.call(model=ImageSynthesis.Models.wanx_v1,prompt=prompt,n=4,size='1024*1024')
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output)
        print(rsp.usage)
    # save file to current directory
    for result in rsp.output.results:
        file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
        with open('./%s' % file_name, 'wb+') as f:
            f.write(requests.get(result.url).content)
else:
    print('Failed, status_code: %s, code: %s, message: %s' %
          (rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
    simple_call()

6
Execute the notebook cell.
7
Click on the link provided in the output of notebook cell. It will download the image. Locate and open the downloaded image. We gave the prompt as a "Mouse riding an elephant" and the outcome is shown as below.
8

  1. Application Creation
    The application creation is used to create applications directly and this option allows 3 variants of Qwen alone.

9
Click on "Create Now" in Application Creation.
10
Copy the API-KEY like the same way done for model call earlier and click on "New Applications".
11
Rename the application and click on "set up" to choose the LM.
12
Click on Save and Publish.
13
Enter the prompt and click on the arrow.
14
By these approaches we can manage AI applications with model call and application set up.

0 1 0
Share on

ferdinjoe

19 posts | 19 followers

You may also like

Comments

ferdinjoe

19 posts | 19 followers

Related Products