Class: Intelligence::SambaNova::Adapter

Inherits:
Legacy::Adapter show all
Defined in:
lib/intelligence/adapters/samba_nova.rb

Instance Method Summary collapse

Methods included from Legacy::ChatMethods

#chat_request_body, #chat_request_legacy_message_attributes

Methods included from Generic::ChatMethods

#chat_request_body, #chat_request_headers, #chat_request_message_attributes, #chat_request_uri, #chat_result_attributes, included, #stream_result_attributes, #stream_result_chunk_attributes, #translate_end_result, #translate_error_response_status

Instance Method Details

#chat_result_error_attributes(response) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/intelligence/adapters/samba_nova.rb', line 37

def chat_result_error_attributes( response )

  error_type, error_description = translate_error_response_status( response.status )
  result = {
    error_type: error_type.to_s,
    error_description: error_description
  }

  parsed_body = JSON.parse( response.body, symbolize_names: true ) rescue nil 
  if parsed_body && parsed_body.respond_to?( :include? ) && parsed_body.include?( :error )
    result = {
      error_type: error_type.to_s,
      error: parsed_body[ :error ][ :code ] || error_type.to_s,
      error_description: parsed_body[ :error ][ :message ] || error_description
    }
  elsif response.headers[ 'content-type' ].start_with?( 'text/plain' ) &&
        response.body && response.body.length > 0
    result[ :error_description ] = response.body
  end

  result

end