lex_common.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef LEX_COMMON__LEX_COMMON_H_
17 #define LEX_COMMON__LEX_COMMON_H_
18 
21 
22 #include <aws/lex/LexRuntimeServiceClient.h>
23 #include <aws/lex/model/PostTextRequest.h>
24 #include <aws/lex/model/PostTextResult.h>
25 #include <aws/lex/model/PostContentRequest.h>
26 #include <aws/lex/model/PostContentResult.h>
27 #include <aws/core/Aws.h>
28 #include <aws/core/utils/Outcome.h>
29 #include <aws/core/utils/memory/stl/AWSString.h>
30 #include <aws/core/utils/HashingUtils.h>
31 #include <aws/core/utils/json/JsonSerializer.h>
32 #include <aws/core/utils/logging/AWSLogging.h>
33 #include <aws/core/utils/logging/LogMacros.h>
34 
35 #include <lex_common/error_codes.h>
38 
39 #include <algorithm>
40 #include <iostream>
41 #include <iterator>
42 #include <memory>
43 #include <string>
44 #include <regex>
45 #include <unordered_map>
46 #include <vector>
47 
48 namespace Aws
49 {
50 namespace Lex
51 {
52 
56 static const char * kAllocationTag = "lex";
57 
61 struct LexRequest
62 {
63  std::string accept_type;
64  std::string text_request;
65  std::vector<uint8_t> audio_request;
66  std::string content_type;
67 };
68 
73 {
74  std::string text_response;
75  std::string message_format_type;
76  std::vector<uint8_t> audio_response;
77  std::string intent_name;
78  std::string dialog_state;
79  std::unordered_map<std::string, std::string> slots;
80  std::string session_attributes;
81 };
82 
102  Aws::LexRuntimeService::Model::PostContentResult & result,
103  LexResponse & response);
104 
106 /*\@{*/
107 std::ostream & operator<<(
108  std::ostream & os,
109  const Aws::LexRuntimeService::Model::PostContentRequest & request);
110 
111 std::ostream & operator<<(
112  std::ostream & os,
113  const Aws::LexRuntimeService::Model::PostContentResult & result);
114 /*\@}*/
115 
120 {
121 public:
129  virtual ErrorCode PostContent(
130  const LexRequest & request,
131  LexResponse & response) = 0;
132 };
133 
138 {
139 protected:
143  std::shared_ptr<LexConfiguration> lex_configuration_;
144 
148  std::shared_ptr<Aws::LexRuntimeService::LexRuntimeServiceClient> lex_runtime_client_;
149 
150 public:
159  ErrorCode ConfigureAwsLex(
160  std::shared_ptr<LexConfiguration> lex_configuration,
161  std::shared_ptr<Aws::LexRuntimeService::LexRuntimeServiceClient> lex_runtime_client);
162 
171  ErrorCode PostContent(
172  const LexRequest & request,
173  LexResponse & response) override;
174 };
175 
186  std::shared_ptr<Client::ParameterReaderInterface> params,
187  LexInteractor & lex_interactor)
188 {
189  ErrorCode result;
190  auto lex_configuration = std::make_shared<LexConfiguration>();
191  result = LoadLexParameters(*params, *lex_configuration);
192  if (result != SUCCESS) {
193  return result;
194  }
195  Client::ClientConfigurationProvider configuration_provider(params);
196  auto lex_runtime_client = Aws::MakeShared<Aws::LexRuntimeService::LexRuntimeServiceClient>(
197  kAllocationTag, configuration_provider.GetClientConfiguration());
198  lex_interactor = LexInteractor();
199  lex_interactor.ConfigureAwsLex(lex_configuration, lex_runtime_client);
200  return result;
201 }
202 
203 } // namespace Lex
204 } // namespace Aws
205 
206 #endif // LEX_COMMON__LEX_COMMON_H_
std::string text_request
Definition: lex_common.h:64
std::string session_attributes
Definition: lex_common.h:80
static const char * kAllocationTag
Definition: lex_common.h:56
std::string content_type
Definition: lex_common.h:66
std::vector< uint8_t > audio_request
Definition: lex_common.h:65
ErrorCode BuildLexInteractor(std::shared_ptr< Client::ParameterReaderInterface > params, LexInteractor &lex_interactor)
Utility function to configure a LexInteractor.
Definition: lex_common.h:185
std::shared_ptr< Aws::LexRuntimeService::LexRuntimeServiceClient > lex_runtime_client_
Definition: lex_common.h:148
ErrorCode CopyResult(Aws::LexRuntimeService::Model::PostContentResult &result, LexResponse &response)
Copy the PostContentRestult to a LexResponse.
Definition: lex_common.cpp:62
std::ostream & operator<<(std::ostream &os, const Aws::LexRuntimeService::Model::PostContentRequest &request)
Definition: lex_common.cpp:27
std::string message_format_type
Definition: lex_common.h:75
std::string accept_type
Definition: lex_common.h:63
std::unordered_map< std::string, std::string > slots
Definition: lex_common.h:79
ClientConfiguration GetClientConfiguration(const std::string &ros_version_override="")
std::string text_response
Definition: lex_common.h:74
std::shared_ptr< LexConfiguration > lex_configuration_
Definition: lex_common.h:143
std::vector< uint8_t > audio_response
Definition: lex_common.h:76
ErrorCode LoadLexParameters(const Client::ParameterReaderInterface &parameter_interface, LexConfiguration &lex_configuration)
std::string intent_name
Definition: lex_common.h:77
std::string dialog_state
Definition: lex_common.h:78


lex_common
Author(s): AWS RoboMaker
autogenerated on Sat Mar 6 2021 03:43:24