Class: RubyLLM::Client
- Inherits:
-
Object
- Object
- RubyLLM::Client
- Defined in:
- lib/ruby_llm/client.rb
Overview
Client class for handling LLM provider interactions
Instance Method Summary collapse
- #chat(messages, model: nil, temperature: 0.7, stream: false, tools: nil, &block) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #list_models(provider = nil) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
6 7 8 |
# File 'lib/ruby_llm/client.rb', line 6 def initialize @providers = {} end |
Instance Method Details
#chat(messages, model: nil, temperature: 0.7, stream: false, tools: nil, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_llm/client.rb', line 10 def chat(, model: nil, temperature: 0.7, stream: false, tools: nil, &block) # Convert any hash messages to Message objects = .map do |msg| msg.is_a?(Message) ? msg : Message.new(**msg) end provider = provider_for(model) = provider.chat( , model: model, temperature: temperature, stream: stream, tools: tools, &block ) # Always return an array of messages, even for single responses .is_a?(Array) ? : [] end |
#list_models(provider = nil) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ruby_llm/client.rb', line 30 def list_models(provider = nil) if provider provider_for(nil, provider).list_models else all_providers.flat_map(&:list_models) end end |