omniai-google 3.7.0 → 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: 81bb938d26c6804a6942a17e57e1b1393f0e77925467a60659443f28c76d3752
4
- data.tar.gz: ce70db23296a73089d2cbc6eaf344ae269af945c112dfc0942a17e31dc116dfe
3
+ metadata.gz: 8f0e603d848a10021b4039331d5ace03d9fcebdc6ff0657128bc9cb1da5b8a4d
4
+ data.tar.gz: 53712cee681975309f887148fd7bf68e7c8b73030feff12287d3b46f7b6af7e0
5
5
  SHA512:
6
- metadata.gz: 0f5101592e2603341f545b3402a0c4b3b3516dd3fee36532d2a5691803e11610124db98d89af4e532bd16ccfff2663a37308d999dee79aea700a3066df559771
7
- data.tar.gz: 78109e536527bc9853e84111e664c25c3574a0f7c952fadbaf2a025478be0172c7cd1a203c4bdf88aa185b242f2fb74f9b88f6d88205a0ec8c479bfe2391b6a0
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
@@ -86,8 +86,8 @@ module OmniAI
86
86
  # @param input [String, Array<String>, Array<Integer>] required
87
87
  # @param model [String] optional
88
88
  # @param options [Hash] provider-specific options (e.g. task_type: "RETRIEVAL_DOCUMENT")
89
- def embed(input, model: Embed::DEFAULT_MODEL, **options)
90
- Embed.process!(input, model:, client: self, **options)
89
+ def embed(input, model: Embed::DEFAULT_MODEL, **)
90
+ Embed.process!(input, model:, client: self, **)
91
91
  end
92
92
 
93
93
  # @raise [OmniAI::Error]
@@ -44,7 +44,7 @@ module OmniAI
44
44
  prompt_tokens = data.dig("usageMetadata", "promptTokenCount")
45
45
  total_tokens = data.dig("usageMetadata", "totalTokenCount")
46
46
 
47
- Usage.new(prompt_tokens: prompt_tokens, total_tokens: total_tokens)
47
+ Usage.new(prompt_tokens:, total_tokens:)
48
48
  end
49
49
 
50
50
  # @return [Context]
@@ -73,13 +73,14 @@ module OmniAI
73
73
  #
74
74
  # @return [Symbol] :embed_content, :predict, or :batch_embed_contents
75
75
  def endpoint
76
- @endpoint ||= if @client.vertex? && @model.start_with?("gemini-embedding-2")
77
- :embed_content
78
- elsif @client.vertex?
79
- :predict
80
- else
81
- :batch_embed_contents
82
- end
76
+ @endpoint ||=
77
+ if @client.vertex? && @model.start_with?("gemini-embedding-2")
78
+ :embed_content
79
+ elsif @client.vertex?
80
+ :predict
81
+ else
82
+ :batch_embed_contents
83
+ end
83
84
  end
84
85
 
85
86
  # @return [Context]
@@ -106,7 +107,7 @@ module OmniAI
106
107
  raise ArgumentError, "embedContent does not support batch input" if @input.is_a?(Array) && @input.length > 1
107
108
 
108
109
  text = @input.is_a?(Array) ? @input.first : @input
109
- result = { content: { parts: [{ text: text }] } }
110
+ result = { content: { parts: [{ text: }] } }
110
111
  result[:taskType] = @options[:task_type] if @options[:task_type]
111
112
  result
112
113
  end
@@ -126,11 +127,11 @@ module OmniAI
126
127
  requests: inputs.map do |text|
127
128
  request = {
128
129
  model: "models/#{@model}",
129
- content: { parts: [{ text: text }] },
130
+ content: { parts: [{ text: }] },
130
131
  }
131
132
  request[:taskType] = @options[:task_type] if @options[:task_type]
132
133
  request
133
- end
134
+ end,
134
135
  }
135
136
  end
136
137
 
@@ -139,15 +140,15 @@ module OmniAI
139
140
  { key: (@client.api_key unless @client.credentials?) }.compact
140
141
  end
141
142
 
143
+ PROCEDURES = {
144
+ embed_content: "embedContent",
145
+ predict: "predict",
146
+ batch_embed_contents: "batchEmbedContents",
147
+ }.freeze
148
+
142
149
  # @return [String]
143
150
  def path
144
- procedure = case endpoint
145
- when :embed_content then "embedContent"
146
- when :predict then "predict"
147
- when :batch_embed_contents then "batchEmbedContents"
148
- end
149
-
150
- "/#{@client.path}/models/#{@model}:#{procedure}"
151
+ "/#{@client.path}/models/#{@model}:#{PROCEDURES[endpoint]}"
151
152
  end
152
153
  end
153
154
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Google
5
- VERSION = "3.7.0"
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.0
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre