Teach you how to use API plug-ins to develop an AI assistant for fast image processing

This article is shared from the Huawei Cloud Community "[Case Teaching] The Convenience of Huawei Cloud API Graph Engine Service GES—AI Assistant to Help Quickly Process Pictures" , author: Huawei Cloud PaaS Service Xiaozhi.

Calling cloud services, APIs, SDKs, debugging, viewing... "I" can do it. Let's experience using Huawei Cloud API to quickly process images with AI.

1 Introduction to the API plug-in of IntelliJ IDEA

The API plug-in supports VS Code IDE, IntelliJ IDEA and other platforms, as well as Huawei Cloud's self-developed CodeArts IDE. Based on the capabilities provided by Huawei Cloud services, it helps developers build applications more efficiently and conveniently. The API plug-in is associated with API Explorer, DevStar, CodeLabs, SDK Center, and CLI Center products under Huawei Cloud Services, and is committed to providing developers with a more stable, faster, and safer programming experience.

In this plug-in, we provide but are not limited to the following functions:

Connected to the Huawei Cloud API open platform, it supports users to retrieve APIs, view API documents, debug APIs, and provide SDK sample codes for users to learn how to use APIs.

Provides Huawei Cloud SDK code snippet completion function, and SDK dependency packages are automatically introduced to accelerate users' integration of Huawei Cloud APIs.

Connected to Huawei Cloud Development Experience Center Codelabs, it provides 500+ cloud service code examples and guided tutorials to help users learn quickly.

illustrate:

On a series of platforms such as IntelliJ IDEA and VS Code IDE, the name of the Huawei Cloud API plug-in is Huawei Cloud API. In CodeArts IDE, the API plug-in is natively built into the IDE, and its name is Huawei Cloud API Development Kit.

The use of API plug-ins on series platforms such as IntelliJ IDEA and VS Code IDE depends on the base plug-in. Please install the base plug-in in advance.

2 API plug-in installation--IntelliJ IDEA

2.1 IntelliJ IDEA and other platforms

Installation preparation: Download and install JDK1.8 or higher. Download and install IntelliJ IDEA 2020.2 or higher.

Note: The IntellIj platform also supports IDEs including Goland, Pycharm, etc. If you develop on other related IDEs, please download and configure the compiler or interpreter of the corresponding language. Here we take IDEA as an example to introduce the installation process of the IntelliJ platform plug-in. For other IntelliJ series IDEs, please refer to IDEA. https://developer.huaweicloud.com/develop/toolkit.html

start installation:

You can download and install the offline package directly from the IDE plug-in market or directly from the JetBrains plug-in market.

IDE installation:

  1. Select File > Settings in the top menu bar of IntelliJ IDEA, and click Plugins in the left navigation bar of the Settings dialog box.
  2. Click Marketplace in the Plugins area and enter Huawei Cloud API in the search bar.

Huawei Cloud API will appear in the Search Results area, click Install, and restart the IDE after completion.

Offline package installation:

  1. Enter the plug-in market and search for Huawei Cloud API, enter the plug-in details page, select the desired version of the API plug-in under the Versions tab, and click Download to download the offline plug-in compressed package and save it locally. .
  2. Select File > Settings in the top menu bar of IntelliJ IDEA, and click Plugins in the left navigation bar of the Settings dialog box.
  3. Click in the Plugins area, and then click Install Plugin from Disk....
  4. Select the offline installation package (no need to decompress it) in the Choose Plugin File dialog box, and follow the prompts on the IntelliJ IDEA installation page to complete the subsequent installation steps.

Note: If the IntelliJ IDE you want to install the plug-in for is already open on the desktop, enter the plug-in market and search for Huawei Cloud API. Enter the plug-in details page. In the upper right corner, the locally opened IDE will be identified. Click the corresponding button. In the pop-up Click OK in the IDE window, and the IDE background will start to install the corresponding version of the API plug-in.

Installation verification: After successfully installing the plug-in on the IntelliJ series platform, you can see the Huawei Cloud Toolkit icon in the left navigation bar. Click on the back panel and the words Huawei Cloud API will appear, indicating that the installation is successful.

2.2 API list

The API list is displayed on the left, and all APIs can be queried. Currently, there are 206 cloud services and APIs 9213.

https://developer.huaweicloud.com/develop/toolkit.html

Registered with Huawei Cloud and completed real-name authentication

Already have a development environment that supports Java JDK 1.8 and above

The Access Key (AK) and Secret Access Key (SK) corresponding to the Huawei Cloud account have been obtained. Please create and view your AK/SK on the "My Credentials > Access Key" page of the Huawei Cloud Console. For details, see Access Keys. https://support.huaweicloud.com/usermanual-ca/zh-cn_topic_0046606340.html

endpoint refers to the application areas of Huawei Cloud services and the terminal nodes of each service. For details, please view the regions and terminal nodes.

https://developer.huaweicloud.com/endpoint

SDK acquisition and installation:

<dependency>
    <groupId>com.huaweicloud.sdk</groupId>
    <artifactId>huaweicloud-sdk-ges</artifactId>
    <version>3.0.69</version>
</dependency>

3 Quick map search

Sample code

package com.huawei.ges;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ServerResponseException;
import com.huaweicloud.sdk.ges.v1.GesClient;
import com.huaweicloud.sdk.ges.v1.model.ListGraphsRequest;
import com.huaweicloud.sdk.ges.v1.model.ListGraphsResponse;
import com.huaweicloud.sdk.ges.v1.region.GesRegion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ListGraphsDemo {
    private static final Logger logger = LoggerFactory.getLogger(ListGraphsDemo.class.getName());

    public static void main(String[] args) {
        ICredential auth = new BasicCredentials().withAk("{ak}").withSk("{sk}");
        GesClient client = GesClient.newBuilder().withCredential(auth).withRegion(GesRegion.valueOf("cn-north-4")).build();

        ListGraphsRequest request = new ListGraphsRequest();

        try {
            ListGraphsResponse response = client.listGraphs(request);
            logger.info(response.toString());
        } catch (ClientRequestException e) {
            logger.error(String.valueOf(e.getHttpStatusCode()));
            logger.error(e.toString());
        } catch (ServerResponseException e) {
            logger.error(String.valueOf(e.getHttpStatusCode()));
            logger.error(e.toString());
        }
    }
}

4 Incremental import diagram

Sample code

package com.huawei.ges;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ServerResponseException;
import com.huaweicloud.sdk.ges.v1.GesClient;
import com.huaweicloud.sdk.ges.v1.model.ImportGraphReq;
import com.huaweicloud.sdk.ges.v1.model.ImportGraphRequest;
import com.huaweicloud.sdk.ges.v1.model.ImportGraphResponse;
import com.huaweicloud.sdk.ges.v1.region.GesRegion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ImportGraphDemo {
    private static final Logger logger = LoggerFactory.getLogger(ImportGraphDemo.class.getName());

    public static void main(String[] args) {
        ICredential auth = new BasicCredentials().withAk("{ak}").withSk("{sk}");
        GesClient client = GesClient.newBuilder().withCredential(auth).withRegion(GesRegion.valueOf("cn-north-4")).build();

        // 请求Body
        ImportGraphReq importGraphReq = new ImportGraphReq();
        importGraphReq.setSchemaPath("{schemaPath}");
        importGraphReq.setEdgesetPath("{edgesetPath}");
        importGraphReq.setVertexsetPath("{vertexsetPath}");

        ImportGraphRequest request = new ImportGraphRequest();
        request.setGraphId("{graph_id}");
        request.setActionId(ImportGraphRequest.ActionIdEnum.IMPORT_GRAPH);  // 枚举类型
        request.setBody(importGraphReq);

        try {
            ImportGraphResponse response = client.importGraph(request);
            logger.info(response.toString());
        } catch (ClientRequestException e) {
            logger.error(String.valueOf(e.getHttpStatusCode()));
            logger.error(e.toString());
        } catch (ServerResponseException e) {
            logger.error(String.valueOf(e.getHttpStatusCode()));
            logger.error(e.toString());
        }
    }
}

5 Query job status on the management plane

Sample code

package com.huawei.ges;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ServerResponseException;
import com.huaweicloud.sdk.ges.v1.GesClient;
import com.huaweicloud.sdk.ges.v1.model.ShowJobRequest;
import com.huaweicloud.sdk.ges.v1.model.ShowJobResponse;
import com.huaweicloud.sdk.ges.v1.region.GesRegion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ShowJobDemo {
    private static final Logger logger = LoggerFactory.getLogger(ShowJobDemo.class.getName());

    public static void main(String[] args) {
        ICredential auth = new BasicCredentials().withAk("{ak}").withSk("{sk}");
        GesClient client = GesClient.newBuilder().withCredential(auth).withRegion(GesRegion.valueOf("cn-north-4")).build();

        ShowJobRequest request = new ShowJobRequest();
        request.setGraphId("{graphId}");
        request.setJobId("{jobId}");

        try {
            ShowJobResponse response = client.showJob(request);
            logger.info(response.toString());
        } catch (ClientRequestException e) {
            logger.error(String.valueOf(e.getHttpStatusCode()));
            logger.error(e.toString());
        } catch (ServerResponseException e) {
            logger.error(String.valueOf(e.getHttpStatusCode()));
            logger.error(e.toString());
        }
    }
}

6 Experience the charm of plug-ins

Huawei Cloud devkit is now online: https://developer.huaweicloud.com/develop/toolkit.html

Click to follow and learn about Huawei Cloud’s new technologies as soon as possible~

JetBrains releases Rust IDE: RustRover Java 21 / JDK 21 (LTS) GA With so many Java developers in China, an ecological-level application development framework .NET 8 should be born. The performance is greatly improved, and it is far ahead of .NET 7. PostgreSQL 16 is released by a former member of the Rust team I deeply regret and asked to cancel my name. I completed the removal of Nue JS on the front end yesterday. The author said that I will create a new Web ecosystem. NetEase Fuxi responded to the death of an employee who was "threatened by HR due to BUG". Ren Zhengfei: We are about to enter the fourth industrial revolution, Apple Is Huawei's teacher Vercel's new product "v0": Generate UI interface code based on text
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4526289/blog/10111788