Skip to content

Commit

Permalink
This release adds support for using Guardrails with the Converse and …
Browse files Browse the repository at this point in the history
…ConverseStream APIs.
  • Loading branch information
aws-sdk-dotnet-automation committed Jun 18, 2024
1 parent eeab51c commit a37aeb4
Show file tree
Hide file tree
Showing 70 changed files with 5,660 additions and 134 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@
<property>Amazon.BedrockRuntime.Model.ContentBlockStopEvent.ContentBlockIndex</property>
<min>0</min>
</property-value-rule>
<property-value-rule>
<property>Amazon.BedrockRuntime.Model.GuardrailConfiguration.GuardrailIdentifier</property>
<min>0</min>
<max>2048</max>
<pattern>(([a-z0-9]+)|(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:[0-9]{12}:guardrail/[a-z0-9]+))</pattern>
</property-value-rule>
<property-value-rule>
<property>Amazon.BedrockRuntime.Model.GuardrailConfiguration.GuardrailVersion</property>
<pattern>(([1-9][0-9]{0,7})|(DRAFT))</pattern>
</property-value-rule>
<property-value-rule>
<property>Amazon.BedrockRuntime.Model.GuardrailStreamConfiguration.GuardrailIdentifier</property>
<min>0</min>
<max>2048</max>
<pattern>(([a-z0-9]+)|(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:[0-9]{12}:guardrail/[a-z0-9]+))</pattern>
</property-value-rule>
<property-value-rule>
<property>Amazon.BedrockRuntime.Model.GuardrailStreamConfiguration.GuardrailVersion</property>
<pattern>(([1-9][0-9]{0,7})|(DRAFT))</pattern>
</property-value-rule>
<property-value-rule>
<property>Amazon.BedrockRuntime.Model.ImageSource.Bytes</property>
<min>1</min>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
namespace Amazon.BedrockRuntime.Model
{
/// <summary>
/// The model must request at least one tool (no text is generated).
/// The model must request at least one tool (no text is generated). For example, <c>{"any"
/// : {}}</c>.
/// </summary>
public partial class AnyToolChoice
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
namespace Amazon.BedrockRuntime.Model
{
/// <summary>
/// The Model automatically decides if a tool should be called or to whether to generate
/// text instead.
/// The Model automatically decides if a tool should be called or whether to generate
/// text instead. For example, <c>{"auto" : {}}</c>.
/// </summary>
public partial class AutoToolChoice
{
Expand Down
28 changes: 27 additions & 1 deletion sdk/src/Services/BedrockRuntime/Generated/Model/ContentBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,41 @@
namespace Amazon.BedrockRuntime.Model
{
/// <summary>
/// A block of content for a message.
/// A block of content for a message that you pass to, or receive from, a model with the
/// Converse API (<a>Converse</a> and <a>ConverseStream</a>).
/// </summary>
public partial class ContentBlock
{
private GuardrailConverseContentBlock _guardContent;
private ImageBlock _image;
private string _text;
private ToolResultBlock _toolResult;
private ToolUseBlock _toolUse;

/// <summary>
/// Gets and sets the property GuardContent.
/// <para>
/// Contains the content to assess with the guardrail. If you don't specify <c>guardContent</c>
/// in a call to the Converse API, the guardrail (if passed in the Converse API) assesses
/// the entire message.
/// </para>
///
/// <para>
/// For more information, see <i>Use a guardrail with the Converse API</i> in the <i>Amazon
/// Bedrock User Guide</i>. <pre><c> &lt;/p&gt; </c></pre>
/// </summary>
public GuardrailConverseContentBlock GuardContent
{
get { return this._guardContent; }
set { this._guardContent = value; }
}

// Check to see if GuardContent property is set
internal bool IsSetGuardContent()
{
return this._guardContent != null;
}

/// <summary>
/// Gets and sets the property Image.
/// <para>
Expand Down
37 changes: 33 additions & 4 deletions sdk/src/Services/BedrockRuntime/Generated/Model/ConverseRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,30 @@ namespace Amazon.BedrockRuntime.Model
/// Sends messages to the specified Amazon Bedrock model. <c>Converse</c> provides a consistent
/// interface that works with all models that support messages. This allows you to write
/// code once and use it with different models. Should a model have unique inference parameters,
/// you can also pass those unique parameters to the model. 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.
/// you can also pass those unique parameters to the model.
///
///
/// <para>
/// For information about the Converse API, see <i>Use the Converse API</i> in the <i>Amazon
/// Bedrock User Guide</i>. To use a guardrail, see <i>Use a guardrail with the Converse
/// API</i> in the <i>Amazon Bedrock User Guide</i>. To use a tool with a model, see <i>Tool
/// use (Function calling)</i> in the <i>Amazon Bedrock User Guide</i>
/// </para>
///
/// <para>
/// For example code, see <i>Converse API examples</i> in the <i>Amazon Bedrock User Guide</i>.
///
/// </para>
///
/// <para>
/// This operation requires permission for the <c>bedrock:InvokeModel</c> action.
/// </para>
/// </summary>
public partial class ConverseRequest : AmazonBedrockRuntimeRequest
{
private Amazon.Runtime.Documents.Document _additionalModelRequestFields;
private List<string> _additionalModelResponseFieldPaths = AWSConfigs.InitializeCollections ? new List<string>() : null;
private GuardrailConfiguration _guardrailConfig;
private InferenceConfiguration _inferenceConfig;
private List<Message> _messages = AWSConfigs.InitializeCollections ? new List<Message>() : null;
private string _modelId;
Expand Down Expand Up @@ -78,7 +89,7 @@ internal bool IsSetAdditionalModelRequestFields()
/// Gets and sets the property AdditionalModelResponseFieldPaths.
/// <para>
/// Additional model parameters field paths to return in the response. <c>Converse</c>
/// returns the requested fields as a JSON Pointer object in the <c>additionalModelResultFields</c>
/// returns the requested fields as a JSON Pointer object in the <c>additionalModelResponseFields</c>
/// field. The following is example JSON for <c>additionalModelResponseFieldPaths</c>.
/// </para>
///
Expand Down Expand Up @@ -110,6 +121,24 @@ internal bool IsSetAdditionalModelResponseFieldPaths()
return this._additionalModelResponseFieldPaths != null && (this._additionalModelResponseFieldPaths.Count > 0 || !AWSConfigs.InitializeCollections);
}

/// <summary>
/// Gets and sets the property GuardrailConfig.
/// <para>
/// Configuration information for a guardrail that you want to use in the request.
/// </para>
/// </summary>
public GuardrailConfiguration GuardrailConfig
{
get { return this._guardrailConfig; }
set { this._guardrailConfig = value; }
}

// Check to see if GuardrailConfig property is set
internal bool IsSetGuardrailConfig()
{
return this._guardrailConfig != null;
}

/// <summary>
/// Gets and sets the property InferenceConfig.
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public partial class ConverseResponse : AmazonWebServiceResponse
private ConverseMetrics _metrics;
private ConverseOutput _output;
private StopReason _stopReason;
private ConverseTrace _trace;
private TokenUsage _usage;

/// <summary>
Expand Down Expand Up @@ -115,6 +116,24 @@ internal bool IsSetStopReason()
return this._stopReason != null;
}

/// <summary>
/// Gets and sets the property Trace.
/// <para>
/// A trace object that contains information about the Guardrail behavior.
/// </para>
/// </summary>
public ConverseTrace Trace
{
get { return this._trace; }
set { this._trace = value; }
}

// Check to see if Trace property is set
internal bool IsSetTrace()
{
return this._trace != null;
}

/// <summary>
/// Gets and sets the property Usage.
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public partial class ConverseStreamMetadataEvent
: IEventStreamEvent
{
private ConverseStreamMetrics _metrics;
private ConverseStreamTrace _trace;
private TokenUsage _usage;

/// <summary>
Expand All @@ -61,6 +62,25 @@ internal bool IsSetMetrics()
return this._metrics != null;
}

/// <summary>
/// Gets and sets the property Trace.
/// <para>
/// The trace object in the response from <a>ConverseStream</a> that contains information
/// about the guardrail behavior.
/// </para>
/// </summary>
public ConverseStreamTrace Trace
{
get { return this._trace; }
set { this._trace = value; }
}

// Check to see if Trace property is set
internal bool IsSetTrace()
{
return this._trace != null;
}

/// <summary>
/// Gets and sets the property Usage.
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace Amazon.BedrockRuntime.Model
/// stream. <c>ConverseStream</c> provides a consistent API that works with all Amazon
/// Bedrock models that support messages. This allows you to write code once and use it
/// with different models. Should a model have unique inference parameters, you can also
/// pass those unique parameters to the model. 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.
/// pass those unique parameters to the model.
///
///
/// <para>
Expand All @@ -45,8 +44,15 @@ namespace Amazon.BedrockRuntime.Model
/// </para>
///
/// <para>
/// For example code, see <i>Invoke model with streaming code example</i> in the <i>Amazon
/// Bedrock User Guide</i>.
/// For information about the Converse API, see <i>Use the Converse API</i> in the <i>Amazon
/// Bedrock User Guide</i>. To use a guardrail, see <i>Use a guardrail with the Converse
/// API</i> in the <i>Amazon Bedrock User Guide</i>. To use a tool with a model, see <i>Tool
/// use (Function calling)</i> in the <i>Amazon Bedrock User Guide</i>
/// </para>
///
/// <para>
/// For example code, see <i>Conversation streaming example</i> in the <i>Amazon Bedrock
/// User Guide</i>.
/// </para>
///
/// <para>
Expand All @@ -58,6 +64,7 @@ public partial class ConverseStreamRequest : AmazonBedrockRuntimeRequest
{
private Amazon.Runtime.Documents.Document _additionalModelRequestFields;
private List<string> _additionalModelResponseFieldPaths = AWSConfigs.InitializeCollections ? new List<string>() : null;
private GuardrailStreamConfiguration _guardrailConfig;
private InferenceConfiguration _inferenceConfig;
private List<Message> _messages = AWSConfigs.InitializeCollections ? new List<Message>() : null;
private string _modelId;
Expand Down Expand Up @@ -87,7 +94,7 @@ internal bool IsSetAdditionalModelRequestFields()
/// Gets and sets the property AdditionalModelResponseFieldPaths.
/// <para>
/// Additional model parameters field paths to return in the response. <c>ConverseStream</c>
/// returns the requested fields as a JSON Pointer object in the <c>additionalModelResultFields</c>
/// returns the requested fields as a JSON Pointer object in the <c>additionalModelResponseFields</c>
/// field. The following is example JSON for <c>additionalModelResponseFieldPaths</c>.
/// </para>
///
Expand Down Expand Up @@ -119,6 +126,24 @@ internal bool IsSetAdditionalModelResponseFieldPaths()
return this._additionalModelResponseFieldPaths != null && (this._additionalModelResponseFieldPaths.Count > 0 || !AWSConfigs.InitializeCollections);
}

/// <summary>
/// Gets and sets the property GuardrailConfig.
/// <para>
/// Configuration information for a guardrail that you want to use in the request.
/// </para>
/// </summary>
public GuardrailStreamConfiguration GuardrailConfig
{
get { return this._guardrailConfig; }
set { this._guardrailConfig = value; }
}

// Check to see if GuardrailConfig property is set
internal bool IsSetGuardrailConfig()
{
return this._guardrailConfig != null;
}

/// <summary>
/// Gets and sets the property InferenceConfig.
/// <para>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/*
* Do not modify this file. This file is generated from the bedrock-runtime-2023-09-30.normal.json service model.
*/
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;
using System.IO;
using System.Net;

using Amazon.Runtime;
using Amazon.Runtime.Internal;

#pragma warning disable CS0612,CS0618,CS1570
namespace Amazon.BedrockRuntime.Model
{
/// <summary>
/// The trace object in a response from <a>ConverseStream</a>. Currently, you can only
/// trace guardrails.
/// </summary>
public partial class ConverseStreamTrace
{
private GuardrailTraceAssessment _guardrail;

/// <summary>
/// Gets and sets the property Guardrail.
/// <para>
/// The guardrail trace object.
/// </para>
/// </summary>
public GuardrailTraceAssessment Guardrail
{
get { return this._guardrail; }
set { this._guardrail = value; }
}

// Check to see if Guardrail property is set
internal bool IsSetGuardrail()
{
return this._guardrail != null;
}

}
}
Loading

0 comments on commit a37aeb4

Please sign in to comment.