Skip to content

Commit

Permalink
feat(client-bedrock-runtime): Add Prompt management support to Bedroc…
Browse files Browse the repository at this point in the history
…k runtime APIs: Converse, ConverseStream, InvokeModel, InvokeModelWithStreamingResponse
  • Loading branch information
awstools committed Nov 7, 2024
1 parent 3d8d0bb commit 6607253
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 57 deletions.
13 changes: 10 additions & 3 deletions clients/client-bedrock-runtime/src/commands/ConverseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MetadataBearer as __MetadataBearer } from "@smithy/types";

import { BedrockRuntimeClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../BedrockRuntimeClient";
import { commonParams } from "../endpoint/EndpointParameters";
import { ConverseRequest, ConverseResponse } from "../models/models_0";
import { ConverseRequest, ConverseRequestFilterSensitiveLog, ConverseResponse } from "../models/models_0";
import { de_ConverseCommand, se_ConverseCommand } from "../protocols/Aws_restJson1";

/**
Expand Down Expand Up @@ -34,6 +34,8 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
* If a model has unique inference parameters, you can also pass those unique parameters
* to the model.</p>
* <p>Amazon Bedrock doesn't store any text, images, or documents that you provide as content. The data is only used to generate the response.</p>
* <p>You can submit a prompt by including it in the <code>messages</code> field, specifying the <code>modelId</code> of a foundation model or inference profile to run inference on it, and including any other fields that are relevant to your use case.</p>
* <p>You can also submit a prompt from Prompt management by specifying the ARN of the prompt version and including a map of variables to values in the <code>promptVariables</code> field. You can append more messages to the prompt by using the <code>messages</code> field. If you use a prompt from Prompt management, you can't include the following fields in the request: <code>additionalModelRequestFields</code>, <code>inferenceConfig</code>, <code>system</code>, or <code>toolConfig</code>. Instead, these fields must be defined through Prompt management. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-use.html">Use a prompt from Prompt management</a>.</p>
* <p>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>
Expand All @@ -49,7 +51,7 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
* const client = new BedrockRuntimeClient(config);
* const input = { // ConverseRequest
* modelId: "STRING_VALUE", // required
* messages: [ // Messages // required
* messages: [ // Messages
* { // Message
* role: "user" || "assistant", // required
* content: [ // ContentBlocks // required
Expand Down Expand Up @@ -155,6 +157,11 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
* trace: "enabled" || "disabled",
* },
* additionalModelRequestFields: "DOCUMENT_VALUE",
* promptVariables: { // PromptVariableMap
* "<keys>": { // PromptVariableValues Union: only one key present
* text: "STRING_VALUE",
* },
* },
* additionalModelResponseFieldPaths: [ // AdditionalModelResponseFieldPaths
* "STRING_VALUE",
* ],
Expand Down Expand Up @@ -466,7 +473,7 @@ export class ConverseCommand extends $Command
})
.s("AmazonBedrockFrontendService", "Converse", {})
.n("BedrockRuntimeClient", "ConverseCommand")
.f(void 0, void 0)
.f(ConverseRequestFilterSensitiveLog, void 0)
.ser(se_ConverseCommand)
.de(de_ConverseCommand)
.build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BedrockRuntimeClientResolvedConfig, ServiceInputTypes, ServiceOutputTyp
import { commonParams } from "../endpoint/EndpointParameters";
import {
ConverseStreamRequest,
ConverseStreamRequestFilterSensitiveLog,
ConverseStreamResponse,
ConverseStreamResponseFilterSensitiveLog,
} from "../models/models_0";
Expand Down Expand Up @@ -44,6 +45,8 @@ export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __M
* <p>The CLI doesn't support streaming operations in Amazon Bedrock, including <code>ConverseStream</code>.</p>
* </note>
* <p>Amazon Bedrock doesn't store any text, images, or documents that you provide as content. The data is only used to generate the response.</p>
* <p>You can submit a prompt by including it in the <code>messages</code> field, specifying the <code>modelId</code> of a foundation model or inference profile to run inference on it, and including any other fields that are relevant to your use case.</p>
* <p>You can also submit a prompt from Prompt management by specifying the ARN of the prompt version and including a map of variables to values in the <code>promptVariables</code> field. You can append more messages to the prompt by using the <code>messages</code> field. If you use a prompt from Prompt management, you can't include the following fields in the request: <code>additionalModelRequestFields</code>, <code>inferenceConfig</code>, <code>system</code>, or <code>toolConfig</code>. Instead, these fields must be defined through Prompt management. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-use.html">Use a prompt from Prompt management</a>.</p>
* <p>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>
Expand All @@ -59,7 +62,7 @@ export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __M
* const client = new BedrockRuntimeClient(config);
* const input = { // ConverseStreamRequest
* modelId: "STRING_VALUE", // required
* messages: [ // Messages // required
* messages: [ // Messages
* { // Message
* role: "user" || "assistant", // required
* content: [ // ContentBlocks // required
Expand Down Expand Up @@ -166,6 +169,11 @@ export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __M
* streamProcessingMode: "sync" || "async",
* },
* additionalModelRequestFields: "DOCUMENT_VALUE",
* promptVariables: { // PromptVariableMap
* "<keys>": { // PromptVariableValues Union: only one key present
* text: "STRING_VALUE",
* },
* },
* additionalModelResponseFieldPaths: [ // AdditionalModelResponseFieldPaths
* "STRING_VALUE",
* ],
Expand Down Expand Up @@ -472,7 +480,7 @@ export class ConverseStreamCommand extends $Command
},
})
.n("BedrockRuntimeClient", "ConverseStreamCommand")
.f(void 0, ConverseStreamResponseFilterSensitiveLog)
.f(ConverseStreamRequestFilterSensitiveLog, ConverseStreamResponseFilterSensitiveLog)
.ser(se_ConverseStreamCommand)
.de(de_ConverseStreamCommand)
.build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export { $Command };
* @public
*/
export type InvokeModelCommandInputType = Omit<InvokeModelRequest, "body"> & {
body: BlobPayloadInputTypes;
body?: BlobPayloadInputTypes;
};

/**
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface InvokeModelCommandOutput extends InvokeModelCommandOutputType,
* // const { BedrockRuntimeClient, InvokeModelCommand } = require("@aws-sdk/client-bedrock-runtime"); // CommonJS import
* const client = new BedrockRuntimeClient(config);
* const input = { // InvokeModelRequest
* body: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("") // required
* body: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* contentType: "STRING_VALUE",
* accept: "STRING_VALUE",
* modelId: "STRING_VALUE", // required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export { $Command };
* @public
*/
export type InvokeModelWithResponseStreamCommandInputType = Omit<InvokeModelWithResponseStreamRequest, "body"> & {
body: BlobPayloadInputTypes;
body?: BlobPayloadInputTypes;
};

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ export interface InvokeModelWithResponseStreamCommandOutput
* // const { BedrockRuntimeClient, InvokeModelWithResponseStreamCommand } = require("@aws-sdk/client-bedrock-runtime"); // CommonJS import
* const client = new BedrockRuntimeClient(config);
* const input = { // InvokeModelWithResponseStreamRequest
* body: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("") // required
* body: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* contentType: "STRING_VALUE",
* accept: "STRING_VALUE",
* modelId: "STRING_VALUE", // required
Expand Down
Loading

0 comments on commit 6607253

Please sign in to comment.