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 +4 -4
- data/lib/omniai/chat/response.rb +38 -0
- data/lib/omniai/chat.rb +5 -1
- data/lib/omniai/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20fb99d5f16d225a2f1107557c4a488341abf5c14e612a42e5091605a93592f2
|
|
4
|
+
data.tar.gz: 41b178dee887827bb1197c7a6f21c1699a40f592120964d3b6c92983563e0119
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6572fd2a7453a1cf838781187f607fb92e5675c9a206e85a46379089576837724181bcc52792370f676d876860df791dda840881fab7df6e53d2f509830ff711
|
|
7
|
+
data.tar.gz: 4de9bda7b59d8a2b529ad2c91fa5b4a930c2e00c8667907ba3e2a9a997d0b749f6221c6e72c47ea422caf2e7f6f15b10cc8bce1c9b388a9dcc9715fd73dc9460
|
data/lib/omniai/chat/response.rb
CHANGED
|
@@ -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
|
data/lib/omniai/version.rb
CHANGED