omniai 3.2.0 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d7dc6f3dc47d5f0385f1f3cc26c509364c55c42bd6290a40a4616c16e69eb66
4
- data.tar.gz: 6b6bb6cddbcdcb699495d23137127e3f90fedd2ef179db0a504b2290ff09f1f8
3
+ metadata.gz: 20fb99d5f16d225a2f1107557c4a488341abf5c14e612a42e5091605a93592f2
4
+ data.tar.gz: 41b178dee887827bb1197c7a6f21c1699a40f592120964d3b6c92983563e0119
5
5
  SHA512:
6
- metadata.gz: 3c0a4f6a44bb5d205cda589cb1c85be12921ba1ff8fa9ef0c056b9071af05555db2cd872116597197805a43ac731afeee50925d9643546b9f77150a3465f2d06
7
- data.tar.gz: ccb72e06a11d9eb6b2f4059b95130afea945aaddacd1f90bc357670a5f052ff93d4b3fbf48612caf5e6c228ad5b9802384913f888558b8a6df3167f0d08db6b1
6
+ metadata.gz: 6572fd2a7453a1cf838781187f607fb92e5675c9a206e85a46379089576837724181bcc52792370f676d876860df791dda840881fab7df6e53d2f509830ff711
7
+ data.tar.gz: 4de9bda7b59d8a2b529ad2c91fa5b4a930c2e00c8667907ba3e2a9a997d0b749f6221c6e72c47ea422caf2e7f6f15b10cc8bce1c9b388a9dcc9715fd73dc9460
@@ -16,6 +16,10 @@ module OmniAI
16
16
  # @return [Array<Choice>]
17
17
  attr_accessor :choices
18
18
 
19
+ # @!attribute [parent]
20
+ # @return [Response, nil] the parent response in a tool call chain
21
+ attr_accessor :parent
22
+
19
23
  # @param data [Hash]
20
24
  # @param choices [Array<Choice>]
21
25
  # @param usage [Usage, nil]
@@ -91,6 +95,40 @@ module OmniAI
91
95
  def tool_call_list?
92
96
  !tool_call_list.nil?
93
97
  end
98
+
99
+ # Returns the chain of responses from oldest (first) to newest (self).
100
+ #
101
+ # @return [Array<Response>]
102
+ def response_chain
103
+ chain = []
104
+ current = self
105
+
106
+ while current
107
+ chain.unshift(current)
108
+ current = current.parent
109
+ end
110
+
111
+ chain
112
+ end
113
+
114
+ # Returns aggregated usage across all responses in the chain.
115
+ # Walks the parent chain and sums all token counts.
116
+ #
117
+ # @return [Usage, nil]
118
+ def total_usage
119
+ chain = response_chain
120
+ usages = chain.map(&:usage).compact
121
+ return nil if usages.empty?
122
+
123
+ input_tokens = usages.sum { |u| u.input_tokens || 0 }
124
+ output_tokens = usages.sum { |u| u.output_tokens || 0 }
125
+
126
+ Usage.new(
127
+ input_tokens:,
128
+ output_tokens:,
129
+ total_tokens: input_tokens + output_tokens
130
+ )
131
+ end
94
132
  end
95
133
  end
96
134
  end
@@ -12,11 +12,17 @@ module OmniAI
12
12
  # @return [Function]
13
13
  attr_accessor :function
14
14
 
15
+ # @!attribute [r] options
16
+ # @return [Hash] provider-specific options
17
+ attr_reader :options
18
+
15
19
  # @param id [String]
16
20
  # @param function [Function]
17
- def initialize(id:, function:)
21
+ # @param options [Hash] optional - used for provider-specific options
22
+ def initialize(id:, function:, **options)
18
23
  @id = id
19
24
  @function = function
25
+ @options = options
20
26
  end
21
27
 
22
28
  # @return [String]
@@ -12,11 +12,17 @@ module OmniAI
12
12
  # @return [ToolCall]
13
13
  attr_accessor :tool_call_id
14
14
 
15
+ # @!attribute [r] options
16
+ # @return [Hash] provider-specific options
17
+ attr_reader :options
18
+
15
19
  # @param content [Object] e.g. a string, hash, array, boolean, numeric, etc.
16
20
  # @param tool_call_id [String]
17
- def initialize(content:, tool_call_id:)
21
+ # @param options [Hash] optional - used for provider-specific options
22
+ def initialize(content:, tool_call_id:, **options)
18
23
  @content = content
19
24
  @tool_call_id = tool_call_id
25
+ @options = options
20
26
  end
21
27
 
22
28
  # @return [String]
data/lib/omniai/chat.rb CHANGED
@@ -113,12 +113,16 @@ module OmniAI
113
113
  end
114
114
 
115
115
  if tools? && completion.tool_call_list?
116
- spawn!(
116
+ next_completion = spawn!(
117
117
  @prompt.dup.tap do |prompt|
118
118
  prompt.messages += completion.messages
119
119
  prompt.messages += build_tool_call_messages(completion.tool_call_list)
120
120
  end
121
121
  ).process!
122
+
123
+ next_completion.parent = completion
124
+
125
+ next_completion
122
126
  else
123
127
  completion
124
128
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = "3.2.0"
4
+ VERSION = "3.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre