教你用API插件开发一个AI快速处理图片小助手

本文分享自华为云社区《【案例教学】华为云API图引擎服务 GES的便捷性---AI帮助快速处理图片小助手》,作者:华为云PaaS服务小智。

调用云服务、API、SDK、调试、查看...... "我"都行,一起来体验用Huawei Cloud API实现AI快速处理图片。

1 IntelliJ IDEA 之API插件介绍

API插件支持 VS Code IDE、IntelliJ IDEA等平台、以及华为云自研 CodeArts IDE,基于华为云服务提供的能力,帮助开发者更高效、便捷的搭建应用。API插件关联华为云服务下的 API Explorer、DevStar、CodeLabs、SDK 中心和 CLI 中心产品,致力于为开发者提供更稳定、快速、安全的编程体验。

在本插件中,我们提供了但不局限于如下的功能:

对接华为云API开放平台,支持用户检索API、查看API文档、调试API、以及提供SDK示例代码供用户学习如何使用API。

提供华为云SDK代码片段补全功能,SDK依赖包自动引入,加速用户集成华为云API。

对接华为云开发体验馆Codelabs,提供500+云服务代码示例,向导式教程帮助用户快速学习。

说明:

在IntelliJ IDEA等系列平台和VS Code IDE,华为云API插件的名称是Huawei Cloud API。而在CodeArts IDE,API插件是IDE原生内置的,名称是华为云API开发套件。

API插件在IntelliJ IDEA等系列平台和VS Code IDE的使用依赖底座插件,请提前安装底座插件。

2 API插件安装--IntelliJ IDEA

2.1 IntelliJ IDEA等平台

安装准备:下载并安装JDK1.8或更高版本。下载并安装IntelliJ IDEA 2020.2或更高版本。

须知:IntellIj平台同时支撑包括Goland、Pycharm等在内的IDE,若在其它相关IDE上开发,请下载配置好对应语言的编译器或者解释器。这里以IDEA为例介绍IntelliJ平台插件的安装流程,其他IntelliJ系列的IDE请参考IDEA。https://developer.huaweicloud.com/develop/toolkit.html

开始安装:

您可以在直接在IDE插件市场或者直接在JetBrains插件市场下载离线包安装。

IDE安装:

  1. 在IntelliJ IDEA顶部菜单栏中选择File > Settings,在Settings对话框的左侧导航栏中单击Plugins。
  2. Plugins区域单击Marketplace,在搜索栏中输入Huawei Cloud API。

Search Results区域会出现Huawei Cloud API,单击Install,完成后重启IDE。

离线包安装:

  1. 进入插件市场搜索Huawei Cloud API,进入插件详情页,在Versions页签下选择想要版本的API插件,点击Download下载离线的插件压缩包保存到本地。。
  2. 在IntelliJ IDEA顶部菜单栏中选择File > Settings,在Settings对话框的左侧导航栏中单击Plugins。
  3. 在Plugins区域单击 ,再单击Install Plugin from Disk...。
  4. 在Choose Plugin File对话框中选择离线安装包(不用解压),并按照IntelliJ IDEA安装页面的提示,完成后续安装步骤。

说明:若当前您想要安装插件的IntelliJ IDE已经在桌面打开,则进入插件市场搜索Huawei Cloud API,进入插件详情页,在右上角会识别到本地已经打开的IDE,点击相应按钮,在弹出的IDE窗口中点击ok,则IDE后台会开始安装相应版本的API插件。

安装验证:在IntelliJ系列平台上安装插件成功后在左侧的导航栏中可以看到Huawei Cloud Toolkit图标,点击后面板会出现Huawei Cloud API的字样,则说明安装成功。

2.2 API列表

左侧展示API列表,可以查询所有API,目前云服务206,APIs9213

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

已 注册 华为云,并完成 实名认证

已具备开发环境 ,支持Java JDK 1.8及其以上版本

已获取华为云账号对应的Access Key(AK)和Secret Access Key(SK)。请在华为云控制台"我的凭证 > 访问密钥"页面上创建和查看您的 AK/SK。具体请参见访问密钥。https://support.huaweicloud.com/usermanual-ca/zh-cn_topic_0046606340.html

endpoint 华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点。

https://developer.huaweicloud.com/endpoint

SDK 获取和安装:

复制代码
<dependency>
    <groupId>com.huaweicloud.sdk</groupId>
    <artifactId>huaweicloud-sdk-ges</artifactId>
    <version>3.0.69</version>
</dependency>

3 快速查图

示例代码

复制代码
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 增量导入图

示例代码

复制代码
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 管理面查询Job状态

示例代码

复制代码
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 体验插件的魅力

华为云devkit已上线:https://developer.huaweicloud.com/develop/toolkit.html

点击关注,第一时间了解华为云新鲜技术~

相关推荐
Rose 使者1 天前
全球IP归属地查询接口如何用C#进行调用?
c#·api·ip地址
莱茵不哈哈2 天前
My图床项目
api·base·图床
Dynadot_tech2 天前
使用API有效率地管理Dynadot域名,查看域名市场中所售域名的详细信息
api·域名·dynadot·域名市场
ApiHug3 天前
ApiHug 1.3.9 支持 Spring 3.5.0 + Plugin 0.7.4 内置小插件升级!儿童节快乐!!!
java·后端·spring·api·apihug·apismart
webmote335 天前
DeepSeek私域数据训练之封装Anything LLM的API 【net 9】
.net·api·deepseek
慧都小妮子5 天前
跨平台浏览器集成库JxBrowser 支持 Chrome 扩展程序,高效赋能 Java 桌面应用
开发语言·python·api·jxbrowser·chrome 扩展程序
Web极客码5 天前
WordPress 6.5版本带来的新功能
前端·api·wordpress
天才在此7 天前
开源库免费API服务平台 ALLBEAPI
开源·api·免费
Estar.Lee9 天前
腾讯云开发者社区文章内容提取免费API接口教程
android·云计算·腾讯云·api·免费api·api大全
dearxue9 天前
ApiHug 1.3.9 支持 Spring 3.5.0 + Plugin 0.7.4 内置小插件升级 & 儿童节快乐!
spring·api·intellij idea