omniai-anthropic 3.11.0 → 3.12.0

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: c25e922a88c2e1af6329ab3dce2308bcc75d8ce8bb02dfba1e55149aaf427488
4
- data.tar.gz: 1eb6c6dcdd6a01265d6e65de7347c05c107f5b9ea0adc782a8dae66a2c9a9d7d
3
+ metadata.gz: 07dc160091024eb4028a842392bbdf5921c74580217306b0610e0f347fda80b8
4
+ data.tar.gz: 0afd8a083a99409182777f74baf8ef128f60fc94b27650dda2b5dc10f3334c08
5
5
  SHA512:
6
- metadata.gz: b3cf984aa4edb6f096eb2c9e61e3f94f11ea0ab602c7aec06da671ea39747778c9e653a08f1bf006ace435bf8439f5a81379b82e24771ce6873b088f7ef9e68d
7
- data.tar.gz: ef55f2e7b1bdc99983a7d3b04ead43b0528d2788ffb79d18b61ce84b8736036f272728ce220e12d2611c1302d7a214dbf8c6047fa7f2dd739d2acaec8ac87593
6
+ metadata.gz: e18b6a471f4113af70d6c6dad210fd150d3502f68f812f7f30fd16f4cd30071dcf52bf2ae4dbfb0aec4d729e12dbc30e2fd76c4a13c9853bfe1ab6ac6b0dcb61
7
+ data.tar.gz: e41208c9d2904ec7a2f94af28ecb28547a827e6d34fbb5a6f0f31b5a56be284a28d893306cd8750d75f34ea0ac65012b707333701abc8cae9eb48fa48f3f09c5
data/README.md CHANGED
@@ -180,6 +180,12 @@ client.chat(prompt, tools:, cache: true) # 5-minute TTL
180
180
  client.chat(prompt, tools:, cache: { ttl: "1h" }) # 1-hour TTL
181
181
  ```
182
182
 
183
+ For single-shot prompts that share a system prompt but send a different message each time (e.g. one call per document), `cache: :system` marks only the system prompt (or the last tool), so the unique message is not written to the cache:
184
+
185
+ ```ruby
186
+ client.chat(prompt, cache: :system) # 5-minute TTL
187
+ ```
188
+
183
189
  `usage.input_tokens` reports the whole prompt, including cached tokens. The cache breakdown is on each response's raw usage:
184
190
 
185
191
  ```ruby
@@ -186,12 +186,12 @@ module OmniAI
186
186
  end
187
187
 
188
188
  # When caching, the last block of the last message is marked so each tool-loop round reads the history the
189
- # previous round wrote.
189
+ # previous round wrote. `cache: :system` skips this for single-shot prompts whose message is never reused.
190
190
  #
191
191
  # @return [Array<Hash>]
192
192
  def messages
193
193
  messages = @prompt.messages.reject(&:system?).map { |message| message.serialize(context:) }
194
- return messages unless cache_control && messages.any?
194
+ return messages unless cache_control && @options[:cache] != :system && messages.any?
195
195
 
196
196
  *history, last = messages
197
197
  history + [last.merge(content: with_cache_control(last[:content]))]
@@ -211,12 +211,13 @@ module OmniAI
211
211
 
212
212
  # Translates the opt-in `cache` option to Anthropic's `cache_control`.
213
213
  # Example: `cache: true` becomes `{ type: "ephemeral" }` (5-minute TTL)
214
+ # Example: `cache: :system` becomes `{ type: "ephemeral" }` on the system prompt (or last tool) only
214
215
  # Example: `cache: { ttl: "1h" }` becomes `{ type: "ephemeral", ttl: "1h" }`
215
216
  #
216
217
  # @return [Hash, nil]
217
218
  def cache_control
218
219
  case @options[:cache]
219
- when true then { type: "ephemeral" }
220
+ when true, :system then { type: "ephemeral" }
220
221
  when Hash then { type: "ephemeral" }.merge(@options[:cache])
221
222
  end
222
223
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Anthropic
5
- VERSION = "3.11.0"
5
+ VERSION = "3.12.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-anthropic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.0
4
+ version: 3.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre