Class: OCI::GenerativeAiInference::Models::CohereChatResponse

Inherits:
BaseChatResponse
  • Object
show all
Defined in:
lib/oci/generative_ai_inference/models/cohere_chat_response.rb

Overview

The response to the chat conversation.

Constant Summary collapse

FINISH_REASON_ENUM =
[
  FINISH_REASON_COMPLETE = 'COMPLETE'.freeze,
  FINISH_REASON_ERROR_TOXIC = 'ERROR_TOXIC'.freeze,
  FINISH_REASON_ERROR_LIMIT = 'ERROR_LIMIT'.freeze,
  FINISH_REASON_ERROR = 'ERROR'.freeze,
  FINISH_REASON_USER_CANCEL = 'USER_CANCEL'.freeze,
  FINISH_REASON_MAX_TOKENS = 'MAX_TOKENS'.freeze,
  FINISH_REASON_UNKNOWN_ENUM_VALUE = 'UNKNOWN_ENUM_VALUE'.freeze
].freeze

Constants inherited from BaseChatResponse

BaseChatResponse::API_FORMAT_ENUM

Instance Attribute Summary collapse

Attributes inherited from BaseChatResponse

#api_format

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseChatResponse

get_subtype

Constructor Details

#initialize(attributes = {}) ⇒ CohereChatResponse

Initializes the object

Parameters:

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

    Model attributes in the form of hash

Options Hash (attributes):



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
123
124
125
126
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 91

def initialize(attributes = {})
  return unless attributes.is_a?(Hash)

  attributes['apiFormat'] = 'COHERE'

  super(attributes)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }

  self.text = attributes[:'text'] if attributes[:'text']

  self.citations = attributes[:'citations'] if attributes[:'citations']

  self.is_search_required = attributes[:'isSearchRequired'] unless attributes[:'isSearchRequired'].nil?
  self.is_search_required = false if is_search_required.nil? && !attributes.key?(:'isSearchRequired') # rubocop:disable Style/StringLiterals

  raise 'You cannot provide both :isSearchRequired and :is_search_required' if attributes.key?(:'isSearchRequired') && attributes.key?(:'is_search_required')

  self.is_search_required = attributes[:'is_search_required'] unless attributes[:'is_search_required'].nil?
  self.is_search_required = false if is_search_required.nil? && !attributes.key?(:'isSearchRequired') && !attributes.key?(:'is_search_required') # rubocop:disable Style/StringLiterals

  self.finish_reason = attributes[:'finishReason'] if attributes[:'finishReason']

  raise 'You cannot provide both :finishReason and :finish_reason' if attributes.key?(:'finishReason') && attributes.key?(:'finish_reason')

  self.finish_reason = attributes[:'finish_reason'] if attributes[:'finish_reason']

  self.search_queries = attributes[:'searchQueries'] if attributes[:'searchQueries']

  raise 'You cannot provide both :searchQueries and :search_queries' if attributes.key?(:'searchQueries') && attributes.key?(:'search_queries')

  self.search_queries = attributes[:'search_queries'] if attributes[:'search_queries']

  self.documents = attributes[:'documents'] if attributes[:'documents']
end

Instance Attribute Details

#citationsArray<OCI::GenerativeAiInference::Models::Citation>

Inline citations for the generated reply.



29
30
31
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 29

def citations
  @citations
end

#documentsArray<Object>

Documents seen by the model when generating the reply. Each document is a JSON String representing the field and values of the document.

Returns:

  • (Array<Object>)


47
48
49
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 47

def documents
  @documents
end

#finish_reasonString

[Required] Why the generation was completed.

Returns:

  • (String)


37
38
39
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 37

def finish_reason
  @finish_reason
end

#is_search_requiredBOOLEAN

Denotes that a search for documents is required.

Returns:

  • (BOOLEAN)


33
34
35
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 33

def is_search_required
  @is_search_required
end

#search_queriesArray<OCI::GenerativeAiInference::Models::SearchQuery>

Generated search queries.



41
42
43
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 41

def search_queries
  @search_queries
end

#textString

[Required] Contents of the reply generated by the model.

Returns:

  • (String)


25
26
27
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 25

def text
  @text
end

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 50

def self.attribute_map
  {
    # rubocop:disable Style/SymbolLiteral
    'api_format': :'apiFormat',
    'text': :'text',
    'citations': :'citations',
    'is_search_required': :'isSearchRequired',
    'finish_reason': :'finishReason',
    'search_queries': :'searchQueries',
    'documents': :'documents'
    # rubocop:enable Style/SymbolLiteral
  }
end

.swagger_typesObject

Attribute type mapping.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 65

def self.swagger_types
  {
    # rubocop:disable Style/SymbolLiteral
    'api_format': :'String',
    'text': :'String',
    'citations': :'Array<OCI::GenerativeAiInference::Models::Citation>',
    'is_search_required': :'BOOLEAN',
    'finish_reason': :'String',
    'search_queries': :'Array<OCI::GenerativeAiInference::Models::SearchQuery>',
    'documents': :'Array<Object>'
    # rubocop:enable Style/SymbolLiteral
  }
end

Instance Method Details

#==(other) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • other (Object)

    the other object to be compared



148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 148

def ==(other)
  return true if equal?(other)

  self.class == other.class &&
    api_format == other.api_format &&
    text == other.text &&
    citations == other.citations &&
    is_search_required == other.is_search_required &&
    finish_reason == other.finish_reason &&
    search_queries == other.search_queries &&
    documents == other.documents
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 184

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)

  self.class.swagger_types.each_pair do |key, type|
    if type =~ /^Array<(.*)>/i
      # check to ensure the input is an array given that the the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        public_method("#{key}=").call(
          attributes[self.class.attribute_map[key]]
            .map { |v| OCI::Internal::Util.convert_to_type(Regexp.last_match(1), v) }
        )
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      public_method("#{key}=").call(
        OCI::Internal::Util.convert_to_type(type, attributes[self.class.attribute_map[key]])
      )
    end
    # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#eql?(other) ⇒ Boolean

Parameters:

  • other (Object)

    the other object to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


164
165
166
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 164

def eql?(other)
  self == other
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



173
174
175
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 173

def hash
  [api_format, text, citations, is_search_required, finish_reason, search_queries, documents].hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



217
218
219
220
221
222
223
224
225
226
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 217

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = public_method(attr).call
    next if value.nil? && !instance_variable_defined?("@#{attr}")

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



211
212
213
# File 'lib/oci/generative_ai_inference/models/cohere_chat_response.rb', line 211

def to_s
  to_hash.to_s
end