Class: Looped::Application

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/looped/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model: nil, judge_model: nil, reflection_model: nil, max_iterations: 10, optimizer_batch_size: 5, optimizer_interval: 60) ⇒ Application

Returns a new instance of Application.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/looped/application.rb', line 30

def initialize(
  model: nil,
  judge_model: nil,
  reflection_model: nil,
  max_iterations: 10,
  optimizer_batch_size: 5,
  optimizer_interval: 60
)
  @state = T.let(State.new, State)
  @agent = T.let(
    Agent.new(
      model: model,
      max_iterations: max_iterations,
      judge_model: judge_model
    ),
    Agent
  )
  @optimizer = T.let(
    Optimizer.new(
      state: @state,
      batch_size: optimizer_batch_size,
      check_interval: optimizer_interval,
      reflection_model: reflection_model
    ),
    Optimizer
  )
  @running = T.let(false, T::Boolean)
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



12
13
14
# File 'lib/looped/application.rb', line 12

def agent
  @agent
end

#optimizerObject (readonly)

Returns the value of attribute optimizer.



15
16
17
# File 'lib/looped/application.rb', line 15

def optimizer
  @optimizer
end

#stateObject (readonly)

Returns the value of attribute state.



18
19
20
# File 'lib/looped/application.rb', line 18

def state
  @state
end

Instance Method Details

#runObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/looped/application.rb', line 60

def run
  @running = true

  puts banner
  puts "Type a coding task and press Enter. Type 'quit' to exit."
  puts "Type 'status' to see optimization status."
  puts ""

  Async do |task|
    # Start the optimizer in the background
    optimizer_task = task.async do
      @optimizer.start
    end

    # Run the interactive loop
    begin
      interactive_loop
    ensure
      @optimizer.stop
      optimizer_task.stop
    end
  end
end

#run_task(task:, context: '') ⇒ Object



85
86
87
# File 'lib/looped/application.rb', line 85

def run_task(task:, context: '')
  @agent.run(task: task, context: context)
end

#stopObject



90
91
92
93
# File 'lib/looped/application.rb', line 90

def stop
  @running = false
  @optimizer.stop
end