diff --git a/clients/client-bedrock-agent-runtime/README.md b/clients/client-bedrock-agent-runtime/README.md index c4801643a64ee..9f7b14c3ef7e4 100644 --- a/clients/client-bedrock-agent-runtime/README.md +++ b/clients/client-bedrock-agent-runtime/README.md @@ -234,6 +234,14 @@ InvokeFlow [Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-agent-runtime/command/InvokeFlowCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-agent-runtime/Interface/InvokeFlowCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-agent-runtime/Interface/InvokeFlowCommandOutput/) + +
+ +OptimizePrompt + + +[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-agent-runtime/command/OptimizePromptCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-agent-runtime/Interface/OptimizePromptCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-agent-runtime/Interface/OptimizePromptCommandOutput/) +
diff --git a/clients/client-bedrock-agent-runtime/src/BedrockAgentRuntime.ts b/clients/client-bedrock-agent-runtime/src/BedrockAgentRuntime.ts index cc762f8bf4cfa..c4738c6a25343 100644 --- a/clients/client-bedrock-agent-runtime/src/BedrockAgentRuntime.ts +++ b/clients/client-bedrock-agent-runtime/src/BedrockAgentRuntime.ts @@ -15,6 +15,11 @@ import { } from "./commands/GetAgentMemoryCommand"; import { InvokeAgentCommand, InvokeAgentCommandInput, InvokeAgentCommandOutput } from "./commands/InvokeAgentCommand"; import { InvokeFlowCommand, InvokeFlowCommandInput, InvokeFlowCommandOutput } from "./commands/InvokeFlowCommand"; +import { + OptimizePromptCommand, + OptimizePromptCommandInput, + OptimizePromptCommandOutput, +} from "./commands/OptimizePromptCommand"; import { RetrieveAndGenerateCommand, RetrieveAndGenerateCommandInput, @@ -27,6 +32,7 @@ const commands = { GetAgentMemoryCommand, InvokeAgentCommand, InvokeFlowCommand, + OptimizePromptCommand, RetrieveCommand, RetrieveAndGenerateCommand, }; @@ -85,6 +91,20 @@ export interface BedrockAgentRuntime { cb: (err: any, data?: InvokeFlowCommandOutput) => void ): void; + /** + * @see {@link OptimizePromptCommand} + */ + optimizePrompt( + args: OptimizePromptCommandInput, + options?: __HttpHandlerOptions + ): Promise; + optimizePrompt(args: OptimizePromptCommandInput, cb: (err: any, data?: OptimizePromptCommandOutput) => void): void; + optimizePrompt( + args: OptimizePromptCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: OptimizePromptCommandOutput) => void + ): void; + /** * @see {@link RetrieveCommand} */ diff --git a/clients/client-bedrock-agent-runtime/src/BedrockAgentRuntimeClient.ts b/clients/client-bedrock-agent-runtime/src/BedrockAgentRuntimeClient.ts index da205ecbcaa2e..154e98389b4c2 100644 --- a/clients/client-bedrock-agent-runtime/src/BedrockAgentRuntimeClient.ts +++ b/clients/client-bedrock-agent-runtime/src/BedrockAgentRuntimeClient.ts @@ -63,6 +63,7 @@ import { DeleteAgentMemoryCommandInput, DeleteAgentMemoryCommandOutput } from ". import { GetAgentMemoryCommandInput, GetAgentMemoryCommandOutput } from "./commands/GetAgentMemoryCommand"; import { InvokeAgentCommandInput, InvokeAgentCommandOutput } from "./commands/InvokeAgentCommand"; import { InvokeFlowCommandInput, InvokeFlowCommandOutput } from "./commands/InvokeFlowCommand"; +import { OptimizePromptCommandInput, OptimizePromptCommandOutput } from "./commands/OptimizePromptCommand"; import { RetrieveAndGenerateCommandInput, RetrieveAndGenerateCommandOutput, @@ -87,6 +88,7 @@ export type ServiceInputTypes = | GetAgentMemoryCommandInput | InvokeAgentCommandInput | InvokeFlowCommandInput + | OptimizePromptCommandInput | RetrieveAndGenerateCommandInput | RetrieveCommandInput; @@ -98,6 +100,7 @@ export type ServiceOutputTypes = | GetAgentMemoryCommandOutput | InvokeAgentCommandOutput | InvokeFlowCommandOutput + | OptimizePromptCommandOutput | RetrieveAndGenerateCommandOutput | RetrieveCommandOutput; diff --git a/clients/client-bedrock-agent-runtime/src/commands/InvokeFlowCommand.ts b/clients/client-bedrock-agent-runtime/src/commands/InvokeFlowCommand.ts index ba8fabc478710..899a1755b8876 100644 --- a/clients/client-bedrock-agent-runtime/src/commands/InvokeFlowCommand.ts +++ b/clients/client-bedrock-agent-runtime/src/commands/InvokeFlowCommand.ts @@ -37,7 +37,7 @@ export interface InvokeFlowCommandInput extends InvokeFlowRequest {} export interface InvokeFlowCommandOutput extends InvokeFlowResponse, __MetadataBearer {} /** - *

Invokes an alias of a flow to run the inputs that you specify and return the output of each node as a stream. If there's an error, the error is returned. For more information, see Test a flow in Amazon Bedrock in the Amazon Bedrock User Guide.

+ *

Invokes an alias of a flow to run the inputs that you specify and return the output of each node as a stream. If there's an error, the error is returned. For more information, see Test a flow in Amazon Bedrock in the Amazon Bedrock User Guide.

* *

The CLI doesn't support streaming operations in Amazon Bedrock, including InvokeFlow.

*
diff --git a/clients/client-bedrock-agent-runtime/src/commands/OptimizePromptCommand.ts b/clients/client-bedrock-agent-runtime/src/commands/OptimizePromptCommand.ts new file mode 100644 index 0000000000000..2f1a7567aa4d1 --- /dev/null +++ b/clients/client-bedrock-agent-runtime/src/commands/OptimizePromptCommand.ts @@ -0,0 +1,162 @@ +// smithy-typescript generated code +import { getEndpointPlugin } from "@smithy/middleware-endpoint"; +import { getSerdePlugin } from "@smithy/middleware-serde"; +import { Command as $Command } from "@smithy/smithy-client"; +import { MetadataBearer as __MetadataBearer } from "@smithy/types"; + +import { + BedrockAgentRuntimeClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes, +} from "../BedrockAgentRuntimeClient"; +import { commonParams } from "../endpoint/EndpointParameters"; +import { + OptimizePromptRequest, + OptimizePromptRequestFilterSensitiveLog, + OptimizePromptResponse, + OptimizePromptResponseFilterSensitiveLog, +} from "../models/models_0"; +import { de_OptimizePromptCommand, se_OptimizePromptCommand } from "../protocols/Aws_restJson1"; + +/** + * @public + */ +export type { __MetadataBearer }; +export { $Command }; +/** + * @public + * + * The input for {@link OptimizePromptCommand}. + */ +export interface OptimizePromptCommandInput extends OptimizePromptRequest {} +/** + * @public + * + * The output of {@link OptimizePromptCommand}. + */ +export interface OptimizePromptCommandOutput extends OptimizePromptResponse, __MetadataBearer {} + +/** + *

Optimizes a prompt for the task that you specify. For more information, see Optimize a prompt in the Amazon Bedrock User Guide.

+ * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { BedrockAgentRuntimeClient, OptimizePromptCommand } from "@aws-sdk/client-bedrock-agent-runtime"; // ES Modules import + * // const { BedrockAgentRuntimeClient, OptimizePromptCommand } = require("@aws-sdk/client-bedrock-agent-runtime"); // CommonJS import + * const client = new BedrockAgentRuntimeClient(config); + * const input = { // OptimizePromptRequest + * input: { // InputPrompt Union: only one key present + * textPrompt: { // TextPrompt + * text: "STRING_VALUE", // required + * }, + * }, + * targetModelId: "STRING_VALUE", // required + * }; + * const command = new OptimizePromptCommand(input); + * const response = await client.send(command); + * // { // OptimizePromptResponse + * // optimizedPrompt: { // OptimizedPromptStream Union: only one key present + * // optimizedPromptEvent: { // OptimizedPromptEvent + * // optimizedPrompt: { // OptimizedPrompt Union: only one key present + * // textPrompt: { // TextPrompt + * // text: "STRING_VALUE", // required + * // }, + * // }, + * // }, + * // analyzePromptEvent: { // AnalyzePromptEvent + * // message: "STRING_VALUE", + * // }, + * // internalServerException: { // InternalServerException + * // message: "STRING_VALUE", + * // }, + * // throttlingException: { // ThrottlingException + * // message: "STRING_VALUE", + * // }, + * // validationException: { // ValidationException + * // message: "STRING_VALUE", + * // }, + * // dependencyFailedException: { // DependencyFailedException + * // message: "STRING_VALUE", + * // resourceName: "STRING_VALUE", + * // }, + * // accessDeniedException: { // AccessDeniedException + * // message: "STRING_VALUE", + * // }, + * // badGatewayException: { // BadGatewayException + * // message: "STRING_VALUE", + * // resourceName: "STRING_VALUE", + * // }, + * // }, + * // }; + * + * ``` + * + * @param OptimizePromptCommandInput - {@link OptimizePromptCommandInput} + * @returns {@link OptimizePromptCommandOutput} + * @see {@link OptimizePromptCommandInput} for command's `input` shape. + * @see {@link OptimizePromptCommandOutput} for command's `response` shape. + * @see {@link BedrockAgentRuntimeClientResolvedConfig | config} for BedrockAgentRuntimeClient's `config` shape. + * + * @throws {@link AccessDeniedException} (client fault) + *

The request is denied because of missing access permissions. Check your permissions and retry your request.

+ * + * @throws {@link BadGatewayException} (server fault) + *

There was an issue with a dependency due to a server issue. Retry your request.

+ * + * @throws {@link DependencyFailedException} (client fault) + *

There was an issue with a dependency. Check the resource configurations and retry the request.

+ * + * @throws {@link InternalServerException} (server fault) + *

An internal server error occurred. Retry your request.

+ * + * @throws {@link ThrottlingException} (client fault) + *

The number of requests exceeds the limit. Resubmit your request later.

+ * + * @throws {@link ValidationException} (client fault) + *

Input validation failed. Check your request parameters and retry the request.

+ * + * @throws {@link BedrockAgentRuntimeServiceException} + *

Base exception class for all service exceptions from BedrockAgentRuntime service.

+ * + * @public + */ +export class OptimizePromptCommand extends $Command + .classBuilder< + OptimizePromptCommandInput, + OptimizePromptCommandOutput, + BedrockAgentRuntimeClientResolvedConfig, + ServiceInputTypes, + ServiceOutputTypes + >() + .ep(commonParams) + .m(function (this: any, Command: any, cs: any, config: BedrockAgentRuntimeClientResolvedConfig, o: any) { + return [ + getSerdePlugin(config, this.serialize, this.deserialize), + getEndpointPlugin(config, Command.getEndpointParameterInstructions()), + ]; + }) + .s("AmazonBedrockAgentRunTimeService", "OptimizePrompt", { + /** + * @internal + */ + eventStream: { + output: true, + }, + }) + .n("BedrockAgentRuntimeClient", "OptimizePromptCommand") + .f(OptimizePromptRequestFilterSensitiveLog, OptimizePromptResponseFilterSensitiveLog) + .ser(se_OptimizePromptCommand) + .de(de_OptimizePromptCommand) + .build() { + /** @internal type navigation helper, not in runtime. */ + protected declare static __types: { + api: { + input: OptimizePromptRequest; + output: OptimizePromptResponse; + }; + sdk: { + input: OptimizePromptCommandInput; + output: OptimizePromptCommandOutput; + }; + }; +} diff --git a/clients/client-bedrock-agent-runtime/src/commands/index.ts b/clients/client-bedrock-agent-runtime/src/commands/index.ts index 58f87c23227c4..50b2d4137bcf6 100644 --- a/clients/client-bedrock-agent-runtime/src/commands/index.ts +++ b/clients/client-bedrock-agent-runtime/src/commands/index.ts @@ -3,5 +3,6 @@ export * from "./DeleteAgentMemoryCommand"; export * from "./GetAgentMemoryCommand"; export * from "./InvokeAgentCommand"; export * from "./InvokeFlowCommand"; +export * from "./OptimizePromptCommand"; export * from "./RetrieveAndGenerateCommand"; export * from "./RetrieveCommand"; diff --git a/clients/client-bedrock-agent-runtime/src/models/models_0.ts b/clients/client-bedrock-agent-runtime/src/models/models_0.ts index bdd8aaf4d0973..b173075c1c197 100644 --- a/clients/client-bedrock-agent-runtime/src/models/models_0.ts +++ b/clients/client-bedrock-agent-runtime/src/models/models_0.ts @@ -76,7 +76,7 @@ export interface RequestBody { } /** - *

Contains information about the action group being invoked. For more information about the possible structures, see the InvocationInput tab in OrchestrationTrace in the Amazon Bedrock User Guide.

+ *

Contains information about the action group being invoked. For more information about the possible structures, see the InvocationInput tab in OrchestrationTrace in the Amazon Bedrock User Guide.

* @public */ export interface ActionGroupInvocationInput { @@ -4143,6 +4143,335 @@ export interface GetAgentMemoryResponse { memoryContents?: Memory[] | undefined; } +/** + *

Contains information about the text prompt to optimize.

+ * @public + */ +export interface TextPrompt { + /** + *

The text in the text prompt to optimize.

+ * @public + */ + text: string | undefined; +} + +/** + *

Contains information about the prompt to optimize.

+ * @public + */ +export type InputPrompt = InputPrompt.TextPromptMember | InputPrompt.$UnknownMember; + +/** + * @public + */ +export namespace InputPrompt { + /** + *

Contains information about the text prompt to optimize.

+ * @public + */ + export interface TextPromptMember { + textPrompt: TextPrompt; + $unknown?: never; + } + + /** + * @public + */ + export interface $UnknownMember { + textPrompt?: never; + $unknown: [string, any]; + } + + export interface Visitor { + textPrompt: (value: TextPrompt) => T; + _: (name: string, value: any) => T; + } + + export const visit = (value: InputPrompt, visitor: Visitor): T => { + if (value.textPrompt !== undefined) return visitor.textPrompt(value.textPrompt); + return visitor._(value.$unknown[0], value.$unknown[1]); + }; +} + +/** + * @public + */ +export interface OptimizePromptRequest { + /** + *

Contains the prompt to optimize.

+ * @public + */ + input: InputPrompt | undefined; + + /** + *

The unique identifier of the model that you want to optimize the prompt for.

+ * @public + */ + targetModelId: string | undefined; +} + +/** + *

An event in which the prompt was analyzed in preparation for optimization.

+ * @public + */ +export interface AnalyzePromptEvent { + /** + *

A message describing the analysis of the prompt.

+ * @public + */ + message?: string | undefined; +} + +/** + *

Contains information about the optimized prompt.

+ * @public + */ +export type OptimizedPrompt = OptimizedPrompt.TextPromptMember | OptimizedPrompt.$UnknownMember; + +/** + * @public + */ +export namespace OptimizedPrompt { + /** + *

Contains information about the text in the prompt that was optimized.

+ * @public + */ + export interface TextPromptMember { + textPrompt: TextPrompt; + $unknown?: never; + } + + /** + * @public + */ + export interface $UnknownMember { + textPrompt?: never; + $unknown: [string, any]; + } + + export interface Visitor { + textPrompt: (value: TextPrompt) => T; + _: (name: string, value: any) => T; + } + + export const visit = (value: OptimizedPrompt, visitor: Visitor): T => { + if (value.textPrompt !== undefined) return visitor.textPrompt(value.textPrompt); + return visitor._(value.$unknown[0], value.$unknown[1]); + }; +} + +/** + *

An event in which the prompt was optimized.

+ * @public + */ +export interface OptimizedPromptEvent { + /** + *

Contains information about the optimized prompt.

+ * @public + */ + optimizedPrompt?: OptimizedPrompt | undefined; +} + +/** + *

The stream containing events in the prompt optimization process.

+ * @public + */ +export type OptimizedPromptStream = + | OptimizedPromptStream.AccessDeniedExceptionMember + | OptimizedPromptStream.AnalyzePromptEventMember + | OptimizedPromptStream.BadGatewayExceptionMember + | OptimizedPromptStream.DependencyFailedExceptionMember + | OptimizedPromptStream.InternalServerExceptionMember + | OptimizedPromptStream.OptimizedPromptEventMember + | OptimizedPromptStream.ThrottlingExceptionMember + | OptimizedPromptStream.ValidationExceptionMember + | OptimizedPromptStream.$UnknownMember; + +/** + * @public + */ +export namespace OptimizedPromptStream { + /** + *

An event in which the prompt was optimized.

+ * @public + */ + export interface OptimizedPromptEventMember { + optimizedPromptEvent: OptimizedPromptEvent; + analyzePromptEvent?: never; + internalServerException?: never; + throttlingException?: never; + validationException?: never; + dependencyFailedException?: never; + accessDeniedException?: never; + badGatewayException?: never; + $unknown?: never; + } + + /** + *

An event in which the prompt was analyzed in preparation for optimization.

+ * @public + */ + export interface AnalyzePromptEventMember { + optimizedPromptEvent?: never; + analyzePromptEvent: AnalyzePromptEvent; + internalServerException?: never; + throttlingException?: never; + validationException?: never; + dependencyFailedException?: never; + accessDeniedException?: never; + badGatewayException?: never; + $unknown?: never; + } + + /** + *

An internal server error occurred. Retry your request.

+ * @public + */ + export interface InternalServerExceptionMember { + optimizedPromptEvent?: never; + analyzePromptEvent?: never; + internalServerException: InternalServerException; + throttlingException?: never; + validationException?: never; + dependencyFailedException?: never; + accessDeniedException?: never; + badGatewayException?: never; + $unknown?: never; + } + + /** + *

Your request was throttled because of service-wide limitations. Resubmit your request later or in a different region. You can also purchase Provisioned Throughput to increase the rate or number of tokens you can process.

+ * @public + */ + export interface ThrottlingExceptionMember { + optimizedPromptEvent?: never; + analyzePromptEvent?: never; + internalServerException?: never; + throttlingException: ThrottlingException; + validationException?: never; + dependencyFailedException?: never; + accessDeniedException?: never; + badGatewayException?: never; + $unknown?: never; + } + + /** + *

Input validation failed. Check your request parameters and retry the request.

+ * @public + */ + export interface ValidationExceptionMember { + optimizedPromptEvent?: never; + analyzePromptEvent?: never; + internalServerException?: never; + throttlingException?: never; + validationException: ValidationException; + dependencyFailedException?: never; + accessDeniedException?: never; + badGatewayException?: never; + $unknown?: never; + } + + /** + *

There was an issue with a dependency. Check the resource configurations and retry the request.

+ * @public + */ + export interface DependencyFailedExceptionMember { + optimizedPromptEvent?: never; + analyzePromptEvent?: never; + internalServerException?: never; + throttlingException?: never; + validationException?: never; + dependencyFailedException: DependencyFailedException; + accessDeniedException?: never; + badGatewayException?: never; + $unknown?: never; + } + + /** + *

The request is denied because of missing access permissions. Check your permissions and retry your request.

+ * @public + */ + export interface AccessDeniedExceptionMember { + optimizedPromptEvent?: never; + analyzePromptEvent?: never; + internalServerException?: never; + throttlingException?: never; + validationException?: never; + dependencyFailedException?: never; + accessDeniedException: AccessDeniedException; + badGatewayException?: never; + $unknown?: never; + } + + /** + *

There was an issue with a dependency due to a server issue. Retry your request.

+ * @public + */ + export interface BadGatewayExceptionMember { + optimizedPromptEvent?: never; + analyzePromptEvent?: never; + internalServerException?: never; + throttlingException?: never; + validationException?: never; + dependencyFailedException?: never; + accessDeniedException?: never; + badGatewayException: BadGatewayException; + $unknown?: never; + } + + /** + * @public + */ + export interface $UnknownMember { + optimizedPromptEvent?: never; + analyzePromptEvent?: never; + internalServerException?: never; + throttlingException?: never; + validationException?: never; + dependencyFailedException?: never; + accessDeniedException?: never; + badGatewayException?: never; + $unknown: [string, any]; + } + + export interface Visitor { + optimizedPromptEvent: (value: OptimizedPromptEvent) => T; + analyzePromptEvent: (value: AnalyzePromptEvent) => T; + internalServerException: (value: InternalServerException) => T; + throttlingException: (value: ThrottlingException) => T; + validationException: (value: ValidationException) => T; + dependencyFailedException: (value: DependencyFailedException) => T; + accessDeniedException: (value: AccessDeniedException) => T; + badGatewayException: (value: BadGatewayException) => T; + _: (name: string, value: any) => T; + } + + export const visit = (value: OptimizedPromptStream, visitor: Visitor): T => { + if (value.optimizedPromptEvent !== undefined) return visitor.optimizedPromptEvent(value.optimizedPromptEvent); + if (value.analyzePromptEvent !== undefined) return visitor.analyzePromptEvent(value.analyzePromptEvent); + if (value.internalServerException !== undefined) + return visitor.internalServerException(value.internalServerException); + if (value.throttlingException !== undefined) return visitor.throttlingException(value.throttlingException); + if (value.validationException !== undefined) return visitor.validationException(value.validationException); + if (value.dependencyFailedException !== undefined) + return visitor.dependencyFailedException(value.dependencyFailedException); + if (value.accessDeniedException !== undefined) return visitor.accessDeniedException(value.accessDeniedException); + if (value.badGatewayException !== undefined) return visitor.badGatewayException(value.badGatewayException); + return visitor._(value.$unknown[0], value.$unknown[1]); + }; +} + +/** + * @public + */ +export interface OptimizePromptResponse { + /** + *

The prompt after being optimized for the task.

+ * @public + */ + optimizedPrompt: AsyncIterable | undefined; +} + /** *

Contains the query made to the knowledge base.

*

This data type is used in the following API operations:

@@ -6038,6 +6367,75 @@ export const InvokeAgentResponseFilterSensitiveLog = (obj: InvokeAgentResponse): ...(obj.completion && { completion: "STREAMING_CONTENT" }), }); +/** + * @internal + */ +export const TextPromptFilterSensitiveLog = (obj: TextPrompt): any => ({ + ...obj, +}); + +/** + * @internal + */ +export const InputPromptFilterSensitiveLog = (obj: InputPrompt): any => { + if (obj.textPrompt !== undefined) return { textPrompt: SENSITIVE_STRING }; + if (obj.$unknown !== undefined) return { [obj.$unknown[0]]: "UNKNOWN" }; +}; + +/** + * @internal + */ +export const OptimizePromptRequestFilterSensitiveLog = (obj: OptimizePromptRequest): any => ({ + ...obj, + ...(obj.input && { input: InputPromptFilterSensitiveLog(obj.input) }), +}); + +/** + * @internal + */ +export const AnalyzePromptEventFilterSensitiveLog = (obj: AnalyzePromptEvent): any => ({ + ...obj, +}); + +/** + * @internal + */ +export const OptimizedPromptFilterSensitiveLog = (obj: OptimizedPrompt): any => { + if (obj.textPrompt !== undefined) return { textPrompt: SENSITIVE_STRING }; + if (obj.$unknown !== undefined) return { [obj.$unknown[0]]: "UNKNOWN" }; +}; + +/** + * @internal + */ +export const OptimizedPromptEventFilterSensitiveLog = (obj: OptimizedPromptEvent): any => ({ + ...obj, + ...(obj.optimizedPrompt && { optimizedPrompt: OptimizedPromptFilterSensitiveLog(obj.optimizedPrompt) }), +}); + +/** + * @internal + */ +export const OptimizedPromptStreamFilterSensitiveLog = (obj: OptimizedPromptStream): any => { + if (obj.optimizedPromptEvent !== undefined) return { optimizedPromptEvent: SENSITIVE_STRING }; + if (obj.analyzePromptEvent !== undefined) return { analyzePromptEvent: SENSITIVE_STRING }; + if (obj.internalServerException !== undefined) return { internalServerException: obj.internalServerException }; + if (obj.throttlingException !== undefined) return { throttlingException: obj.throttlingException }; + if (obj.validationException !== undefined) return { validationException: obj.validationException }; + if (obj.dependencyFailedException !== undefined) return { dependencyFailedException: obj.dependencyFailedException }; + if (obj.accessDeniedException !== undefined) return { accessDeniedException: obj.accessDeniedException }; + if (obj.badGatewayException !== undefined) return { badGatewayException: obj.badGatewayException }; + if (obj.$unknown !== undefined) return { [obj.$unknown[0]]: "UNKNOWN" }; +}; + +/** + * @internal + */ +export const OptimizePromptResponseFilterSensitiveLog = (obj: OptimizePromptResponse): any => ({ + ...obj, + ...(obj.optimizedPrompt && { optimizedPrompt: "STREAMING_CONTENT" }), +}); + /** * @internal */ diff --git a/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts b/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts index 2b9bb25e50b09..9f613591dc484 100644 --- a/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts @@ -37,6 +37,7 @@ import { DeleteAgentMemoryCommandInput, DeleteAgentMemoryCommandOutput } from ". import { GetAgentMemoryCommandInput, GetAgentMemoryCommandOutput } from "../commands/GetAgentMemoryCommand"; import { InvokeAgentCommandInput, InvokeAgentCommandOutput } from "../commands/InvokeAgentCommand"; import { InvokeFlowCommandInput, InvokeFlowCommandOutput } from "../commands/InvokeFlowCommand"; +import { OptimizePromptCommandInput, OptimizePromptCommandOutput } from "../commands/OptimizePromptCommand"; import { RetrieveAndGenerateCommandInput, RetrieveAndGenerateCommandOutput, @@ -45,6 +46,7 @@ import { RetrieveCommandInput, RetrieveCommandOutput } from "../commands/Retriev import { BedrockAgentRuntimeServiceException as __BaseException } from "../models/BedrockAgentRuntimeServiceException"; import { AccessDeniedException, + AnalyzePromptEvent, ApiResult, Attribution, BadGatewayException, @@ -81,6 +83,7 @@ import { InferenceConfig, InferenceConfiguration, InputFile, + InputPrompt, InternalServerException, InvocationResultMember, KnowledgeBaseConfiguration, @@ -94,6 +97,8 @@ import { MemorySessionSummary, ModelInvocationInput, Observation, + OptimizedPromptEvent, + OptimizedPromptStream, OrchestrationConfiguration, OrchestrationTrace, OutputFile, @@ -115,6 +120,7 @@ import { ServiceQuotaExceededException, SessionState, TextInferenceConfig, + TextPrompt, ThrottlingException, Trace, TracePart, @@ -218,6 +224,29 @@ export const se_InvokeFlowCommand = async ( return b.build(); }; +/** + * serializeAws_restJson1OptimizePromptCommand + */ +export const se_OptimizePromptCommand = async ( + input: OptimizePromptCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const b = rb(input, context); + const headers: any = { + "content-type": "application/json", + }; + b.bp("/optimize-prompt"); + let body: any; + body = JSON.stringify( + take(input, { + input: (_) => _json(_), + targetModelId: [], + }) + ); + b.m("POST").h(headers).b(body); + return b.build(); +}; + /** * serializeAws_restJson1RetrieveCommand */ @@ -346,6 +375,24 @@ export const de_InvokeFlowCommand = async ( return contents; }; +/** + * deserializeAws_restJson1OptimizePromptCommand + */ +export const de_OptimizePromptCommand = async ( + output: __HttpResponse, + context: __SerdeContext & __EventStreamSerdeContext +): Promise => { + if (output.statusCode !== 200 && output.statusCode >= 300) { + return de_CommandError(output, context); + } + const contents: any = map({ + $metadata: deserializeMetadata(output), + }); + const data: any = output.body; + contents.optimizedPrompt = de_OptimizedPromptStream(data, context); + return contents; +}; + /** * deserializeAws_restJson1RetrieveCommand */ @@ -690,6 +737,60 @@ const de_FlowResponseStream = ( return { $unknown: output }; }); }; +/** + * deserializeAws_restJson1OptimizedPromptStream + */ +const de_OptimizedPromptStream = ( + output: any, + context: __SerdeContext & __EventStreamSerdeContext +): AsyncIterable => { + return context.eventStreamMarshaller.deserialize(output, async (event) => { + if (event["optimizedPromptEvent"] != null) { + return { + optimizedPromptEvent: await de_OptimizedPromptEvent_event(event["optimizedPromptEvent"], context), + }; + } + if (event["analyzePromptEvent"] != null) { + return { + analyzePromptEvent: await de_AnalyzePromptEvent_event(event["analyzePromptEvent"], context), + }; + } + if (event["internalServerException"] != null) { + return { + internalServerException: await de_InternalServerException_event(event["internalServerException"], context), + }; + } + if (event["throttlingException"] != null) { + return { + throttlingException: await de_ThrottlingException_event(event["throttlingException"], context), + }; + } + if (event["validationException"] != null) { + return { + validationException: await de_ValidationException_event(event["validationException"], context), + }; + } + if (event["dependencyFailedException"] != null) { + return { + dependencyFailedException: await de_DependencyFailedException_event( + event["dependencyFailedException"], + context + ), + }; + } + if (event["accessDeniedException"] != null) { + return { + accessDeniedException: await de_AccessDeniedException_event(event["accessDeniedException"], context), + }; + } + if (event["badGatewayException"] != null) { + return { + badGatewayException: await de_BadGatewayException_event(event["badGatewayException"], context), + }; + } + return { $unknown: output }; + }); +}; /** * deserializeAws_restJson1ResponseStream */ @@ -782,6 +883,12 @@ const de_AccessDeniedException_event = async (output: any, context: __SerdeConte }; return de_AccessDeniedExceptionRes(parsedOutput, context); }; +const de_AnalyzePromptEvent_event = async (output: any, context: __SerdeContext): Promise => { + const contents: AnalyzePromptEvent = {} as any; + const data: any = await parseBody(output.body, context); + Object.assign(contents, _json(data)); + return contents; +}; const de_BadGatewayException_event = async (output: any, context: __SerdeContext): Promise => { const parsedOutput: any = { ...output, @@ -840,6 +947,12 @@ const de_InternalServerException_event = async ( }; return de_InternalServerExceptionRes(parsedOutput, context); }; +const de_OptimizedPromptEvent_event = async (output: any, context: __SerdeContext): Promise => { + const contents: OptimizedPromptEvent = {} as any; + const data: any = await parseBody(output.body, context); + Object.assign(contents, _json(data)); + return contents; +}; const de_PayloadPart_event = async (output: any, context: __SerdeContext): Promise => { const contents: PayloadPart = {} as any; const data: any = await parseBody(output.body, context); @@ -1095,6 +1208,8 @@ const se_InputFiles = (input: InputFile[], context: __SerdeContext): any => { }); }; +// se_InputPrompt omitted. + // se_InvocationResultMember omitted. /** @@ -1266,6 +1381,8 @@ const se_TextInferenceConfig = (input: TextInferenceConfig, context: __SerdeCont }); }; +// se_TextPrompt omitted. + /** * serializeAws_restJson1Document */ @@ -1277,6 +1394,8 @@ const se_Document = (input: __DocumentType, context: __SerdeContext): any => { // de_ActionGroupInvocationOutput omitted. +// de_AnalyzePromptEvent omitted. + // de_ApiContentMap omitted. // de_ApiInvocationInput omitted. @@ -1672,6 +1791,10 @@ const de_Observation = (output: any, context: __SerdeContext): Observation => { }) as any; }; +// de_OptimizedPrompt omitted. + +// de_OptimizedPromptEvent omitted. + // de_OrchestrationModelInvocationOutput omitted. /** @@ -1862,6 +1985,8 @@ const de_RetrievedReferences = (output: any, context: __SerdeContext): Retrieved // de_StopSequences omitted. +// de_TextPrompt omitted. + // de_TextResponsePart omitted. /** diff --git a/codegen/sdk-codegen/aws-models/bedrock-agent-runtime.json b/codegen/sdk-codegen/aws-models/bedrock-agent-runtime.json index 9450bfcdbe49d..16496cd68447a 100644 --- a/codegen/sdk-codegen/aws-models/bedrock-agent-runtime.json +++ b/codegen/sdk-codegen/aws-models/bedrock-agent-runtime.json @@ -67,7 +67,7 @@ } }, "traits": { - "smithy.api#documentation": "

Contains information about the action group being invoked. For more information about the possible structures, see the InvocationInput tab in OrchestrationTrace in the Amazon Bedrock User Guide.

" + "smithy.api#documentation": "

Contains information about the action group being invoked. For more information about the possible structures, see the InvocationInput tab in OrchestrationTrace in the Amazon Bedrock User Guide.

" } }, "com.amazonaws.bedrockagentruntime#ActionGroupInvocationOutput": { @@ -181,6 +181,9 @@ { "target": "com.amazonaws.bedrockagentruntime#MemoryResource" }, + { + "target": "com.amazonaws.bedrockagentruntime#OptimizePromptResource" + }, { "target": "com.amazonaws.bedrockagentruntime#RetrieveAndGenerateResource" }, @@ -867,6 +870,21 @@ } } }, + "com.amazonaws.bedrockagentruntime#AnalyzePromptEvent": { + "type": "structure", + "members": { + "message": { + "target": "smithy.api#String", + "traits": { + "smithy.api#documentation": "

A message describing the analysis of the prompt.

" + } + } + }, + "traits": { + "smithy.api#documentation": "

An event in which the prompt was analyzed in preparation for optimization.

", + "smithy.api#sensitive": {} + } + }, "com.amazonaws.bedrockagentruntime#ApiContentMap": { "type": "map", "key": { @@ -3336,6 +3354,20 @@ "target": "com.amazonaws.bedrockagentruntime#InputFile" } }, + "com.amazonaws.bedrockagentruntime#InputPrompt": { + "type": "union", + "members": { + "textPrompt": { + "target": "com.amazonaws.bedrockagentruntime#TextPrompt", + "traits": { + "smithy.api#documentation": "

Contains information about the text prompt to optimize.

" + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about the prompt to optimize.

" + } + }, "com.amazonaws.bedrockagentruntime#InputText": { "type": "string", "traits": { @@ -3663,7 +3695,7 @@ } ], "traits": { - "smithy.api#documentation": "

Invokes an alias of a flow to run the inputs that you specify and return the output of each node as a stream. If there's an error, the error is returned. For more information, see Test a flow in Amazon Bedrock in the Amazon Bedrock User Guide.

\n \n

The CLI doesn't support streaming operations in Amazon Bedrock, including InvokeFlow.

\n
", + "smithy.api#documentation": "

Invokes an alias of a flow to run the inputs that you specify and return the output of each node as a stream. If there's an error, the error is returned. For more information, see Test a flow in Amazon Bedrock in the Amazon Bedrock User Guide.

\n \n

The CLI doesn't support streaming operations in Amazon Bedrock, including InvokeFlow.

\n
", "smithy.api#http": { "code": 200, "method": "POST", @@ -4286,6 +4318,180 @@ "smithy.api#sensitive": {} } }, + "com.amazonaws.bedrockagentruntime#OptimizePrompt": { + "type": "operation", + "input": { + "target": "com.amazonaws.bedrockagentruntime#OptimizePromptRequest" + }, + "output": { + "target": "com.amazonaws.bedrockagentruntime#OptimizePromptResponse" + }, + "errors": [ + { + "target": "com.amazonaws.bedrockagentruntime#AccessDeniedException" + }, + { + "target": "com.amazonaws.bedrockagentruntime#BadGatewayException" + }, + { + "target": "com.amazonaws.bedrockagentruntime#DependencyFailedException" + }, + { + "target": "com.amazonaws.bedrockagentruntime#InternalServerException" + }, + { + "target": "com.amazonaws.bedrockagentruntime#ThrottlingException" + }, + { + "target": "com.amazonaws.bedrockagentruntime#ValidationException" + } + ], + "traits": { + "smithy.api#documentation": "

Optimizes a prompt for the task that you specify. For more information, see Optimize a prompt in the Amazon Bedrock User Guide.

", + "smithy.api#http": { + "code": 200, + "method": "POST", + "uri": "/optimize-prompt" + } + } + }, + "com.amazonaws.bedrockagentruntime#OptimizePromptRequest": { + "type": "structure", + "members": { + "input": { + "target": "com.amazonaws.bedrockagentruntime#InputPrompt", + "traits": { + "smithy.api#documentation": "

Contains the prompt to optimize.

", + "smithy.api#required": {} + } + }, + "targetModelId": { + "target": "smithy.api#String", + "traits": { + "smithy.api#documentation": "

The unique identifier of the model that you want to optimize the prompt for.

", + "smithy.api#length": { + "min": 1, + "max": 2048 + }, + "smithy.api#pattern": "^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:(([0-9]{12}:custom-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}/[a-z0-9]{12})|(:foundation-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.:]?[a-z0-9-]{1,63}))|([0-9]{12}:provisioned-model/[a-z0-9]{12})))|([a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.:]?[a-z0-9-]{1,63}))|(([0-9a-zA-Z][_-]?)+)$", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#input": {} + } + }, + "com.amazonaws.bedrockagentruntime#OptimizePromptResource": { + "type": "resource", + "operations": [ + { + "target": "com.amazonaws.bedrockagentruntime#OptimizePrompt" + } + ] + }, + "com.amazonaws.bedrockagentruntime#OptimizePromptResponse": { + "type": "structure", + "members": { + "optimizedPrompt": { + "target": "com.amazonaws.bedrockagentruntime#OptimizedPromptStream", + "traits": { + "smithy.api#documentation": "

The prompt after being optimized for the task.

", + "smithy.api#httpPayload": {}, + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#output": {} + } + }, + "com.amazonaws.bedrockagentruntime#OptimizedPrompt": { + "type": "union", + "members": { + "textPrompt": { + "target": "com.amazonaws.bedrockagentruntime#TextPrompt", + "traits": { + "smithy.api#documentation": "

Contains information about the text in the prompt that was optimized.

" + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about the optimized prompt.

" + } + }, + "com.amazonaws.bedrockagentruntime#OptimizedPromptEvent": { + "type": "structure", + "members": { + "optimizedPrompt": { + "target": "com.amazonaws.bedrockagentruntime#OptimizedPrompt", + "traits": { + "smithy.api#documentation": "

Contains information about the optimized prompt.

" + } + } + }, + "traits": { + "smithy.api#documentation": "

An event in which the prompt was optimized.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#OptimizedPromptStream": { + "type": "union", + "members": { + "optimizedPromptEvent": { + "target": "com.amazonaws.bedrockagentruntime#OptimizedPromptEvent", + "traits": { + "smithy.api#documentation": "

An event in which the prompt was optimized.

" + } + }, + "analyzePromptEvent": { + "target": "com.amazonaws.bedrockagentruntime#AnalyzePromptEvent", + "traits": { + "smithy.api#documentation": "

An event in which the prompt was analyzed in preparation for optimization.

" + } + }, + "internalServerException": { + "target": "com.amazonaws.bedrockagentruntime#InternalServerException", + "traits": { + "smithy.api#documentation": "

An internal server error occurred. Retry your request.

" + } + }, + "throttlingException": { + "target": "com.amazonaws.bedrockagentruntime#ThrottlingException", + "traits": { + "smithy.api#documentation": "

Your request was throttled because of service-wide limitations. Resubmit your request later or in a different region. You can also purchase Provisioned Throughput to increase the rate or number of tokens you can process.

" + } + }, + "validationException": { + "target": "com.amazonaws.bedrockagentruntime#ValidationException", + "traits": { + "smithy.api#documentation": "

Input validation failed. Check your request parameters and retry the request.

" + } + }, + "dependencyFailedException": { + "target": "com.amazonaws.bedrockagentruntime#DependencyFailedException", + "traits": { + "smithy.api#documentation": "

There was an issue with a dependency. Check the resource configurations and retry the request.

" + } + }, + "accessDeniedException": { + "target": "com.amazonaws.bedrockagentruntime#AccessDeniedException", + "traits": { + "smithy.api#documentation": "

The request is denied because of missing access permissions. Check your permissions and retry your request.

" + } + }, + "badGatewayException": { + "target": "com.amazonaws.bedrockagentruntime#BadGatewayException", + "traits": { + "smithy.api#documentation": "

There was an issue with a dependency due to a server issue. Retry your request.

" + } + } + }, + "traits": { + "smithy.api#documentation": "

The stream containing events in the prompt optimization process.

", + "smithy.api#streaming": {} + } + }, "com.amazonaws.bedrockagentruntime#OrchestrationConfiguration": { "type": "structure", "members": { @@ -5895,6 +6101,26 @@ "smithy.api#documentation": "

Configuration settings for text generation using a language model via the\n RetrieveAndGenerate operation. Includes parameters like temperature, top-p, maximum token\n count, and stop sequences.

\n \n

The valid range of maxTokens depends on the accepted values for your chosen\n model's inference parameters. To see the inference parameters for your model, see Inference\n parameters for foundation models.\n

\n
" } }, + "com.amazonaws.bedrockagentruntime#TextPrompt": { + "type": "structure", + "members": { + "text": { + "target": "smithy.api#String", + "traits": { + "smithy.api#documentation": "

The text in the text prompt to optimize.

", + "smithy.api#length": { + "min": 1, + "max": 200000 + }, + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about the text prompt to optimize.

", + "smithy.api#sensitive": {} + } + }, "com.amazonaws.bedrockagentruntime#TextPromptTemplate": { "type": "string", "traits": {