Class: Girb::Providers::RubyLlm

Inherits:
Base
  • Object
show all
Defined in:
lib/girb/providers/ruby_llm.rb

Instance Method Summary collapse

Constructor Details

#initialize(model: nil) ⇒ RubyLlm

Returns a new instance of RubyLlm.



9
10
11
# File 'lib/girb/providers/ruby_llm.rb', line 9

def initialize(model: nil)
  @model = model
end

Instance Method Details

#chat(messages:, system_prompt:, tools:, binding: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/girb/providers/ruby_llm.rb', line 13

def chat(messages:, system_prompt:, tools:, binding: nil)
  # Use specified model or RubyLLM's default
  chat_options = @model ? { model: @model } : {}
  ruby_llm_chat = ::RubyLLM.chat(**chat_options)

  # Set system prompt
  ruby_llm_chat.with_instructions(system_prompt) if system_prompt && !system_prompt.empty?

  # Add tool schemas (for API payload generation only, not auto-executed)
  tool_instances = build_tools(tools)
  tool_instances.each { |tool| ruby_llm_chat.with_tool(tool) }

  # Add all messages to the chat
  add_messages_to_chat(ruby_llm_chat, messages)

  # Get raw response without auto-executing tools
  response = raw_complete(ruby_llm_chat)

  parse_response(response)
rescue Faraday::BadRequestError => e
  Response.new(error: "API Error: #{e.message}")
rescue StandardError => e
  Response.new(error: "Error: #{e.message}")
end