Class: Brute::MessageTransport::OpenRouter

Inherits:
MessageTransport
  • Object
show all
Defined in:
lib/brute/message_transport/open_router.rb

Overview

MessageTransport for the open_router_enhanced gem (https://github.com/estiens/open_router_enhanced). Brute does not require it — you do:

require "open_router"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dump(message) ⇒ Object



22
23
24
# File 'lib/brute/message_transport/open_router.rb', line 22

def self.dump(message)
  message.to_h
end

.usage_metrics(response) ⇒ Object

What the provider reported about this call — the transport knows its own library's shape, so it knows which detector to ask.



19
20
21
# File 'lib/brute/message_transport/open_router.rb', line 19

def self.usage_metrics(response)
  Brute::UsageDetection::OpenRouter.detect(response)
end

Instance Method Details

#messagesObject

An OpenRouter::Response's messages (one per choice; in practice OpenRouter returns exactly one).



28
29
30
31
32
# File 'lib/brute/message_transport/open_router.rb', line 28

def messages
  return @result.choices.map { |choice| choice["message"] || choice[:message] } if @result.respond_to?(:choices)

  super
end