Class: Coolhand::ApiService

Inherits:
Object
  • Object
show all
Defined in:
lib/coolhand/api_service.rb

Direct Known Subclasses

FeedbackService, LoggerService

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = "v2/llm_request_logs") ⇒ ApiService

Returns a new instance of ApiService.



12
13
14
# File 'lib/coolhand/api_service.rb', line 12

def initialize(endpoint = "v2/llm_request_logs")
  @api_endpoint = "#{base_url}/#{endpoint}"
end

Instance Attribute Details

#api_endpointObject (readonly)

Returns the value of attribute api_endpoint.



10
11
12
# File 'lib/coolhand/api_service.rb', line 10

def api_endpoint
  @api_endpoint
end

Instance Method Details

#api_keyObject



41
42
43
# File 'lib/coolhand/api_service.rb', line 41

def api_key
  configuration.api_key
end

#base_urlObject



37
38
39
# File 'lib/coolhand/api_service.rb', line 37

def base_url
  configuration.base_url
end

#configurationObject



33
34
35
# File 'lib/coolhand/api_service.rb', line 33

def configuration
  Coolhand.configuration
end

#debug_mode?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/coolhand/api_service.rb', line 49

def debug_mode?
  configuration.debug_mode
end

#send_llm_request_log(request_data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/coolhand/api_service.rb', line 16

def send_llm_request_log(request_data)
  payload = {
    llm_request_log: request_data.merge(
      collector: Collector.get_collector_string
    )
  }

  if debug_mode?
    log_separator
    log "🛠️ Debug Mode - Request payload prepared but not sent to API:"
    log JSON.pretty_generate(sanitize_payload_for_json(payload))
    nil
  else
    send_request(payload, "✅ Successfully sent request metadata")
  end
end

#silentObject



45
46
47
# File 'lib/coolhand/api_service.rb', line 45

def silent
  configuration.silent
end