Skip to content

Commit 830dbf9

Browse files
Add Prompt Caching support to Converse and ConverseStream APIs
1 parent 4ead47c commit 830dbf9

17 files changed

+519
-3
lines changed

generator/ServiceModels/bedrock-runtime/bedrock-runtime-2023-09-30.api.json

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@
316316
"min":0,
317317
"sensitive":true
318318
},
319+
"CachePointBlock":{
320+
"type":"structure",
321+
"required":["type"],
322+
"members":{
323+
"type":{"shape":"CachePointType"}
324+
}
325+
},
326+
"CachePointType":{
327+
"type":"string",
328+
"enum":["default"]
329+
},
319330
"ConflictException":{
320331
"type":"structure",
321332
"members":{
@@ -337,6 +348,7 @@
337348
"toolUse":{"shape":"ToolUseBlock"},
338349
"toolResult":{"shape":"ToolResultBlock"},
339350
"guardContent":{"shape":"GuardrailConverseContentBlock"},
351+
"cachePoint":{"shape":"CachePointBlock"},
340352
"reasoningContent":{"shape":"ReasoningContentBlock"}
341353
},
342354
"union":true
@@ -1845,7 +1857,8 @@
18451857
"type":"structure",
18461858
"members":{
18471859
"text":{"shape":"NonEmptyString"},
1848-
"guardContent":{"shape":"GuardrailConverseContentBlock"}
1860+
"guardContent":{"shape":"GuardrailConverseContentBlock"},
1861+
"cachePoint":{"shape":"CachePointBlock"}
18491862
},
18501863
"union":true
18511864
},
@@ -1915,9 +1928,21 @@
19151928
"members":{
19161929
"inputTokens":{"shape":"TokenUsageInputTokensInteger"},
19171930
"outputTokens":{"shape":"TokenUsageOutputTokensInteger"},
1918-
"totalTokens":{"shape":"TokenUsageTotalTokensInteger"}
1931+
"totalTokens":{"shape":"TokenUsageTotalTokensInteger"},
1932+
"cacheReadInputTokens":{"shape":"TokenUsageCacheReadInputTokensInteger"},
1933+
"cacheWriteInputTokens":{"shape":"TokenUsageCacheWriteInputTokensInteger"}
19191934
}
19201935
},
1936+
"TokenUsageCacheReadInputTokensInteger":{
1937+
"type":"integer",
1938+
"box":true,
1939+
"min":0
1940+
},
1941+
"TokenUsageCacheWriteInputTokensInteger":{
1942+
"type":"integer",
1943+
"box":true,
1944+
"min":0
1945+
},
19211946
"TokenUsageInputTokensInteger":{
19221947
"type":"integer",
19231948
"box":true,
@@ -1936,7 +1961,8 @@
19361961
"Tool":{
19371962
"type":"structure",
19381963
"members":{
1939-
"toolSpec":{"shape":"ToolSpecification"}
1964+
"toolSpec":{"shape":"ToolSpecification"},
1965+
"cachePoint":{"shape":"CachePointBlock"}
19401966
},
19411967
"union":true
19421968
},

generator/ServiceModels/bedrock-runtime/bedrock-runtime-2023-09-30.docs.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@
123123
"InvokeModelWithResponseStreamRequest$body": "<p>The prompt and inference parameters in the format specified in the <code>contentType</code> in the header. You must provide the body in JSON format. To see the format and content of the request and response bodies for different models, refer to <a href=\"https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html\">Inference parameters</a>. For more information, see <a href=\"https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html\">Run inference</a> in the Bedrock User Guide.</p>"
124124
}
125125
},
126+
"CachePointBlock": {
127+
"base": "<p>Defines a section of content to be cached for reuse in subsequent API calls.</p>",
128+
"refs": {
129+
"ContentBlock$cachePoint": "<p>CachePoint to include in the message.</p>",
130+
"SystemContentBlock$cachePoint": "<p>CachePoint to include in the system prompt.</p>",
131+
"Tool$cachePoint": "<p>CachePoint to include in the tool configuration.</p>"
132+
}
133+
},
134+
"CachePointType": {
135+
"base": null,
136+
"refs": {
137+
"CachePointBlock$type": "<p>Specifies the type of cache point within the CachePointBlock.</p>"
138+
}
139+
},
126140
"ConflictException": {
127141
"base": "<p>Error occurred because of a conflict while performing an operation.</p>",
128142
"refs": {
@@ -1343,6 +1357,18 @@
13431357
"ConverseStreamMetadataEvent$usage": "<p>Usage information for the conversation stream event.</p>"
13441358
}
13451359
},
1360+
"TokenUsageCacheReadInputTokensInteger": {
1361+
"base": null,
1362+
"refs": {
1363+
"TokenUsage$cacheReadInputTokens": "<p>The number of input tokens read from the cache for the request.</p>"
1364+
}
1365+
},
1366+
"TokenUsageCacheWriteInputTokensInteger": {
1367+
"base": null,
1368+
"refs": {
1369+
"TokenUsage$cacheWriteInputTokens": "<p>The number of input tokens written to the cache for the request.</p>"
1370+
}
1371+
},
13461372
"TokenUsageInputTokensInteger": {
13471373
"base": null,
13481374
"refs": {

generator/ServiceModels/bedrock-runtime/bedrock-runtime-2023-09-30.normal.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,21 @@
392392
"min":0,
393393
"sensitive":true
394394
},
395+
"CachePointBlock":{
396+
"type":"structure",
397+
"required":["type"],
398+
"members":{
399+
"type":{
400+
"shape":"CachePointType",
401+
"documentation":"<p>Specifies the type of cache point within the CachePointBlock.</p>"
402+
}
403+
},
404+
"documentation":"<p>Defines a section of content to be cached for reuse in subsequent API calls.</p>"
405+
},
406+
"CachePointType":{
407+
"type":"string",
408+
"enum":["default"]
409+
},
395410
"ConflictException":{
396411
"type":"structure",
397412
"members":{
@@ -435,6 +450,10 @@
435450
"shape":"GuardrailConverseContentBlock",
436451
"documentation":"<p>Contains the content to assess with the guardrail. If you don't specify <code>guardContent</code> in a call to the Converse API, the guardrail (if passed in the Converse API) assesses the entire message.</p> <p>For more information, see <i>Use a guardrail with the Converse API</i> in the <i>Amazon Bedrock User Guide</i>. <pre><code> &lt;/p&gt; </code></pre>"
437452
},
453+
"cachePoint":{
454+
"shape":"CachePointBlock",
455+
"documentation":"<p>CachePoint to include in the message.</p>"
456+
},
438457
"reasoningContent":{
439458
"shape":"ReasoningContentBlock",
440459
"documentation":"<p>Contains content regarding the reasoning that is carried out by the model. Reasoning refers to a Chain of Thought (CoT) that the model generates to enhance the accuracy of its final response.</p>"
@@ -2641,6 +2660,10 @@
26412660
"guardContent":{
26422661
"shape":"GuardrailConverseContentBlock",
26432662
"documentation":"<p>A content block to assess with the guardrail. Use with the <a href=\"https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html\">Converse</a> or <a href=\"https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html\">ConverseStream</a> API operations. </p> <p>For more information, see <i>Use a guardrail with the Converse API</i> in the <i>Amazon Bedrock User Guide</i>.</p>"
2663+
},
2664+
"cachePoint":{
2665+
"shape":"CachePointBlock",
2666+
"documentation":"<p>CachePoint to include in the system prompt.</p>"
26442667
}
26452668
},
26462669
"documentation":"<p>A system content block.</p>",
@@ -2729,10 +2752,28 @@
27292752
"totalTokens":{
27302753
"shape":"TokenUsageTotalTokensInteger",
27312754
"documentation":"<p>The total of input tokens and tokens generated by the model.</p>"
2755+
},
2756+
"cacheReadInputTokens":{
2757+
"shape":"TokenUsageCacheReadInputTokensInteger",
2758+
"documentation":"<p>The number of input tokens read from the cache for the request.</p>"
2759+
},
2760+
"cacheWriteInputTokens":{
2761+
"shape":"TokenUsageCacheWriteInputTokensInteger",
2762+
"documentation":"<p>The number of input tokens written to the cache for the request.</p>"
27322763
}
27332764
},
27342765
"documentation":"<p>The tokens used in a message API inference call. </p>"
27352766
},
2767+
"TokenUsageCacheReadInputTokensInteger":{
2768+
"type":"integer",
2769+
"box":true,
2770+
"min":0
2771+
},
2772+
"TokenUsageCacheWriteInputTokensInteger":{
2773+
"type":"integer",
2774+
"box":true,
2775+
"min":0
2776+
},
27362777
"TokenUsageInputTokensInteger":{
27372778
"type":"integer",
27382779
"box":true,
@@ -2754,6 +2795,10 @@
27542795
"toolSpec":{
27552796
"shape":"ToolSpecification",
27562797
"documentation":"<p>The specfication for the tool.</p>"
2798+
},
2799+
"cachePoint":{
2800+
"shape":"CachePointBlock",
2801+
"documentation":"<p>CachePoint to include in the tool configuration.</p>"
27572802
}
27582803
},
27592804
"documentation":"<p>Information about a tool that you can use with the Converse API. For more information, see <a href=\"https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use.html\">Tool use (function calling)</a> in the Amazon Bedrock User Guide.</p>",

sdk/code-analysis/ServiceAnalysis/BedrockRuntime/Generated/PropertyValueRules.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@
308308
<max>256</max>
309309
<pattern>[a-zA-Z0-9\s._:/=+@-]*</pattern>
310310
</property-value-rule>
311+
<property-value-rule>
312+
<property>Amazon.BedrockRuntime.Model.TokenUsage.CacheReadInputTokens</property>
313+
<min>0</min>
314+
</property-value-rule>
315+
<property-value-rule>
316+
<property>Amazon.BedrockRuntime.Model.TokenUsage.CacheWriteInputTokens</property>
317+
<min>0</min>
318+
</property-value-rule>
311319
<property-value-rule>
312320
<property>Amazon.BedrockRuntime.Model.TokenUsage.InputTokens</property>
313321
<min>0</min>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
/*
17+
* Do not modify this file. This file is generated from the bedrock-runtime-2023-09-30.normal.json service model.
18+
*/
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Xml.Serialization;
22+
using System.Text;
23+
using System.IO;
24+
using System.Net;
25+
26+
using Amazon.Runtime;
27+
using Amazon.Runtime.Internal;
28+
29+
#pragma warning disable CS0612,CS0618,CS1570
30+
namespace Amazon.BedrockRuntime.Model
31+
{
32+
/// <summary>
33+
/// Defines a section of content to be cached for reuse in subsequent API calls.
34+
/// </summary>
35+
public partial class CachePointBlock
36+
{
37+
private CachePointType _type;
38+
39+
/// <summary>
40+
/// Gets and sets the property Type.
41+
/// <para>
42+
/// Specifies the type of cache point within the CachePointBlock.
43+
/// </para>
44+
/// </summary>
45+
[AWSProperty(Required=true)]
46+
public CachePointType Type
47+
{
48+
get { return this._type; }
49+
set { this._type = value; }
50+
}
51+
52+
// Check to see if Type property is set
53+
internal bool IsSetType()
54+
{
55+
return this._type != null;
56+
}
57+
58+
}
59+
}

sdk/src/Services/BedrockRuntime/Generated/Model/ContentBlock.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Amazon.BedrockRuntime.Model
3737
/// </summary>
3838
public partial class ContentBlock
3939
{
40+
private CachePointBlock _cachePoint;
4041
private DocumentBlock _document;
4142
private GuardrailConverseContentBlock _guardContent;
4243
private ImageBlock _image;
@@ -46,6 +47,24 @@ public partial class ContentBlock
4647
private ToolUseBlock _toolUse;
4748
private VideoBlock _video;
4849

50+
/// <summary>
51+
/// Gets and sets the property CachePoint.
52+
/// <para>
53+
/// CachePoint to include in the message.
54+
/// </para>
55+
/// </summary>
56+
public CachePointBlock CachePoint
57+
{
58+
get { return this._cachePoint; }
59+
set { this._cachePoint = value; }
60+
}
61+
62+
// Check to see if CachePoint property is set
63+
internal bool IsSetCachePoint()
64+
{
65+
return this._cachePoint != null;
66+
}
67+
4968
/// <summary>
5069
/// Gets and sets the property Document.
5170
/// <para>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
/*
17+
* Do not modify this file. This file is generated from the bedrock-runtime-2023-09-30.normal.json service model.
18+
*/
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Globalization;
22+
using System.IO;
23+
using System.Text;
24+
using System.Xml.Serialization;
25+
26+
using Amazon.BedrockRuntime.Model;
27+
using Amazon.Runtime;
28+
using Amazon.Runtime.Internal;
29+
using Amazon.Runtime.Internal.Transform;
30+
using Amazon.Runtime.Internal.Util;
31+
using ThirdParty.Json.LitJson;
32+
33+
#pragma warning disable CS0612,CS0618
34+
namespace Amazon.BedrockRuntime.Model.Internal.MarshallTransformations
35+
{
36+
/// <summary>
37+
/// CachePointBlock Marshaller
38+
/// </summary>
39+
public class CachePointBlockMarshaller : IRequestMarshaller<CachePointBlock, JsonMarshallerContext>
40+
{
41+
/// <summary>
42+
/// Unmarshaller the response from the service to the response class.
43+
/// </summary>
44+
/// <param name="requestObject"></param>
45+
/// <param name="context"></param>
46+
/// <returns></returns>
47+
public void Marshall(CachePointBlock requestObject, JsonMarshallerContext context)
48+
{
49+
if(requestObject == null)
50+
return;
51+
if(requestObject.IsSetType())
52+
{
53+
context.Writer.WritePropertyName("type");
54+
context.Writer.Write(requestObject.Type);
55+
}
56+
57+
}
58+
59+
/// <summary>
60+
/// Singleton Marshaller.
61+
/// </summary>
62+
public readonly static CachePointBlockMarshaller Instance = new CachePointBlockMarshaller();
63+
64+
}
65+
}

0 commit comments

Comments
 (0)