Class: TrieveRubyClient::MessageApi

Inherits:
Object
  • Object
show all
Defined in:
lib/trieve_ruby_client/api/message_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ MessageApi

Returns a new instance of MessageApi.



19
20
21
# File 'lib/trieve_ruby_client/api/message_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/trieve_ruby_client/api/message_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#create_message(tr_dataset, create_message_req_payload, opts = {}) ⇒ String

Create message Create message. Messages are attached to topics in order to coordinate memory of gen-AI chat sessions.Auth’ed user or api key must have an admin or owner role for the specified dataset’s organization.

Parameters:

  • tr_dataset (String)

    The dataset id to use for the request

  • create_message_req_payload (CreateMessageReqPayload)

    JSON request payload to create a message completion

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (String)


28
29
30
31
# File 'lib/trieve_ruby_client/api/message_api.rb', line 28

def create_message(tr_dataset, create_message_req_payload, opts = {})
  data, _status_code, _headers = create_message_with_http_info(tr_dataset, create_message_req_payload, opts)
  data
end

#create_message_with_http_info(tr_dataset, create_message_req_payload, opts = {}) ⇒ Array<(String, Integer, Hash)>

Create message Create message. Messages are attached to topics in order to coordinate memory of gen-AI chat sessions.Auth&#39;ed user or api key must have an admin or owner role for the specified dataset&#39;s organization.

Parameters:

  • tr_dataset (String)

    The dataset id to use for the request

  • create_message_req_payload (CreateMessageReqPayload)

    JSON request payload to create a message completion

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(String, Integer, Hash)>)

    String data, response status code and response headers



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
# File 'lib/trieve_ruby_client/api/message_api.rb', line 39

def create_message_with_http_info(tr_dataset, create_message_req_payload, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MessageApi.create_message ...'
  end
  # verify the required parameter 'tr_dataset' is set
  if @api_client.config.client_side_validation && tr_dataset.nil?
    fail ArgumentError, "Missing the required parameter 'tr_dataset' when calling MessageApi.create_message"
  end
  # verify the required parameter 'create_message_req_payload' is set
  if @api_client.config.client_side_validation && create_message_req_payload.nil?
    fail ArgumentError, "Missing the required parameter 'create_message_req_payload' when calling MessageApi.create_message"
  end
  # resource path
  local_var_path = '/api/message'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['text/plain', 'application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end
  header_params[:'TR-Dataset'] = tr_dataset

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(create_message_req_payload)

  # return_type
  return_type = opts[:debug_return_type] || 'String'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKey']

  new_options = opts.merge(
    :operation => :"MessageApi.create_message",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MessageApi#create_message\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#edit_message(tr_dataset, edit_message_req_payload, opts = {}) ⇒ nil

Edit message Edit message which exists within the topic’s chat history. This will delete the message and replace it with a new message. The new message will be generated by the AI based on the new content provided in the request body. The response will include Chunks first on the stream if the topic is using RAG. The structure will look like ‘[chunks]||mesage`. See docs.trieve.ai for more information. Auth’ed user or api key must have an admin or owner role for the specified dataset’s organization.

Parameters:

  • tr_dataset (String)

    The dataset id to use for the request

  • edit_message_req_payload (EditMessageReqPayload)

    JSON request payload to edit a message and get a new stream

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (nil)


103
104
105
106
# File 'lib/trieve_ruby_client/api/message_api.rb', line 103

def edit_message(tr_dataset, edit_message_req_payload, opts = {})
  edit_message_with_http_info(tr_dataset, edit_message_req_payload, opts)
  nil
end

#edit_message_with_http_info(tr_dataset, edit_message_req_payload, opts = {}) ⇒ Array<(nil, Integer, Hash)>

Edit message Edit message which exists within the topic&#39;s chat history. This will delete the message and replace it with a new message. The new message will be generated by the AI based on the new content provided in the request body. The response will include Chunks first on the stream if the topic is using RAG. The structure will look like &#x60;||mesage&#x60;. See docs.trieve.ai for more information. Auth&#39;ed user or api key must have an admin or owner role for the specified dataset&#39;s organization.

Parameters:

  • tr_dataset (String)

    The dataset id to use for the request

  • edit_message_req_payload (EditMessageReqPayload)

    JSON request payload to edit a message and get a new stream

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(nil, Integer, Hash)>)

    nil, response status code and response headers



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/trieve_ruby_client/api/message_api.rb', line 114

def edit_message_with_http_info(tr_dataset, edit_message_req_payload, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MessageApi.edit_message ...'
  end
  # verify the required parameter 'tr_dataset' is set
  if @api_client.config.client_side_validation && tr_dataset.nil?
    fail ArgumentError, "Missing the required parameter 'tr_dataset' when calling MessageApi.edit_message"
  end
  # verify the required parameter 'edit_message_req_payload' is set
  if @api_client.config.client_side_validation && edit_message_req_payload.nil?
    fail ArgumentError, "Missing the required parameter 'edit_message_req_payload' when calling MessageApi.edit_message"
  end
  # resource path
  local_var_path = '/api/message'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end
  header_params[:'TR-Dataset'] = tr_dataset

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(edit_message_req_payload)

  # return_type
  return_type = opts[:debug_return_type]

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKey']

  new_options = opts.merge(
    :operation => :"MessageApi.edit_message",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MessageApi#edit_message\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_all_topic_messages(tr_dataset, messages_topic_id, opts = {}) ⇒ Array<Message>

Get all messages for a given topic Get all messages for a given topic. If the topic is a RAG topic then the response will include Chunks first on each message. The structure will look like ‘[chunks]||mesage`. See docs.trieve.ai for more information.

Parameters:

  • tr_dataset (String)

    The dataset id to use for the request

  • messages_topic_id (String)

    The ID of the topic to get messages for.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



178
179
180
181
# File 'lib/trieve_ruby_client/api/message_api.rb', line 178

def get_all_topic_messages(tr_dataset, messages_topic_id, opts = {})
  data, _status_code, _headers = get_all_topic_messages_with_http_info(tr_dataset, messages_topic_id, opts)
  data
end

#get_all_topic_messages_with_http_info(tr_dataset, messages_topic_id, opts = {}) ⇒ Array<(Array<Message>, Integer, Hash)>

Get all messages for a given topic Get all messages for a given topic. If the topic is a RAG topic then the response will include Chunks first on each message. The structure will look like &#x60;||mesage&#x60;. See docs.trieve.ai for more information.

Parameters:

  • tr_dataset (String)

    The dataset id to use for the request

  • messages_topic_id (String)

    The ID of the topic to get messages for.

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Array<Message>, Integer, Hash)>)

    Array<Message> data, response status code and response headers



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/trieve_ruby_client/api/message_api.rb', line 189

def get_all_topic_messages_with_http_info(tr_dataset, messages_topic_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MessageApi.get_all_topic_messages ...'
  end
  # verify the required parameter 'tr_dataset' is set
  if @api_client.config.client_side_validation && tr_dataset.nil?
    fail ArgumentError, "Missing the required parameter 'tr_dataset' when calling MessageApi.get_all_topic_messages"
  end
  # verify the required parameter 'messages_topic_id' is set
  if @api_client.config.client_side_validation && messages_topic_id.nil?
    fail ArgumentError, "Missing the required parameter 'messages_topic_id' when calling MessageApi.get_all_topic_messages"
  end
  # resource path
  local_var_path = '/api/messages/{messages_topic_id}'.sub('{' + 'messages_topic_id' + '}', CGI.escape(messages_topic_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  header_params[:'TR-Dataset'] = tr_dataset

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Array<Message>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKey']

  new_options = opts.merge(
    :operation => :"MessageApi.get_all_topic_messages",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MessageApi#get_all_topic_messages\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#regenerate_message(tr_dataset, regenerate_message_req_payload, opts = {}) ⇒ String

Regenerate message Regenerate the assistant response to the last user message of a topic. This will delete the last message and replace it with a new message. The response will include Chunks first on the stream if the topic is using RAG. The structure will look like ‘[chunks]||mesage`. See docs.trieve.ai for more information. Auth’ed user or api key must have an admin or owner role for the specified dataset’s organization.

Parameters:

  • tr_dataset (String)

    The dataset id to use for the request

  • regenerate_message_req_payload (RegenerateMessageReqPayload)

    JSON request payload to delete an agent message then regenerate it in a strem

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (String)


248
249
250
251
# File 'lib/trieve_ruby_client/api/message_api.rb', line 248

def regenerate_message(tr_dataset, regenerate_message_req_payload, opts = {})
  data, _status_code, _headers = regenerate_message_with_http_info(tr_dataset, regenerate_message_req_payload, opts)
  data
end

#regenerate_message_with_http_info(tr_dataset, regenerate_message_req_payload, opts = {}) ⇒ Array<(String, Integer, Hash)>

Regenerate message Regenerate the assistant response to the last user message of a topic. This will delete the last message and replace it with a new message. The response will include Chunks first on the stream if the topic is using RAG. The structure will look like &#x60;||mesage&#x60;. See docs.trieve.ai for more information. Auth&#39;ed user or api key must have an admin or owner role for the specified dataset&#39;s organization.

Parameters:

  • tr_dataset (String)

    The dataset id to use for the request

  • regenerate_message_req_payload (RegenerateMessageReqPayload)

    JSON request payload to delete an agent message then regenerate it in a strem

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(String, Integer, Hash)>)

    String data, response status code and response headers



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/trieve_ruby_client/api/message_api.rb', line 259

def regenerate_message_with_http_info(tr_dataset, regenerate_message_req_payload, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: MessageApi.regenerate_message ...'
  end
  # verify the required parameter 'tr_dataset' is set
  if @api_client.config.client_side_validation && tr_dataset.nil?
    fail ArgumentError, "Missing the required parameter 'tr_dataset' when calling MessageApi.regenerate_message"
  end
  # verify the required parameter 'regenerate_message_req_payload' is set
  if @api_client.config.client_side_validation && regenerate_message_req_payload.nil?
    fail ArgumentError, "Missing the required parameter 'regenerate_message_req_payload' when calling MessageApi.regenerate_message"
  end
  # resource path
  local_var_path = '/api/message'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['text/plain', 'application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end
  header_params[:'TR-Dataset'] = tr_dataset

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(regenerate_message_req_payload)

  # return_type
  return_type = opts[:debug_return_type] || 'String'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKey']

  new_options = opts.merge(
    :operation => :"MessageApi.regenerate_message",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: MessageApi#regenerate_message\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end