Module: Senior

Defined in:
lib/senior.rb,
lib/senior/agent.rb,
lib/senior/errors.rb,
lib/senior/version.rb,
lib/senior/brains/open_ai.rb,
lib/senior/configuration/main.rb,
lib/senior/configuration/open_ai.rb

Overview

Encapsulates all the gem’s logic

Defined Under Namespace

Modules: Brains, Configuration Classes: Agent, ConfigurationError, Error

Constant Summary collapse

VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.agentAgent

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an instance of the agent

Returns:

  • (Agent)

    An instance of the agent



58
59
60
# File 'lib/senior.rb', line 58

def self.agent
  @agent ||= Agent.new
end

.auto_debug(broken_method, args, broken_method_source = nil) ⇒ Object

Calls the given method continuously, using AI to attempt to fix it until it is no longer raises exceptions

Examples:

Debugging a broken method

def square(n) = n * y

result = Senior.auto_debug(method(:square), 2)
result # => 4

Parameters:

  • broken_method (Method)

    A broken method to be fixed

  • args (Object)

    Arguments given to a broken method

  • broken_method_source (String|nil) (defaults to: nil)

    Source code of the broken method

Returns:

  • (Object)

    The return value of the previously broken but now fixed method



29
30
31
# File 'lib/senior.rb', line 29

def self.auto_debug(broken_method, args, broken_method_source = nil)
  agent.auto_debug(broken_method, args, broken_method_source)
end

.configurationSenior::Configuration::Main

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the configuration object for the Senior gem

Returns:



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

def self.configuration
  @configuration ||= Configuration::Main.new
end

.configure {|configuration| ... } ⇒ void

This method returns an undefined value.

Provides a way to configure the Senior gem

Examples:

Configuring the Senior gem

Senior.configure do |config|
  config.open_ai.access_token = 'your_openai_api_key'
end

Yields:

Yield Parameters:



86
87
88
# File 'lib/senior.rb', line 86

def self.configure
  yield(configuration)
end

.suggest_fix(broken_method, args) ⇒ String

Suggests a fix for a broken method

Examples:

Suggesting a fix for a broken method

def square(n) = n * y

suggestion = Senior.suggest_fix(method(:square), 2)
suggestion # => "def square(n) = n * n"

Parameters:

  • broken_method (Method)

    A broken method to be fixed

  • args (Object)

    Arguments given to a broken method

Returns:

  • (String)

    The suggested fix



48
49
50
# File 'lib/senior.rb', line 48

def self.suggest_fix(broken_method, args)
  agent.suggest_fix(broken_method, args)
end