Class: Anthropic::Helpers::Tools::Runner Private
- Inherits:
-
Object
- Object
- Anthropic::Helpers::Tools::Runner
- Defined in:
- lib/anthropic/helpers/tools/runner.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
Instance Method Summary collapse
- #each_message {|| ... } ⇒ Object private
- #each_streaming {|| ... } ⇒ Object private
- #feed_messages(*messages) ⇒ Object private
- #finished? ⇒ Boolean private
-
#initialize(client, params:, max_iterations: nil, compaction_control: nil) ⇒ Runner
constructor
private
A new instance of Runner.
- #next_message ⇒ Anthropic::Models::BetaMessage? private
- #run_until_finished ⇒ Array<Anthropic::Models::BetaMessage> private
Constructor Details
#initialize(client, params:, max_iterations: nil, compaction_control: nil) ⇒ Runner
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 a new instance of Runner.
395 396 397 398 399 400 401 402 403 404 |
# File 'lib/anthropic/helpers/tools/runner.rb', line 395 def initialize(client, params:, max_iterations: nil, compaction_control: nil) @client = client @params = params.to_h @finished = false @max_iterations = max_iterations @iteration_count = 0 @compaction_control = compaction_control @compaction_warned = false @last_response = nil end |
Instance Attribute Details
#params ⇒ Anthropic::Models::Beta::MessageCreateParams
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.
32 33 34 |
# File 'lib/anthropic/helpers/tools/runner.rb', line 32 def params @params end |
Instance Method Details
#each_message {|| ... } ⇒ Object
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.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/anthropic/helpers/tools/runner.rb', line 65 def (&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end fold do = @client.beta..create(with_helper_header(_1, StainlessHelperHeader::BETA_TOOL_RUNNER)) blk.call() [false, ] end end |
#each_streaming {|| ... } ⇒ Object
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.
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/anthropic/helpers/tools/runner.rb', line 78 def each_streaming(&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end fold do stream = @client.beta..stream(with_helper_header(_1, StainlessHelperHeader::BETA_TOOL_RUNNER)) blk.call(stream) [false, stream.] ensure stream&.close end end |
#feed_messages(*messages) ⇒ Object
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.
38 39 40 |
# File 'lib/anthropic/helpers/tools/runner.rb', line 38 def (*) self.params = {**params.to_h, messages: params[:messages].to_a + } end |
#finished? ⇒ Boolean
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.
35 |
# File 'lib/anthropic/helpers/tools/runner.rb', line 35 def finished? = @finished |
#next_message ⇒ Anthropic::Models::BetaMessage?
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.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/anthropic/helpers/tools/runner.rb', line 46 def = nil unless finished? fold do = @client.beta..create(with_helper_header(_1, StainlessHelperHeader::BETA_TOOL_RUNNER)) [true, ] end end end |
#run_until_finished ⇒ Array<Anthropic::Models::BetaMessage>
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.
58 59 60 61 62 |
# File 'lib/anthropic/helpers/tools/runner.rb', line 58 def run_until_finished = [] each_streaming { << _1. } end |