Class: Brute::Middleware::OpenRouter::Completion
- Inherits:
-
Object
- Object
- Brute::Middleware::OpenRouter::Completion
- Defined in:
- lib/brute/middleware/open_router.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config: {}, **options) ⇒ Completion
constructor
config: keyword arguments for OpenRouter::Client.new (access_token:, request_timeout:, uri_base:, extra_headers:).
Constructor Details
#initialize(app, config: {}, **options) ⇒ Completion
config: keyword arguments for OpenRouter::Client.new (access_token:, request_timeout:, uri_base:, extra_headers:). Defaults to OpenRouter.configuration's global settings. options: keyword arguments for OpenRouter::CompletionOptions.new (model:, temperature:, tools:, ...).
12 13 14 15 16 |
# File 'lib/brute/middleware/open_router.rb', line 12 def initialize(app, config: {}, **) @app = app @config = config @options = ::OpenRouter::CompletionOptions.new(**) end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/brute/middleware/open_router.rb', line 18 def call(env) = Brute::MessageTransport::OpenRouter.dump_all(env[:messages]) ::OpenRouter::Client.new(**@config).then do |client| client.complete(, @options).then do |response| # OpenRouter in fact only returns a single message... # https://github.com/estiens/open_router_enhanced/blob/main/lib/open_router/response.rb Brute::MessageTransport::OpenRouter.wrap_each(response) do || env[:messages] << end end end env end |