omniai 3.2.1 → 3.2.3

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: b3e745edbb32e4102309da753fb4ccdb4cec5b6ab69a4bebf7260a39d99b31b4
4
+ data.tar.gz: d8546d88f6c5cdc1c665d08bd7624f284c0e5baec04162f3a7ee29474f25beba
5
5
  SHA512:
6
- metadata.gz: f57c9c5daa85d4cb77c8569abc79cb01203c531fbe9e0849a38884229c45b555df3c286cf7646c071ec000356ff748f7b53a0c0a0c26da5feba402fdf4a0cfe0
7
- data.tar.gz: c9abb1aa60e64e663428f42c66bbc78b639dbbaabdfb0510f3ced5ba25ecddbe9497a3d0389a632816748c54b209142c1d4ccc15271a0f313fb32e7a3d8c87b3
6
+ metadata.gz: 59798981414c5fb32fd3f59fcc2d159c21b37cc1b6ce979424b91e7154147d05ba36e6e048ef3ff002f70022be5b02af0c7e66eb1c2e6dab6a434cb1be9ee794
7
+ data.tar.gz: 45f18be41f25a010810901fc9fe001f31698549fdfff6c0a1b59d5eae612f53ad6cd4ff9a857cb11b2a77fe50a1e8f0d000a388f836604e7e26d1d8212635258
@@ -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,50 @@ module OmniAI
91
95
  def tool_call_list?
92
96
  !tool_call_list.nil?
93
97
  end
98
+
99
+ # Links this response chain to a parent response.
100
+ # Walks up to find the oldest response (no parent) and sets its parent.
101
+ #
102
+ # @param parent [Response]
103
+ def link_to(parent)
104
+ current = self
105
+ current = current.parent while current.parent
106
+ current.parent = parent
107
+ end
108
+
109
+ # Returns the chain of responses from oldest (first) to newest (self).
110
+ #
111
+ # @return [Array<Response>]
112
+ def response_chain
113
+ chain = []
114
+ current = self
115
+
116
+ while current
117
+ chain.unshift(current)
118
+ current = current.parent
119
+ end
120
+
121
+ chain
122
+ end
123
+
124
+ # Returns aggregated usage across all responses in the chain.
125
+ # Walks the parent chain and sums all token counts.
126
+ #
127
+ # @return [Usage, nil]
128
+ def total_usage
129
+ chain = response_chain
130
+ usages = chain.map(&:usage).compact
131
+ return nil if usages.empty?
132
+
133
+ input_tokens = usages.sum { |u| u.input_tokens || 0 }
134
+ output_tokens = usages.sum { |u| u.output_tokens || 0 }
135
+
136
+ Usage.new(
137
+ input_tokens:,
138
+ output_tokens:,
139
+ total_tokens: input_tokens + output_tokens
140
+ )
141
+ end
94
142
  end
95
143
  end
96
144
  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.link_to(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.3"
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre