Class: DSPy::DeepResearch::SectionQueue
- Inherits:
-
Object
- Object
- DSPy::DeepResearch::SectionQueue
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/deep_research/section_queue.rb
Constant Summary collapse
- SectionSpec =
DSPy::DeepResearch::Signatures::BuildOutline::SectionSpec
Instance Method Summary collapse
- #attempts_for(section) ⇒ Object
- #clear ⇒ Object
- #dequeue ⇒ Object
- #empty? ⇒ Boolean
- #enqueue(section) ⇒ Object
- #enqueue_follow_up(section, prompt:) ⇒ Object
- #enqueue_front(section) ⇒ Object
-
#initialize ⇒ SectionQueue
constructor
A new instance of SectionQueue.
Constructor Details
#initialize ⇒ SectionQueue
Returns a new instance of SectionQueue.
11 12 13 14 |
# File 'lib/dspy/deep_research/section_queue.rb', line 11 def initialize @queue = T.let([], T::Array[SectionSpec]) @attempts = T.let(Hash.new(0), T::Hash[String, Integer]) end |
Instance Method Details
#attempts_for(section) ⇒ Object
61 62 63 64 |
# File 'lib/dspy/deep_research/section_queue.rb', line 61 def attempts_for(section) base = base_identifier(section) @attempts.fetch(base, section.attempt) end |
#clear ⇒ Object
67 68 69 |
# File 'lib/dspy/deep_research/section_queue.rb', line 67 def clear @queue.clear end |
#dequeue ⇒ Object
51 52 53 |
# File 'lib/dspy/deep_research/section_queue.rb', line 51 def dequeue @queue.shift end |
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/dspy/deep_research/section_queue.rb', line 56 def empty? @queue.empty? end |
#enqueue(section) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/dspy/deep_research/section_queue.rb', line 17 def enqueue(section) base = base_identifier(section) @attempts[base] = section.attempt @queue << section section end |
#enqueue_follow_up(section, prompt:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dspy/deep_research/section_queue.rb', line 33 def enqueue_follow_up(section, prompt:) base = base_identifier(section) next_attempt = section.attempt + 1 @queue.delete_if { |queued| base_identifier(queued) == base } follow_up = SectionSpec.new( identifier: "#{base}-retry-#{next_attempt}", title: section.title, prompt: prompt, token_budget: section.token_budget, attempt: next_attempt, parent_identifier: section.parent_identifier || base ) enqueue_front(follow_up) end |
#enqueue_front(section) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/dspy/deep_research/section_queue.rb', line 25 def enqueue_front(section) base = base_identifier(section) @attempts[base] = section.attempt @queue.unshift(section) section end |