Class: Intelligence::SambaNova::Adapter

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

Constant Summary collapse

DEFAULT_BASE_URI =
"https://api.sambanova.ai/v1"

Instance Method Summary collapse

Methods included from ChatResponseMethods

#result

Methods included from ChatRequestMethods

#receive_result

Instance Method Details

#chat_result_error_attributes(response) ⇒ Object



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

def chat_result_error_attributes( response )
  error_type, error_description = to_error_response( 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 ) && 
     parsed_body[ :error ].is_a?( String )
    result[ :error_description ] = parsed_body[ :error ]
  elsif response.headers[ 'content-type' ].start_with?( 'text/plain' ) &&
        response.body && response.body.length > 0
    result[ :error_description ] = response.body
  end

  result
end