Class: Deepsearch::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/deepsearch/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



70
71
72
73
74
75
76
77
78
79
# File 'lib/deepsearch/configuration.rb', line 70

def initialize
  @tavily_api_key = nil
  @serper_api_key = nil
  @search_adapter = :tavily
  @custom_search_adapter_class = nil
  @listener = nil
  @logger = Logger.new($stdout, level: Logger::DEBUG)
  @ruby_llm = RubyLLMConfig.new
  @prompts = PromptsConfig.new
end

Instance Attribute Details

#custom_search_adapter_classObject

Returns the value of attribute custom_search_adapter_class.



66
67
68
# File 'lib/deepsearch/configuration.rb', line 66

def custom_search_adapter_class
  @custom_search_adapter_class
end

#listenerObject

An object that can listen to events from the Deepsearch pipeline. The object must respond to ‘on_deepsearch_event(event_name, **payload)`.

Examples:

class MyListener
  def on_deepsearch_event(event, step:, result:)
    puts "Event: #{event}, Step: #{step}, Success: #{result.success?}"
  end
end
Deepsearch.configure { |c| c.listener = MyListener.new


66
67
# File 'lib/deepsearch/configuration.rb', line 66

attr_accessor :tavily_api_key, :serper_api_key, :search_adapter, :custom_search_adapter_class, :logger, :listener,
:prompts

#loggerObject

Returns the value of attribute logger.



66
67
68
# File 'lib/deepsearch/configuration.rb', line 66

def logger
  @logger
end

#promptsObject

Returns the value of attribute prompts.



66
67
68
# File 'lib/deepsearch/configuration.rb', line 66

def prompts
  @prompts
end

#ruby_llmObject (readonly)

Returns the value of attribute ruby_llm.



68
69
70
# File 'lib/deepsearch/configuration.rb', line 68

def ruby_llm
  @ruby_llm
end

#search_adapterObject

Returns the value of attribute search_adapter.



66
67
68
# File 'lib/deepsearch/configuration.rb', line 66

def search_adapter
  @search_adapter
end

#serper_api_keyObject

Returns the value of attribute serper_api_key.



66
67
68
# File 'lib/deepsearch/configuration.rb', line 66

def serper_api_key
  @serper_api_key
end

#tavily_api_keyObject

Returns the value of attribute tavily_api_key.



66
67
68
# File 'lib/deepsearch/configuration.rb', line 66

def tavily_api_key
  @tavily_api_key
end

Instance Method Details

#configure_llm!Object

Configure RubyLLM with current settings from the ‘RubyLLMConfig` config object.



92
93
94
95
96
97
98
99
100
101
# File 'lib/deepsearch/configuration.rb', line 92

def configure_llm!
  require "ruby_llm" unless defined?(RubyLLM)

  RubyLLM.configure do |config|
    RubyLLMConfig.supported_attributes.each do |attr|
      value = @ruby_llm.public_send(attr)          
      config.public_send("#{attr}=", value) unless value.nil?
    end
  end
end

#reset!Object



81
82
83
84
85
86
87
88
89
# File 'lib/deepsearch/configuration.rb', line 81

def reset!
  @tavily_api_key = nil
  @serper_api_key = nil
  @search_adapter = :tavily
  @listener = nil
  @logger = Logger.new($stdout, level: Logger::DEBUG)
  @ruby_llm = RubyLLMConfig.new
  @prompts = PromptsConfig.new
end