omniai 3.2.1 → 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: 329e024c0319179ac8ff6757755d8c3d4275f68a759ec864200b88d1930e8e52
4
- data.tar.gz: beac9879c26d58b6ff6cc5dd71e32cd29a2e32f511971d8982e78c9ece33d654
3
+ metadata.gz: 20fb99d5f16d225a2f1107557c4a488341abf5c14e612a42e5091605a93592f2
4
+ data.tar.gz: 41b178dee887827bb1197c7a6f21c1699a40f592120964d3b6c92983563e0119
5
5
  SHA512:
6
- metadata.gz: f57c9c5daa85d4cb77c8569abc79cb01203c531fbe9e0849a38884229c45b555df3c286cf7646c071ec000356ff748f7b53a0c0a0c26da5feba402fdf4a0cfe0
7
- data.tar.gz: c9abb1aa60e64e663428f42c66bbc78b639dbbaabdfb0510f3ced5ba25ecddbe9497a3d0389a632816748c54b209142c1d4ccc15271a0f313fb32e7a3d8c87b3
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
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.1"
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.1
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre