Class: Azure::CognitiveServices::QnamakerRuntime::V4_0::Runtime

Inherits:
Object
  • Object
show all
Includes:
MsRestAzure
Defined in:
lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb

Overview

An API for QnAMaker runtime

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Runtime

Creates and initializes a new instance of the Runtime class.



17
18
19
# File 'lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb', line 17

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientQnamakerRuntimeClient (readonly)



22
23
24
# File 'lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb', line 22

def client
  @client
end

Instance Method Details

#generate_answer(kb_id, generate_answer_payload, custom_headers: nil) ⇒ QnASearchResultList

GenerateAnswer call to query the knowledgebase.

will be added to the HTTP request.



34
35
36
37
# File 'lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb', line 34

def generate_answer(kb_id, generate_answer_payload, custom_headers:nil)
  response = generate_answer_async(kb_id, generate_answer_payload, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#generate_answer_async(kb_id, generate_answer_payload, custom_headers: nil) ⇒ Concurrent::Promise

GenerateAnswer call to query the knowledgebase.

to the HTTP request.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb', line 63

def generate_answer_async(kb_id, generate_answer_payload, custom_headers:nil)
  fail ArgumentError, '@client.runtime_endpoint is nil' if @client.runtime_endpoint.nil?
  fail ArgumentError, 'kb_id is nil' if kb_id.nil?
  fail ArgumentError, 'generate_answer_payload is nil' if generate_answer_payload.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::QnamakerRuntime::V4_0::Models::QueryDTO.mapper()
  request_content = @client.serialize(request_mapper,  generate_answer_payload)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'knowledgebases/{kbId}/generateAnswer'

  request_url = @base_url || @client.base_url
request_url = request_url.gsub('{RuntimeEndpoint}', @client.runtime_endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'kbId' => kb_id},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::QnamakerRuntime::V4_0::Models::QnASearchResultList.mapper()
        result.body = @client.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#generate_answer_with_http_info(kb_id, generate_answer_payload, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

GenerateAnswer call to query the knowledgebase.

will be added to the HTTP request.



49
50
51
# File 'lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb', line 49

def generate_answer_with_http_info(kb_id, generate_answer_payload, custom_headers:nil)
  generate_answer_async(kb_id, generate_answer_payload, custom_headers:custom_headers).value!
end

#train(kb_id, train_payload, custom_headers: nil) ⇒ Object

Train call to add suggestions to the knowledgebase.

will be added to the HTTP request.



133
134
135
136
# File 'lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb', line 133

def train(kb_id, train_payload, custom_headers:nil)
  response = train_async(kb_id, train_payload, custom_headers:custom_headers).value!
  nil
end

#train_async(kb_id, train_payload, custom_headers: nil) ⇒ Concurrent::Promise

Train call to add suggestions to the knowledgebase.

to the HTTP request.



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb', line 162

def train_async(kb_id, train_payload, custom_headers:nil)
  fail ArgumentError, '@client.runtime_endpoint is nil' if @client.runtime_endpoint.nil?
  fail ArgumentError, 'kb_id is nil' if kb_id.nil?
  fail ArgumentError, 'train_payload is nil' if train_payload.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::QnamakerRuntime::V4_0::Models::FeedbackRecordsDTO.mapper()
  request_content = @client.serialize(request_mapper,  train_payload)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'knowledgebases/{kbId}/train'

  request_url = @base_url || @client.base_url
request_url = request_url.gsub('{RuntimeEndpoint}', @client.runtime_endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'kbId' => kb_id},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 204
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

    result
  end

  promise.execute
end

#train_with_http_info(kb_id, train_payload, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Train call to add suggestions to the knowledgebase.

will be added to the HTTP request.



148
149
150
# File 'lib/4.0/generated/azure_cognitiveservices_qnamakerruntime/runtime.rb', line 148

def train_with_http_info(kb_id, train_payload, custom_headers:nil)
  train_async(kb_id, train_payload, custom_headers:custom_headers).value!
end