Class: ConsoleAgent::ContextBuilder
- Inherits:
-
Object
- Object
- ConsoleAgent::ContextBuilder
- Defined in:
- lib/console_agent/context_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
- #build_smart ⇒ Object
- #environment_context ⇒ Object
-
#initialize(config = ConsoleAgent.configuration) ⇒ ContextBuilder
constructor
A new instance of ContextBuilder.
Constructor Details
#initialize(config = ConsoleAgent.configuration) ⇒ ContextBuilder
Returns a new instance of ContextBuilder.
3 4 5 |
# File 'lib/console_agent/context_builder.rb', line 3 def initialize(config = ConsoleAgent.configuration) @config = config end |
Instance Method Details
#build ⇒ Object
7 8 9 10 11 12 |
# File 'lib/console_agent/context_builder.rb', line 7 def build build_smart rescue => e ConsoleAgent.logger.warn("ConsoleAgent: context build error: #{e.}") smart_system_instructions + "\n\n" + environment_context end |
#build_smart ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/console_agent/context_builder.rb', line 14 def build_smart parts = [] parts << smart_system_instructions parts << environment_context parts << guide_context parts << memory_context parts.compact.join("\n\n") end |
#environment_context ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/console_agent/context_builder.rb', line 23 def environment_context lines = ["## Environment"] lines << "- Ruby #{RUBY_VERSION}" lines << "- Rails #{Rails.version}" if defined?(Rails) && Rails.respond_to?(:version) if defined?(ActiveRecord::Base) && ActiveRecord::Base.connected? adapter = ActiveRecord::Base.connection.adapter_name rescue 'unknown' lines << "- Database adapter: #{adapter}" end if defined?(Bundler) key_gems = %w[devise cancancan pundit sidekiq delayed_job resque paperclip carrierwave activestorage shrine pg mysql2 sqlite3 mongoid] loaded = key_gems.select { |g| Gem.loaded_specs.key?(g) } lines << "- Key gems: #{loaded.join(', ')}" unless loaded.empty? end lines.join("\n") end |