omniai-google 3.7.1 → 3.7.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: 74848884db95fef34b6c7306b2814ecf8d50797963e690a93b77e69c93cc7d3a
4
- data.tar.gz: 9fbb92e5fe4fe36d9086182391ae383180607b5e97b36a17e458dc200bef73e1
3
+ metadata.gz: 8f0e603d848a10021b4039331d5ace03d9fcebdc6ff0657128bc9cb1da5b8a4d
4
+ data.tar.gz: 53712cee681975309f887148fd7bf68e7c8b73030feff12287d3b46f7b6af7e0
5
5
  SHA512:
6
- metadata.gz: c92c79303ec17e46832115d075aa29760ba8d1f52111286d51d370c49c5266bb2e0ec9956e058a133de69bd0bb28c8ea4fa52efab34edea64f9cdc896397069e
7
- data.tar.gz: 5fc61a87b13a8bd3ba73bc6b8c150c7da1d77aef938d7c826f9eac541b78ea288fb0698bbaf9a7609d7a19a85607b3d04d97e82cd013a46f64c319c86329ea60
6
+ metadata.gz: ef4e3f492ed3c3be562ed3f1137b8264126e7b4e80134195800661bb0341b77bdce81d38ccc12ca254752f80e594e4e83adcc09afd24edff5eccf42addb51aa2
7
+ data.tar.gz: fcd20b06d373fb62752e26cfc89ca8bdac82a9bcfad1a2d6cb8d6c520a1c698d6dfcf606038f03bafd322695b20d6eba43d2e391ca860fc8ce57ca1ef78ca3ca
@@ -86,13 +86,41 @@ module OmniAI
86
86
  parts = candidate["content"]["parts"] ||= []
87
87
  last_part = parts.last
88
88
 
89
- if (last_part&.key?("text") && part.key?("text")) ||
90
- (last_part&.key?("thought") && part.key?("thought"))
89
+ if can_concatenate?(last_part, part)
91
90
  last_part["text"] += part["text"]
92
91
  else
93
92
  parts << part
94
93
  end
95
94
  end
95
+
96
+ # True when `part` should concatenate into `last_part` rather than appear
97
+ # as a new part. Two parts merge only when they're the same kind: both
98
+ # text parts AND they agree on whether they're a reasoning (thought) chunk
99
+ # or an answer chunk. Without the thought-state check, an answer chunk
100
+ # arriving after thought chunks would coalesce into the trailing thought,
101
+ # marking the visible answer as `thought: true` and causing callers to see
102
+ # an empty `response.text`.
103
+ #
104
+ # @param last_part [Hash, nil]
105
+ # @param part [Hash]
106
+ # @return [Boolean]
107
+ def can_concatenate?(last_part, part)
108
+ return false if last_part.nil?
109
+ return false unless last_part.key?("text") && part.key?("text")
110
+
111
+ thought_part?(last_part) == thought_part?(part)
112
+ end
113
+
114
+ # Gemini may omit the "thought" key entirely on answer parts (so it's nil),
115
+ # or set it explicitly to `false`, or `true` for thought parts. Normalize to
116
+ # a single boolean so the comparison in can_concatenate? treats nil and false
117
+ # as equivalent (both = "this is an answer part, not a thought part").
118
+ #
119
+ # @param part [Hash]
120
+ # @return [Boolean]
121
+ def thought_part?(part)
122
+ part["thought"] == true
123
+ end
96
124
  end
97
125
  end
98
126
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Google
5
- VERSION = "3.7.1"
5
+ VERSION = "3.7.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-google
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre