Class: Nukitori::ChatFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/nukitori/chat_factory.rb

Class Method Summary collapse

Class Method Details

.create(model: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nukitori/chat_factory.rb', line 6

def create(model: nil)
  options = {}
  options[:model] = model if model

  begin
    RubyLLM.chat(**options)
  rescue RubyLLM::ModelNotFoundError
    # If custom OpenAI-compatible API is configured, add required options
    if custom_openai_api?
      options[:provider] = :openai
      options[:assume_model_exists] = true
    end

    RubyLLM.chat(**options)
  end
end