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 +4 -4
- data/README.md +6 -0
- data/lib/omniai/anthropic/chat.rb +4 -3
- data/lib/omniai/anthropic/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: 07dc160091024eb4028a842392bbdf5921c74580217306b0610e0f347fda80b8
|
|
4
|
+
data.tar.gz: 0afd8a083a99409182777f74baf8ef128f60fc94b27650dda2b5dc10f3334c08
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|