From c4d6cb06f1456b9a73c544672f4f69948d3654b8 Mon Sep 17 00:00:00 2001 From: sdk-team Date: Wed, 15 Apr 2020 19:58:49 +0800 Subject: [PATCH] Add pre train service api. --- CHANGELOG | 3 + VERSION | 2 +- nlp-automl/CMakeLists.txt | 8 ++- .../nlp-automl/Nlp_automlClient.h | 8 +++ .../model/RunPreTrainServiceRequest.h | 54 ++++++++++++++++ .../model/RunPreTrainServiceResult.h | 51 +++++++++++++++ nlp-automl/src/Nlp-automlClient.cc | 36 +++++++++++ .../src/model/RunPreTrainServiceRequest.cc | 62 +++++++++++++++++++ .../src/model/RunPreTrainServiceResult.cc | 51 +++++++++++++++ 9 files changed, 272 insertions(+), 3 deletions(-) create mode 100644 nlp-automl/include/alibabacloud/nlp-automl/model/RunPreTrainServiceRequest.h create mode 100644 nlp-automl/include/alibabacloud/nlp-automl/model/RunPreTrainServiceResult.h create mode 100644 nlp-automl/src/model/RunPreTrainServiceRequest.cc create mode 100644 nlp-automl/src/model/RunPreTrainServiceResult.cc diff --git a/CHANGELOG b/CHANGELOG index 97252d63c..fda6bacfd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +2020-04-15 Version: 1.36.358 +- Add pre train service api. + 2020-04-15 Version: 1.36.357 - CreateNode API add return NodeId. diff --git a/VERSION b/VERSION index 3eacc2dc1..8b2d2e356 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.36.357 \ No newline at end of file +1.36.358 \ No newline at end of file diff --git a/nlp-automl/CMakeLists.txt b/nlp-automl/CMakeLists.txt index 74fcf7500..73e7f72aa 100644 --- a/nlp-automl/CMakeLists.txt +++ b/nlp-automl/CMakeLists.txt @@ -28,7 +28,9 @@ set(nlp-automl_public_header_model include/alibabacloud/nlp-automl/model/GetPredictResultRequest.h include/alibabacloud/nlp-automl/model/GetPredictResultResult.h include/alibabacloud/nlp-automl/model/RunContactReviewRequest.h - include/alibabacloud/nlp-automl/model/RunContactReviewResult.h ) + include/alibabacloud/nlp-automl/model/RunContactReviewResult.h + include/alibabacloud/nlp-automl/model/RunPreTrainServiceRequest.h + include/alibabacloud/nlp-automl/model/RunPreTrainServiceResult.h ) set(nlp-automl_src src/Nlp-automlClient.cc @@ -39,7 +41,9 @@ set(nlp-automl_src src/model/GetPredictResultRequest.cc src/model/GetPredictResultResult.cc src/model/RunContactReviewRequest.cc - src/model/RunContactReviewResult.cc ) + src/model/RunContactReviewResult.cc + src/model/RunPreTrainServiceRequest.cc + src/model/RunPreTrainServiceResult.cc ) add_library(nlp-automl ${LIB_TYPE} ${nlp-automl_public_header} diff --git a/nlp-automl/include/alibabacloud/nlp-automl/Nlp_automlClient.h b/nlp-automl/include/alibabacloud/nlp-automl/Nlp_automlClient.h index b76a3f6ce..f11167ed7 100644 --- a/nlp-automl/include/alibabacloud/nlp-automl/Nlp_automlClient.h +++ b/nlp-automl/include/alibabacloud/nlp-automl/Nlp_automlClient.h @@ -30,6 +30,8 @@ #include "model/GetPredictResultResult.h" #include "model/RunContactReviewRequest.h" #include "model/RunContactReviewResult.h" +#include "model/RunPreTrainServiceRequest.h" +#include "model/RunPreTrainServiceResult.h" namespace AlibabaCloud @@ -51,6 +53,9 @@ namespace AlibabaCloud typedef Outcome RunContactReviewOutcome; typedef std::future RunContactReviewOutcomeCallable; typedef std::function&)> RunContactReviewAsyncHandler; + typedef Outcome RunPreTrainServiceOutcome; + typedef std::future RunPreTrainServiceOutcomeCallable; + typedef std::function&)> RunPreTrainServiceAsyncHandler; Nlp_automlClient(const Credentials &credentials, const ClientConfiguration &configuration); Nlp_automlClient(const std::shared_ptr &credentialsProvider, const ClientConfiguration &configuration); @@ -68,6 +73,9 @@ namespace AlibabaCloud RunContactReviewOutcome runContactReview(const Model::RunContactReviewRequest &request)const; void runContactReviewAsync(const Model::RunContactReviewRequest& request, const RunContactReviewAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; RunContactReviewOutcomeCallable runContactReviewCallable(const Model::RunContactReviewRequest& request) const; + RunPreTrainServiceOutcome runPreTrainService(const Model::RunPreTrainServiceRequest &request)const; + void runPreTrainServiceAsync(const Model::RunPreTrainServiceRequest& request, const RunPreTrainServiceAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; + RunPreTrainServiceOutcomeCallable runPreTrainServiceCallable(const Model::RunPreTrainServiceRequest& request) const; private: std::shared_ptr endpointProvider_; diff --git a/nlp-automl/include/alibabacloud/nlp-automl/model/RunPreTrainServiceRequest.h b/nlp-automl/include/alibabacloud/nlp-automl/model/RunPreTrainServiceRequest.h new file mode 100644 index 000000000..120c98306 --- /dev/null +++ b/nlp-automl/include/alibabacloud/nlp-automl/model/RunPreTrainServiceRequest.h @@ -0,0 +1,54 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ALIBABACLOUD_NLP_AUTOML_MODEL_RUNPRETRAINSERVICEREQUEST_H_ +#define ALIBABACLOUD_NLP_AUTOML_MODEL_RUNPRETRAINSERVICEREQUEST_H_ + +#include +#include +#include +#include + +namespace AlibabaCloud +{ + namespace Nlp_automl + { + namespace Model + { + class ALIBABACLOUD_NLP_AUTOML_EXPORT RunPreTrainServiceRequest : public RpcServiceRequest + { + + public: + RunPreTrainServiceRequest(); + ~RunPreTrainServiceRequest(); + + std::string getPredictContent()const; + void setPredictContent(const std::string& predictContent); + std::string getServiceVersion()const; + void setServiceVersion(const std::string& serviceVersion); + std::string getServiceName()const; + void setServiceName(const std::string& serviceName); + + private: + std::string predictContent_; + std::string serviceVersion_; + std::string serviceName_; + + }; + } + } +} +#endif // !ALIBABACLOUD_NLP_AUTOML_MODEL_RUNPRETRAINSERVICEREQUEST_H_ \ No newline at end of file diff --git a/nlp-automl/include/alibabacloud/nlp-automl/model/RunPreTrainServiceResult.h b/nlp-automl/include/alibabacloud/nlp-automl/model/RunPreTrainServiceResult.h new file mode 100644 index 000000000..ac9a3cbf1 --- /dev/null +++ b/nlp-automl/include/alibabacloud/nlp-automl/model/RunPreTrainServiceResult.h @@ -0,0 +1,51 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ALIBABACLOUD_NLP_AUTOML_MODEL_RUNPRETRAINSERVICERESULT_H_ +#define ALIBABACLOUD_NLP_AUTOML_MODEL_RUNPRETRAINSERVICERESULT_H_ + +#include +#include +#include +#include +#include + +namespace AlibabaCloud +{ + namespace Nlp_automl + { + namespace Model + { + class ALIBABACLOUD_NLP_AUTOML_EXPORT RunPreTrainServiceResult : public ServiceResult + { + public: + + + RunPreTrainServiceResult(); + explicit RunPreTrainServiceResult(const std::string &payload); + ~RunPreTrainServiceResult(); + std::string getPredictResult()const; + + protected: + void parse(const std::string &payload); + private: + std::string predictResult_; + + }; + } + } +} +#endif // !ALIBABACLOUD_NLP_AUTOML_MODEL_RUNPRETRAINSERVICERESULT_H_ \ No newline at end of file diff --git a/nlp-automl/src/Nlp-automlClient.cc b/nlp-automl/src/Nlp-automlClient.cc index 6e37a47af..239734f63 100644 --- a/nlp-automl/src/Nlp-automlClient.cc +++ b/nlp-automl/src/Nlp-automlClient.cc @@ -195,3 +195,39 @@ Nlp_automlClient::RunContactReviewOutcomeCallable Nlp_automlClient::runContactRe return task->get_future(); } +Nlp_automlClient::RunPreTrainServiceOutcome Nlp_automlClient::runPreTrainService(const RunPreTrainServiceRequest &request) const +{ + auto endpointOutcome = endpointProvider_->getEndpoint(); + if (!endpointOutcome.isSuccess()) + return RunPreTrainServiceOutcome(endpointOutcome.error()); + + auto outcome = makeRequest(endpointOutcome.result(), request); + + if (outcome.isSuccess()) + return RunPreTrainServiceOutcome(RunPreTrainServiceResult(outcome.result())); + else + return RunPreTrainServiceOutcome(outcome.error()); +} + +void Nlp_automlClient::runPreTrainServiceAsync(const RunPreTrainServiceRequest& request, const RunPreTrainServiceAsyncHandler& handler, const std::shared_ptr& context) const +{ + auto fn = [this, request, handler, context]() + { + handler(this, request, runPreTrainService(request), context); + }; + + asyncExecute(new Runnable(fn)); +} + +Nlp_automlClient::RunPreTrainServiceOutcomeCallable Nlp_automlClient::runPreTrainServiceCallable(const RunPreTrainServiceRequest &request) const +{ + auto task = std::make_shared>( + [this, request]() + { + return this->runPreTrainService(request); + }); + + asyncExecute(new Runnable([task]() { (*task)(); })); + return task->get_future(); +} + diff --git a/nlp-automl/src/model/RunPreTrainServiceRequest.cc b/nlp-automl/src/model/RunPreTrainServiceRequest.cc new file mode 100644 index 000000000..eab9b7bae --- /dev/null +++ b/nlp-automl/src/model/RunPreTrainServiceRequest.cc @@ -0,0 +1,62 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +using AlibabaCloud::Nlp_automl::Model::RunPreTrainServiceRequest; + +RunPreTrainServiceRequest::RunPreTrainServiceRequest() : + RpcServiceRequest("nlp-automl", "2019-11-11", "RunPreTrainService") +{ + setMethod(HttpRequest::Method::Post); +} + +RunPreTrainServiceRequest::~RunPreTrainServiceRequest() +{} + +std::string RunPreTrainServiceRequest::getPredictContent()const +{ + return predictContent_; +} + +void RunPreTrainServiceRequest::setPredictContent(const std::string& predictContent) +{ + predictContent_ = predictContent; + setBodyParameter("PredictContent", predictContent); +} + +std::string RunPreTrainServiceRequest::getServiceVersion()const +{ + return serviceVersion_; +} + +void RunPreTrainServiceRequest::setServiceVersion(const std::string& serviceVersion) +{ + serviceVersion_ = serviceVersion; + setBodyParameter("ServiceVersion", serviceVersion); +} + +std::string RunPreTrainServiceRequest::getServiceName()const +{ + return serviceName_; +} + +void RunPreTrainServiceRequest::setServiceName(const std::string& serviceName) +{ + serviceName_ = serviceName; + setBodyParameter("ServiceName", serviceName); +} + diff --git a/nlp-automl/src/model/RunPreTrainServiceResult.cc b/nlp-automl/src/model/RunPreTrainServiceResult.cc new file mode 100644 index 000000000..bdb393d50 --- /dev/null +++ b/nlp-automl/src/model/RunPreTrainServiceResult.cc @@ -0,0 +1,51 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +using namespace AlibabaCloud::Nlp_automl; +using namespace AlibabaCloud::Nlp_automl::Model; + +RunPreTrainServiceResult::RunPreTrainServiceResult() : + ServiceResult() +{} + +RunPreTrainServiceResult::RunPreTrainServiceResult(const std::string &payload) : + ServiceResult() +{ + parse(payload); +} + +RunPreTrainServiceResult::~RunPreTrainServiceResult() +{} + +void RunPreTrainServiceResult::parse(const std::string &payload) +{ + Json::Reader reader; + Json::Value value; + reader.parse(payload, value); + setRequestId(value["RequestId"].asString()); + if(!value["PredictResult"].isNull()) + predictResult_ = value["PredictResult"].asString(); + +} + +std::string RunPreTrainServiceResult::getPredictResult()const +{ + return predictResult_; +} +