Class: Brute::Middleware::LLMCall

Inherits:
Object
  • Object
show all
Defined in:
lib/brute/middleware/100_llm_call.rb

Overview

Terminal middleware. Calls the LLM with the current conversation, appends the response to the session, and fires events along the way.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/brute/middleware/100_llm_call.rb', line 12

def call(env)

  available_tools = env[:tools].each_with_object({}) do |tool, hash|
    instance = tool.is_a?(Class) ? tool.new : tool
    hash[instance.name.to_sym] = instance
  end

  completion_options = {
    model: RubyLLM.models.find(env[:model], env[:provider]),
    tools: available_tools,
    temperature: env.fetch(:temperature, 0.7),
  }

  complete(completion_options, env).then do |response|
    env[:messages] << response
  end

  env
end