Module: ActiveAgent::GenerationProvider::ClassMethods

Defined in:
lib/active_agent/generation_provider.rb

Instance Method Summary collapse

Instance Method Details

#configuration(provider_name, **options) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/active_agent/generation_provider.rb', line 15

def configuration(provider_name, **options)
  config = ActiveAgent.config[provider_name.to_s] || ActiveAgent.config[ENV["RAILS_ENV"]][provider_name.to_s]

  raise "Configuration not found for provider: #{provider_name}" unless config

  config.merge!(options)
  configure_provider(config)
end

#configure_provider(config) ⇒ Object



24
25
26
27
28
29
# File 'lib/active_agent/generation_provider.rb', line 24

def configure_provider(config)
  require "active_agent/generation_provider/#{config["service"].underscore}_provider"
  ActiveAgent::GenerationProvider.const_get("#{config["service"].camelize}Provider").new(config)
rescue LoadError
  raise "Missing generation provider for #{config["service"].inspect}"
end

#generation_providerObject



31
32
33
34
# File 'lib/active_agent/generation_provider.rb', line 31

def generation_provider
  self.generation_provider = :openai if _generation_provider.nil?
  _generation_provider
end

#generation_provider=(name_or_provider) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/active_agent/generation_provider.rb', line 41

def generation_provider=(name_or_provider)
  case name_or_provider
  when Symbol, String
    provider = configuration(name_or_provider)
    assign_provider(name_or_provider.to_s, provider)
  else
    raise ArgumentError
  end
end

#generation_provider_nameObject



36
37
38
39
# File 'lib/active_agent/generation_provider.rb', line 36

def generation_provider_name
  self.generation_provider = :openai if _generation_provider_name.nil?
  _generation_provider_name
end