CHATBOT SDK Auto Released By yanke.yk,Version:1.19.0
Signed-off-by: haowei.yao <haowei.yao@alibaba-inc.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
2018-07-05 Version: 1.19.0
|
||||
1, A new optional parameter 'Perspectives' is introduced to the 'Chat' API. By filling this parameter when calling 'Chat', you'll get the knowledge base content within the specified perspectives.
|
||||
|
||||
2018-06-28 Version: 1.18.1
|
||||
1, ScalingConfiguration support hostName and passwordInherit
|
||||
2, ScalingConfiguration support modify
|
||||
|
||||
@@ -78,4 +78,5 @@ add_subdirectory(drds)
|
||||
add_subdirectory(jarvis)
|
||||
add_subdirectory(scdn)
|
||||
add_subdirectory(live)
|
||||
add_subdirectory(rtc)
|
||||
add_subdirectory(rtc)
|
||||
add_subdirectory(chatbot)
|
||||
86
chatbot/CMakeLists.txt
Normal file
86
chatbot/CMakeLists.txt
Normal file
@@ -0,0 +1,86 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
set(public_header_dir ${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
||||
|
||||
set(chatbot_public_header
|
||||
include/alibabacloud/chatbot/ChatbotClient.h
|
||||
include/alibabacloud/chatbot/ChatbotExport.h )
|
||||
|
||||
set(chatbot_public_header_model
|
||||
include/alibabacloud/chatbot/model/ChatRequest.h
|
||||
include/alibabacloud/chatbot/model/ChatResult.h )
|
||||
|
||||
set(chatbot_src
|
||||
src/ChatbotClient.cc
|
||||
src/model/ChatRequest.cc
|
||||
src/model/ChatResult.cc )
|
||||
|
||||
add_library(chatbot ${LIB_TYPE}
|
||||
${chatbot_public_header}
|
||||
${chatbot_public_header_model}
|
||||
${chatbot_src})
|
||||
|
||||
set_target_properties(chatbot
|
||||
PROPERTIES
|
||||
LINKER_LANGUAGE CXX
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
OUTPUT_NAME ${TARGET_OUTPUT_NAME_PREFIX}chatbot
|
||||
)
|
||||
|
||||
if(${LIB_TYPE} STREQUAL "SHARED")
|
||||
set_target_properties(chatbot
|
||||
PROPERTIES
|
||||
DEFINE_SYMBOL ALIBABACLOUD_CHATBOT_LIBRARY)
|
||||
endif()
|
||||
|
||||
target_include_directories(chatbot
|
||||
PRIVATE include
|
||||
${CMAKE_SOURCE_DIR}/core/include
|
||||
)
|
||||
target_link_libraries(chatbot
|
||||
core)
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
ExternalProject_Get_Property(jsoncpp INSTALL_DIR)
|
||||
set(jsoncpp_install_dir ${INSTALL_DIR})
|
||||
add_dependencies(chatbot
|
||||
jsoncpp)
|
||||
target_include_directories(chatbot
|
||||
PRIVATE ${jsoncpp_install_dir}/include)
|
||||
target_link_libraries(chatbot
|
||||
${jsoncpp_install_dir}/lib/jsoncpp.lib)
|
||||
set_target_properties(chatbot
|
||||
PROPERTIES
|
||||
COMPILE_OPTIONS "/bigobj")
|
||||
else()
|
||||
target_include_directories(chatbot
|
||||
PRIVATE /usr/include/jsoncpp)
|
||||
target_link_libraries(chatbot
|
||||
jsoncpp)
|
||||
endif()
|
||||
|
||||
install(FILES ${chatbot_public_header}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/chatbot)
|
||||
install(FILES ${chatbot_public_header_model}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/chatbot/model)
|
||||
install(TARGETS chatbot
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
54
chatbot/include/alibabacloud/chatbot/ChatbotClient.h
Normal file
54
chatbot/include/alibabacloud/chatbot/ChatbotClient.h
Normal file
@@ -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_CHATBOT_CHATBOTCLIENT_H_
|
||||
#define ALIBABACLOUD_CHATBOT_CHATBOTCLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include <alibabacloud/core/EndpointProvider.h>
|
||||
#include <alibabacloud/core/RpcServiceClient.h>
|
||||
#include "ChatbotExport.h"
|
||||
#include "model/ChatRequest.h"
|
||||
#include "model/ChatResult.h"
|
||||
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Chatbot
|
||||
{
|
||||
class ALIBABACLOUD_CHATBOT_EXPORT ChatbotClient : public RpcServiceClient
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, Model::ChatResult> ChatOutcome;
|
||||
typedef std::future<ChatOutcome> ChatOutcomeCallable;
|
||||
typedef std::function<void(const ChatbotClient*, const Model::ChatRequest&, const ChatOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> ChatAsyncHandler;
|
||||
|
||||
ChatbotClient(const Credentials &credentials, const ClientConfiguration &configuration);
|
||||
ChatbotClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
|
||||
ChatbotClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
|
||||
~ChatbotClient();
|
||||
ChatOutcome chat(const Model::ChatRequest &request)const;
|
||||
void chatAsync(const Model::ChatRequest& request, const ChatAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
|
||||
ChatOutcomeCallable chatCallable(const Model::ChatRequest& request) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<EndpointProvider> endpointProvider_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_CHATBOT_CHATBOTCLIENT_H_
|
||||
32
chatbot/include/alibabacloud/chatbot/ChatbotExport.h
Normal file
32
chatbot/include/alibabacloud/chatbot/ChatbotExport.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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_CHATBOT_CHATBOTEXPORT_H_
|
||||
#define ALIBABACLOUD_CHATBOT_CHATBOTEXPORT_H_
|
||||
|
||||
#include <alibabacloud/core/Global.h>
|
||||
|
||||
#if defined(ALIBABACLOUD_SHARED)
|
||||
# if defined(ALIBABACLOUD_CHATBOT_LIBRARY)
|
||||
# define ALIBABACLOUD_CHATBOT_EXPORT ALIBABACLOUD_DECL_EXPORT
|
||||
# else
|
||||
# define ALIBABACLOUD_CHATBOT_EXPORT ALIBABACLOUD_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define ALIBABACLOUD_CHATBOT_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // !ALIBABACLOUD_CHATBOT_CHATBOTEXPORT_H_
|
||||
72
chatbot/include/alibabacloud/chatbot/model/ChatRequest.h
Normal file
72
chatbot/include/alibabacloud/chatbot/model/ChatRequest.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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_CHATBOT_MODEL_CHATREQUEST_H_
|
||||
#define ALIBABACLOUD_CHATBOT_MODEL_CHATREQUEST_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <alibabacloud/core/RpcServiceRequest.h>
|
||||
#include <alibabacloud/chatbot/ChatbotExport.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Chatbot
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_CHATBOT_EXPORT ChatRequest : public RpcServiceRequest
|
||||
{
|
||||
|
||||
public:
|
||||
ChatRequest();
|
||||
~ChatRequest();
|
||||
|
||||
std::string getKnowledgeId()const;
|
||||
void setKnowledgeId(const std::string& knowledgeId);
|
||||
std::string getSenderId()const;
|
||||
void setSenderId(const std::string& senderId);
|
||||
std::string getInstanceId()const;
|
||||
void setInstanceId(const std::string& instanceId);
|
||||
std::string getSenderNick()const;
|
||||
void setSenderNick(const std::string& senderNick);
|
||||
std::vector<std::string> getPerspective()const;
|
||||
void setPerspective(const std::vector<std::string>& perspective);
|
||||
std::string getSessionId()const;
|
||||
void setSessionId(const std::string& sessionId);
|
||||
std::string getTag()const;
|
||||
void setTag(const std::string& tag);
|
||||
std::string getUtterance()const;
|
||||
void setUtterance(const std::string& utterance);
|
||||
std::string getAccessKeyId()const;
|
||||
void setAccessKeyId(const std::string& accessKeyId);
|
||||
|
||||
private:
|
||||
std::string knowledgeId_;
|
||||
std::string senderId_;
|
||||
std::string instanceId_;
|
||||
std::string senderNick_;
|
||||
std::vector<std::string> perspective_;
|
||||
std::string sessionId_;
|
||||
std::string tag_;
|
||||
std::string utterance_;
|
||||
std::string accessKeyId_;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CHATBOT_MODEL_CHATREQUEST_H_
|
||||
85
chatbot/include/alibabacloud/chatbot/model/ChatResult.h
Normal file
85
chatbot/include/alibabacloud/chatbot/model/ChatResult.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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_CHATBOT_MODEL_CHATRESULT_H_
|
||||
#define ALIBABACLOUD_CHATBOT_MODEL_CHATRESULT_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <alibabacloud/core/ServiceResult.h>
|
||||
#include <alibabacloud/chatbot/ChatbotExport.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Chatbot
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_CHATBOT_EXPORT ChatResult : public ServiceResult
|
||||
{
|
||||
public:
|
||||
struct Message
|
||||
{
|
||||
struct Text
|
||||
{
|
||||
std::string content;
|
||||
std::string answerSource;
|
||||
};
|
||||
struct Knowledge
|
||||
{
|
||||
std::string content;
|
||||
std::string answerSource;
|
||||
std::string title;
|
||||
std::string summary;
|
||||
std::string id;
|
||||
};
|
||||
struct Recommend
|
||||
{
|
||||
std::string answerSource;
|
||||
std::string content;
|
||||
std::string title;
|
||||
std::string summary;
|
||||
std::string knowledgeId;
|
||||
};
|
||||
std::string type;
|
||||
Text text;
|
||||
std::vector<Message::Recommend> recommends;
|
||||
Knowledge knowledge;
|
||||
};
|
||||
|
||||
|
||||
ChatResult();
|
||||
explicit ChatResult(const std::string &payload);
|
||||
~ChatResult();
|
||||
std::vector<Message> getMessages()const;
|
||||
std::string getTag()const;
|
||||
std::string getSessionId()const;
|
||||
std::string getMessageId()const;
|
||||
|
||||
protected:
|
||||
void parse(const std::string &payload);
|
||||
private:
|
||||
std::vector<Message> messages_;
|
||||
std::string tag_;
|
||||
std::string sessionId_;
|
||||
std::string messageId_;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_CHATBOT_MODEL_CHATRESULT_H_
|
||||
89
chatbot/src/ChatbotClient.cc
Normal file
89
chatbot/src/ChatbotClient.cc
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 <alibabacloud/chatbot/ChatbotClient.h>
|
||||
#include <alibabacloud/core/SimpleCredentialsProvider.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Location;
|
||||
using namespace AlibabaCloud::Chatbot;
|
||||
using namespace AlibabaCloud::Chatbot::Model;
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string SERVICE_NAME = "Chatbot";
|
||||
}
|
||||
|
||||
ChatbotClient::ChatbotClient(const Credentials &credentials, const ClientConfiguration &configuration) :
|
||||
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
|
||||
{
|
||||
auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "beebot");
|
||||
}
|
||||
|
||||
ChatbotClient::ChatbotClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
|
||||
RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
|
||||
{
|
||||
auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "beebot");
|
||||
}
|
||||
|
||||
ChatbotClient::ChatbotClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
|
||||
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
|
||||
{
|
||||
auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "beebot");
|
||||
}
|
||||
|
||||
ChatbotClient::~ChatbotClient()
|
||||
{}
|
||||
|
||||
ChatbotClient::ChatOutcome ChatbotClient::chat(const ChatRequest &request) const
|
||||
{
|
||||
auto endpointOutcome = endpointProvider_->getEndpoint();
|
||||
if (!endpointOutcome.isSuccess())
|
||||
return ChatOutcome(endpointOutcome.error());
|
||||
|
||||
auto outcome = makeRequest(endpointOutcome.result(), request);
|
||||
|
||||
if (outcome.isSuccess())
|
||||
return ChatOutcome(ChatResult(outcome.result()));
|
||||
else
|
||||
return ChatOutcome(outcome.error());
|
||||
}
|
||||
|
||||
void ChatbotClient::chatAsync(const ChatRequest& request, const ChatAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
|
||||
{
|
||||
auto fn = [this, request, handler, context]()
|
||||
{
|
||||
handler(this, request, chat(request), context);
|
||||
};
|
||||
|
||||
asyncExecute(new Runnable(fn));
|
||||
}
|
||||
|
||||
ChatbotClient::ChatOutcomeCallable ChatbotClient::chatCallable(const ChatRequest &request) const
|
||||
{
|
||||
auto task = std::make_shared<std::packaged_task<ChatOutcome()>>(
|
||||
[this, request]()
|
||||
{
|
||||
return this->chat(request);
|
||||
});
|
||||
|
||||
asyncExecute(new Runnable([task]() { (*task)(); }));
|
||||
return task->get_future();
|
||||
}
|
||||
|
||||
127
chatbot/src/model/ChatRequest.cc
Normal file
127
chatbot/src/model/ChatRequest.cc
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 <alibabacloud/chatbot/model/ChatRequest.h>
|
||||
|
||||
using AlibabaCloud::Chatbot::Model::ChatRequest;
|
||||
|
||||
ChatRequest::ChatRequest() :
|
||||
RpcServiceRequest("chatbot", "2017-10-11", "Chat")
|
||||
{}
|
||||
|
||||
ChatRequest::~ChatRequest()
|
||||
{}
|
||||
|
||||
std::string ChatRequest::getKnowledgeId()const
|
||||
{
|
||||
return knowledgeId_;
|
||||
}
|
||||
|
||||
void ChatRequest::setKnowledgeId(const std::string& knowledgeId)
|
||||
{
|
||||
knowledgeId_ = knowledgeId;
|
||||
setParameter("KnowledgeId", knowledgeId);
|
||||
}
|
||||
|
||||
std::string ChatRequest::getSenderId()const
|
||||
{
|
||||
return senderId_;
|
||||
}
|
||||
|
||||
void ChatRequest::setSenderId(const std::string& senderId)
|
||||
{
|
||||
senderId_ = senderId;
|
||||
setParameter("SenderId", senderId);
|
||||
}
|
||||
|
||||
std::string ChatRequest::getInstanceId()const
|
||||
{
|
||||
return instanceId_;
|
||||
}
|
||||
|
||||
void ChatRequest::setInstanceId(const std::string& instanceId)
|
||||
{
|
||||
instanceId_ = instanceId;
|
||||
setParameter("InstanceId", instanceId);
|
||||
}
|
||||
|
||||
std::string ChatRequest::getSenderNick()const
|
||||
{
|
||||
return senderNick_;
|
||||
}
|
||||
|
||||
void ChatRequest::setSenderNick(const std::string& senderNick)
|
||||
{
|
||||
senderNick_ = senderNick;
|
||||
setParameter("SenderNick", senderNick);
|
||||
}
|
||||
|
||||
std::vector<std::string> ChatRequest::getPerspective()const
|
||||
{
|
||||
return perspective_;
|
||||
}
|
||||
|
||||
void ChatRequest::setPerspective(const std::vector<std::string>& perspective)
|
||||
{
|
||||
perspective_ = perspective;
|
||||
for(int i = 0; i!= perspective.size(); i++)
|
||||
setParameter("Perspective."+ std::to_string(i), perspective.at(i));
|
||||
}
|
||||
|
||||
std::string ChatRequest::getSessionId()const
|
||||
{
|
||||
return sessionId_;
|
||||
}
|
||||
|
||||
void ChatRequest::setSessionId(const std::string& sessionId)
|
||||
{
|
||||
sessionId_ = sessionId;
|
||||
setParameter("SessionId", sessionId);
|
||||
}
|
||||
|
||||
std::string ChatRequest::getTag()const
|
||||
{
|
||||
return tag_;
|
||||
}
|
||||
|
||||
void ChatRequest::setTag(const std::string& tag)
|
||||
{
|
||||
tag_ = tag;
|
||||
setParameter("Tag", tag);
|
||||
}
|
||||
|
||||
std::string ChatRequest::getUtterance()const
|
||||
{
|
||||
return utterance_;
|
||||
}
|
||||
|
||||
void ChatRequest::setUtterance(const std::string& utterance)
|
||||
{
|
||||
utterance_ = utterance;
|
||||
setParameter("Utterance", utterance);
|
||||
}
|
||||
|
||||
std::string ChatRequest::getAccessKeyId()const
|
||||
{
|
||||
return accessKeyId_;
|
||||
}
|
||||
|
||||
void ChatRequest::setAccessKeyId(const std::string& accessKeyId)
|
||||
{
|
||||
accessKeyId_ = accessKeyId;
|
||||
setParameter("AccessKeyId", accessKeyId);
|
||||
}
|
||||
|
||||
111
chatbot/src/model/ChatResult.cc
Normal file
111
chatbot/src/model/ChatResult.cc
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 <alibabacloud/chatbot/model/ChatResult.h>
|
||||
#include <json/json.h>
|
||||
|
||||
using namespace AlibabaCloud::Chatbot;
|
||||
using namespace AlibabaCloud::Chatbot::Model;
|
||||
|
||||
ChatResult::ChatResult() :
|
||||
ServiceResult()
|
||||
{}
|
||||
|
||||
ChatResult::ChatResult(const std::string &payload) :
|
||||
ServiceResult()
|
||||
{
|
||||
parse(payload);
|
||||
}
|
||||
|
||||
ChatResult::~ChatResult()
|
||||
{}
|
||||
|
||||
void ChatResult::parse(const std::string &payload)
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
reader.parse(payload, value);
|
||||
|
||||
setRequestId(value["RequestId"].asString());
|
||||
auto allMessages = value["Messages"]["Message"];
|
||||
for (auto value : allMessages)
|
||||
{
|
||||
Message messagesObject;
|
||||
if(!value["Type"].isNull())
|
||||
messagesObject.type = value["Type"].asString();
|
||||
auto allRecommends = value["Recommends"]["Recommend"];
|
||||
for (auto value : allRecommends)
|
||||
{
|
||||
Message::Recommend recommendsObject;
|
||||
if(!value["KnowledgeId"].isNull())
|
||||
recommendsObject.knowledgeId = value["KnowledgeId"].asString();
|
||||
if(!value["Title"].isNull())
|
||||
recommendsObject.title = value["Title"].asString();
|
||||
if(!value["AnswerSource"].isNull())
|
||||
recommendsObject.answerSource = value["AnswerSource"].asString();
|
||||
if(!value["Summary"].isNull())
|
||||
recommendsObject.summary = value["Summary"].asString();
|
||||
if(!value["Content"].isNull())
|
||||
recommendsObject.content = value["Content"].asString();
|
||||
messagesObject.recommends.push_back(recommendsObject);
|
||||
}
|
||||
auto textNode = value["Text"];
|
||||
if(!textNode["Content"].isNull())
|
||||
messagesObject.text.content = textNode["Content"].asString();
|
||||
if(!textNode["AnswerSource"].isNull())
|
||||
messagesObject.text.answerSource = textNode["AnswerSource"].asString();
|
||||
auto knowledgeNode = value["Knowledge"];
|
||||
if(!knowledgeNode["Id"].isNull())
|
||||
messagesObject.knowledge.id = knowledgeNode["Id"].asString();
|
||||
if(!knowledgeNode["Title"].isNull())
|
||||
messagesObject.knowledge.title = knowledgeNode["Title"].asString();
|
||||
if(!knowledgeNode["Summary"].isNull())
|
||||
messagesObject.knowledge.summary = knowledgeNode["Summary"].asString();
|
||||
if(!knowledgeNode["Content"].isNull())
|
||||
messagesObject.knowledge.content = knowledgeNode["Content"].asString();
|
||||
if(!knowledgeNode["AnswerSource"].isNull())
|
||||
messagesObject.knowledge.answerSource = knowledgeNode["AnswerSource"].asString();
|
||||
messages_.push_back(messagesObject);
|
||||
}
|
||||
if(!value["SessionId"].isNull())
|
||||
sessionId_ = value["SessionId"].asString();
|
||||
if(!value["MessageId"].isNull())
|
||||
messageId_ = value["MessageId"].asString();
|
||||
if(!value["Tag"].isNull())
|
||||
tag_ = value["Tag"].asString();
|
||||
|
||||
}
|
||||
|
||||
std::vector<ChatResult::Message> ChatResult::getMessages()const
|
||||
{
|
||||
return messages_;
|
||||
}
|
||||
|
||||
std::string ChatResult::getTag()const
|
||||
{
|
||||
return tag_;
|
||||
}
|
||||
|
||||
std::string ChatResult::getSessionId()const
|
||||
{
|
||||
return sessionId_;
|
||||
}
|
||||
|
||||
std::string ChatResult::getMessageId()const
|
||||
{
|
||||
return messageId_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user