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.
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.
Click on Tongyi Wanxiang.
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".
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.
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()
Execute the notebook cell.
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.
Click on "Create Now" in Application Creation.
Copy the API-KEY like the same way done for model call earlier and click on "New Applications".
Rename the application and click on "set up" to choose the LM.
Click on Save and Publish.
Enter the prompt and click on the arrow.
By these approaches we can manage AI applications with model call and application set up.
Implementation of Stable Diffusion Web UI Using Heterogeneous ECS Instances
Text to Video Generation Using Alibaba Cloud's Compute Nest Aided by Model Scope
Regional Content Hub - July 22, 2024
Regional Content Hub - July 25, 2024
Regional Content Hub - July 29, 2024
vincentsiu - July 16, 2024
Regional Content Hub - July 25, 2024
Regional Content Hub - July 29, 2024
A one-stop generative AI platform to build intelligent applications that understand your business, based on Qwen model series such as Qwen-Max and other popular models
Learn MoreTop-performance foundation models from Alibaba Cloud
Learn MoreOffline SDKs for visual production, such as image segmentation, video segmentation, and character recognition, based on deep learning technologies developed by Alibaba Cloud.
Learn MoreConduct large-scale data warehousing with MaxCompute
Learn MoreMore Posts by ferdinjoe