diff --git a/clients/client-wisdom/src/Wisdom.ts b/clients/client-wisdom/src/Wisdom.ts index 37e2409f42f3..12ab92aeed48 100644 --- a/clients/client-wisdom/src/Wisdom.ts +++ b/clients/client-wisdom/src/Wisdom.ts @@ -103,6 +103,7 @@ import { NotifyRecommendationsReceivedCommandInput, NotifyRecommendationsReceivedCommandOutput, } from "./commands/NotifyRecommendationsReceivedCommand"; +import { PutFeedbackCommand, PutFeedbackCommandInput, PutFeedbackCommandOutput } from "./commands/PutFeedbackCommand"; import { QueryAssistantCommand, QueryAssistantCommandInput, @@ -879,6 +880,36 @@ export class Wisdom extends WisdomClient { } } + /** + *

Submits feedback to Wisdom. The feedback is used to improve future recommendations from + * GetRecommendations or + * results from QueryAssistant. + * Feedback can be resubmitted up to 6 hours after submission. + *

+ */ + public putFeedback(args: PutFeedbackCommandInput, options?: __HttpHandlerOptions): Promise; + public putFeedback(args: PutFeedbackCommandInput, cb: (err: any, data?: PutFeedbackCommandOutput) => void): void; + public putFeedback( + args: PutFeedbackCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: PutFeedbackCommandOutput) => void + ): void; + public putFeedback( + args: PutFeedbackCommandInput, + optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: PutFeedbackCommandOutput) => void), + cb?: (err: any, data?: PutFeedbackCommandOutput) => void + ): Promise | void { + const command = new PutFeedbackCommand(args); + if (typeof optionsOrCb === "function") { + this.send(command, optionsOrCb); + } else if (typeof cb === "function") { + if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`); + this.send(command, optionsOrCb || {}, cb); + } else { + return this.send(command, optionsOrCb); + } + } + /** *

Performs a manual search against the specified assistant. To retrieve recommendations for * an assistant, use GetRecommendations. diff --git a/clients/client-wisdom/src/WisdomClient.ts b/clients/client-wisdom/src/WisdomClient.ts index df3e050e25dc..754ea5cce613 100644 --- a/clients/client-wisdom/src/WisdomClient.ts +++ b/clients/client-wisdom/src/WisdomClient.ts @@ -99,6 +99,7 @@ import { NotifyRecommendationsReceivedCommandInput, NotifyRecommendationsReceivedCommandOutput, } from "./commands/NotifyRecommendationsReceivedCommand"; +import { PutFeedbackCommandInput, PutFeedbackCommandOutput } from "./commands/PutFeedbackCommand"; import { QueryAssistantCommandInput, QueryAssistantCommandOutput } from "./commands/QueryAssistantCommand"; import { RemoveKnowledgeBaseTemplateUriCommandInput, @@ -139,6 +140,7 @@ export type ServiceInputTypes = | ListKnowledgeBasesCommandInput | ListTagsForResourceCommandInput | NotifyRecommendationsReceivedCommandInput + | PutFeedbackCommandInput | QueryAssistantCommandInput | RemoveKnowledgeBaseTemplateUriCommandInput | SearchContentCommandInput @@ -172,6 +174,7 @@ export type ServiceOutputTypes = | ListKnowledgeBasesCommandOutput | ListTagsForResourceCommandOutput | NotifyRecommendationsReceivedCommandOutput + | PutFeedbackCommandOutput | QueryAssistantCommandOutput | RemoveKnowledgeBaseTemplateUriCommandOutput | SearchContentCommandOutput diff --git a/clients/client-wisdom/src/commands/PutFeedbackCommand.ts b/clients/client-wisdom/src/commands/PutFeedbackCommand.ts new file mode 100644 index 000000000000..57068395f56d --- /dev/null +++ b/clients/client-wisdom/src/commands/PutFeedbackCommand.ts @@ -0,0 +1,105 @@ +// smithy-typescript generated code +import { getSerdePlugin } from "@aws-sdk/middleware-serde"; +import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http"; +import { Command as $Command } from "@aws-sdk/smithy-client"; +import { + FinalizeHandlerArguments, + Handler, + HandlerExecutionContext, + HttpHandlerOptions as __HttpHandlerOptions, + MetadataBearer as __MetadataBearer, + MiddlewareStack, + SerdeContext as __SerdeContext, +} from "@aws-sdk/types"; + +import { + PutFeedbackRequest, + PutFeedbackRequestFilterSensitiveLog, + PutFeedbackResponse, + PutFeedbackResponseFilterSensitiveLog, +} from "../models/models_0"; +import { + deserializeAws_restJson1PutFeedbackCommand, + serializeAws_restJson1PutFeedbackCommand, +} from "../protocols/Aws_restJson1"; +import { ServiceInputTypes, ServiceOutputTypes, WisdomClientResolvedConfig } from "../WisdomClient"; + +export interface PutFeedbackCommandInput extends PutFeedbackRequest {} +export interface PutFeedbackCommandOutput extends PutFeedbackResponse, __MetadataBearer {} + +/** + *

Submits feedback to Wisdom. The feedback is used to improve future recommendations from + * GetRecommendations or + * results from QueryAssistant. + * Feedback can be resubmitted up to 6 hours after submission. + *

+ * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { WisdomClient, PutFeedbackCommand } from "@aws-sdk/client-wisdom"; // ES Modules import + * // const { WisdomClient, PutFeedbackCommand } = require("@aws-sdk/client-wisdom"); // CommonJS import + * const client = new WisdomClient(config); + * const command = new PutFeedbackCommand(input); + * const response = await client.send(command); + * ``` + * + * @see {@link PutFeedbackCommandInput} for command's `input` shape. + * @see {@link PutFeedbackCommandOutput} for command's `response` shape. + * @see {@link WisdomClientResolvedConfig | config} for WisdomClient's `config` shape. + * + */ +export class PutFeedbackCommand extends $Command< + PutFeedbackCommandInput, + PutFeedbackCommandOutput, + WisdomClientResolvedConfig +> { + // Start section: command_properties + // End section: command_properties + + constructor(readonly input: PutFeedbackCommandInput) { + // Start section: command_constructor + super(); + // End section: command_constructor + } + + /** + * @internal + */ + resolveMiddleware( + clientStack: MiddlewareStack, + configuration: WisdomClientResolvedConfig, + options?: __HttpHandlerOptions + ): Handler { + this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize)); + + const stack = clientStack.concat(this.middlewareStack); + + const { logger } = configuration; + const clientName = "WisdomClient"; + const commandName = "PutFeedbackCommand"; + const handlerExecutionContext: HandlerExecutionContext = { + logger, + clientName, + commandName, + inputFilterSensitiveLog: PutFeedbackRequestFilterSensitiveLog, + outputFilterSensitiveLog: PutFeedbackResponseFilterSensitiveLog, + }; + const { requestHandler } = configuration; + return stack.resolve( + (request: FinalizeHandlerArguments) => + requestHandler.handle(request.request as __HttpRequest, options || {}), + handlerExecutionContext + ); + } + + private serialize(input: PutFeedbackCommandInput, context: __SerdeContext): Promise<__HttpRequest> { + return serializeAws_restJson1PutFeedbackCommand(input, context); + } + + private deserialize(output: __HttpResponse, context: __SerdeContext): Promise { + return deserializeAws_restJson1PutFeedbackCommand(output, context); + } + + // Start section: command_body_extra + // End section: command_body_extra +} diff --git a/clients/client-wisdom/src/commands/index.ts b/clients/client-wisdom/src/commands/index.ts index 50551b06a65a..55751871fd67 100644 --- a/clients/client-wisdom/src/commands/index.ts +++ b/clients/client-wisdom/src/commands/index.ts @@ -21,6 +21,7 @@ export * from "./ListContentsCommand"; export * from "./ListKnowledgeBasesCommand"; export * from "./ListTagsForResourceCommand"; export * from "./NotifyRecommendationsReceivedCommand"; +export * from "./PutFeedbackCommand"; export * from "./QueryAssistantCommand"; export * from "./RemoveKnowledgeBaseTemplateUriCommand"; export * from "./SearchContentCommand"; diff --git a/clients/client-wisdom/src/models/models_0.ts b/clients/client-wisdom/src/models/models_0.ts index 8edb39db78d8..ea0c60f8b853 100644 --- a/clients/client-wisdom/src/models/models_0.ts +++ b/clients/client-wisdom/src/models/models_0.ts @@ -890,6 +890,75 @@ export interface NotifyRecommendationsReceivedResponse { errors?: NotifyRecommendationsReceivedError[]; } +export enum Relevance { + HELPFUL = "HELPFUL", + NOT_HELPFUL = "NOT_HELPFUL", +} + +/** + *

The feedback to submit to Wisdom.

+ */ +export interface FeedbackData { + /** + *

The relevance of the target this feedback is for.

+ */ + relevance: Relevance | string | undefined; +} + +export enum TargetType { + RECOMMENDATION = "RECOMMENDATION", + RESULT = "RESULT", +} + +export interface PutFeedbackRequest { + /** + *

The identifier of the Wisdom assistant. Can be either the ID or the ARN. URLs cannot contain the ARN.

+ */ + assistantId: string | undefined; + + /** + *

The identifier of a recommendation. or The identifier of the result data.

+ */ + targetId: string | undefined; + + /** + *

The type of the targetId for which The feedback. is targeted.

+ */ + targetType: TargetType | string | undefined; + + /** + *

The feedback.

+ */ + feedback: FeedbackData | undefined; +} + +export interface PutFeedbackResponse { + /** + *

The identifier of the Wisdom assistant.

+ */ + assistantId: string | undefined; + + /** + *

The Amazon Resource Name (ARN) of the Wisdom assistant.

+ */ + assistantArn: string | undefined; + + /** + *

The identifier of a recommendation. or The identifier of the result data.

+ */ + targetId: string | undefined; + + /** + *

The type of the targetId for which The feedback. is targeted.

+ */ + targetType: TargetType | string | undefined; + + /** + *

The feedback.

+ */ + feedback: FeedbackData | undefined; +} + export interface QueryAssistantRequest { /** *

The identifier of the Wisdom assistant. Can be either the ID or the ARN. URLs cannot contain the ARN.

@@ -2241,6 +2310,27 @@ export const NotifyRecommendationsReceivedResponseFilterSensitiveLog = ( ...obj, }); +/** + * @internal + */ +export const FeedbackDataFilterSensitiveLog = (obj: FeedbackData): any => ({ + ...obj, +}); + +/** + * @internal + */ +export const PutFeedbackRequestFilterSensitiveLog = (obj: PutFeedbackRequest): any => ({ + ...obj, +}); + +/** + * @internal + */ +export const PutFeedbackResponseFilterSensitiveLog = (obj: PutFeedbackResponse): any => ({ + ...obj, +}); + /** * @internal */ diff --git a/clients/client-wisdom/src/protocols/Aws_restJson1.ts b/clients/client-wisdom/src/protocols/Aws_restJson1.ts index 12c043a37d28..3188938310e6 100644 --- a/clients/client-wisdom/src/protocols/Aws_restJson1.ts +++ b/clients/client-wisdom/src/protocols/Aws_restJson1.ts @@ -68,6 +68,7 @@ import { NotifyRecommendationsReceivedCommandInput, NotifyRecommendationsReceivedCommandOutput, } from "../commands/NotifyRecommendationsReceivedCommand"; +import { PutFeedbackCommandInput, PutFeedbackCommandOutput } from "../commands/PutFeedbackCommand"; import { QueryAssistantCommandInput, QueryAssistantCommandOutput } from "../commands/QueryAssistantCommand"; import { RemoveKnowledgeBaseTemplateUriCommandInput, @@ -98,6 +99,7 @@ import { ContentSummary, Document, DocumentText, + FeedbackData, Filter, Highlight, KnowledgeBaseAssociationData, @@ -754,6 +756,34 @@ export const serializeAws_restJson1NotifyRecommendationsReceivedCommand = async }); }; +export const serializeAws_restJson1PutFeedbackCommand = async ( + input: PutFeedbackCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); + const headers: any = { + "content-type": "application/json", + }; + let resolvedPath = + `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/assistants/{assistantId}/feedback"; + resolvedPath = __resolvedPath(resolvedPath, input, "assistantId", () => input.assistantId!, "{assistantId}", false); + let body: any; + body = JSON.stringify({ + ...(input.feedback != null && { feedback: serializeAws_restJson1FeedbackData(input.feedback, context) }), + ...(input.targetId != null && { targetId: input.targetId }), + ...(input.targetType != null && { targetType: input.targetType }), + }); + return new __HttpRequest({ + protocol, + hostname, + port, + method: "PUT", + headers, + path: resolvedPath, + body, + }); +}; + export const serializeAws_restJson1QueryAssistantCommand = async ( input: QueryAssistantCommandInput, context: __SerdeContext @@ -2098,6 +2128,65 @@ const deserializeAws_restJson1NotifyRecommendationsReceivedCommandError = async } }; +export const deserializeAws_restJson1PutFeedbackCommand = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + if (output.statusCode !== 200 && output.statusCode >= 300) { + return deserializeAws_restJson1PutFeedbackCommandError(output, context); + } + const contents: any = map({ + $metadata: deserializeMetadata(output), + }); + const data: Record = __expectNonNull(__expectObject(await parseBody(output.body, context)), "body"); + if (data.assistantArn != null) { + contents.assistantArn = __expectString(data.assistantArn); + } + if (data.assistantId != null) { + contents.assistantId = __expectString(data.assistantId); + } + if (data.feedback != null) { + contents.feedback = deserializeAws_restJson1FeedbackData(data.feedback, context); + } + if (data.targetId != null) { + contents.targetId = __expectString(data.targetId); + } + if (data.targetType != null) { + contents.targetType = __expectString(data.targetType); + } + return contents; +}; + +const deserializeAws_restJson1PutFeedbackCommandError = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + const parsedOutput: any = { + ...output, + body: await parseBody(output.body, context), + }; + const errorCode = loadRestJsonErrorCode(output, parsedOutput.body); + switch (errorCode) { + case "AccessDeniedException": + case "com.amazonaws.wisdom#AccessDeniedException": + throw await deserializeAws_restJson1AccessDeniedExceptionResponse(parsedOutput, context); + case "ResourceNotFoundException": + case "com.amazonaws.wisdom#ResourceNotFoundException": + throw await deserializeAws_restJson1ResourceNotFoundExceptionResponse(parsedOutput, context); + case "ValidationException": + case "com.amazonaws.wisdom#ValidationException": + throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context); + default: + const parsedBody = parsedOutput.body; + throwDefaultError({ + output, + parsedBody, + exceptionCtor: __BaseException, + errorCode, + }); + } +}; + export const deserializeAws_restJson1QueryAssistantCommand = async ( output: __HttpResponse, context: __SerdeContext @@ -2677,6 +2766,12 @@ const serializeAws_restJson1ContentMetadata = (input: Record, co }, {}); }; +const serializeAws_restJson1FeedbackData = (input: FeedbackData, context: __SerdeContext): any => { + return { + ...(input.relevance != null && { relevance: input.relevance }), + }; +}; + const serializeAws_restJson1Filter = (input: Filter, context: __SerdeContext): any => { return { ...(input.field != null && { field: input.field }), @@ -2959,6 +3054,12 @@ const deserializeAws_restJson1DocumentText = (output: any, context: __SerdeConte } as any; }; +const deserializeAws_restJson1FeedbackData = (output: any, context: __SerdeContext): FeedbackData => { + return { + relevance: __expectString(output.relevance), + } as any; +}; + const deserializeAws_restJson1Headers = (output: any, context: __SerdeContext): Record => { return Object.entries(output).reduce((acc: Record, [key, value]: [string, any]) => { if (value === null) { diff --git a/codegen/sdk-codegen/aws-models/wisdom.json b/codegen/sdk-codegen/aws-models/wisdom.json index 467e0cf194b6..0fbe14a90fde 100644 --- a/codegen/sdk-codegen/aws-models/wisdom.json +++ b/codegen/sdk-codegen/aws-models/wisdom.json @@ -68,6 +68,9 @@ { "target": "com.amazonaws.wisdom#NotifyRecommendationsReceived" }, + { + "target": "com.amazonaws.wisdom#PutFeedback" + }, { "target": "com.amazonaws.wisdom#QueryAssistant" }, @@ -1535,6 +1538,21 @@ "smithy.api#documentation": "

The text of the document.

" } }, + "com.amazonaws.wisdom#FeedbackData": { + "type": "structure", + "members": { + "relevance": { + "target": "com.amazonaws.wisdom#Relevance", + "traits": { + "smithy.api#documentation": "

The relevance of the target this feedback is for.

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

The feedback to submit to Wisdom.

" + } + }, "com.amazonaws.wisdom#Filter": { "type": "structure", "members": { @@ -2851,6 +2869,109 @@ "smithy.api#httpError": 412 } }, + "com.amazonaws.wisdom#PutFeedback": { + "type": "operation", + "input": { + "target": "com.amazonaws.wisdom#PutFeedbackRequest" + }, + "output": { + "target": "com.amazonaws.wisdom#PutFeedbackResponse" + }, + "errors": [ + { + "target": "com.amazonaws.wisdom#AccessDeniedException" + }, + { + "target": "com.amazonaws.wisdom#ResourceNotFoundException" + }, + { + "target": "com.amazonaws.wisdom#ValidationException" + } + ], + "traits": { + "smithy.api#documentation": "

Submits feedback to Wisdom. The feedback is used to improve future recommendations from\n GetRecommendations or\n results from QueryAssistant.\n Feedback can be resubmitted up to 6 hours after submission.\n

", + "smithy.api#http": { + "uri": "/assistants/{assistantId}/feedback", + "method": "PUT" + }, + "smithy.api#idempotent": {}, + "smithy.api#private": {} + } + }, + "com.amazonaws.wisdom#PutFeedbackRequest": { + "type": "structure", + "members": { + "assistantId": { + "target": "com.amazonaws.wisdom#UuidOrArn", + "traits": { + "smithy.api#documentation": "

The identifier of the Wisdom assistant. Can be either the ID or the ARN. URLs cannot contain the ARN.

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

The identifier of a recommendation. or The identifier of the result data.

", + "smithy.api#required": {} + } + }, + "targetType": { + "target": "com.amazonaws.wisdom#TargetType", + "traits": { + "smithy.api#documentation": "

The type of the targetId for which The feedback. is targeted.

", + "smithy.api#required": {} + } + }, + "feedback": { + "target": "com.amazonaws.wisdom#FeedbackData", + "traits": { + "smithy.api#documentation": "

The feedback.

", + "smithy.api#required": {} + } + } + } + }, + "com.amazonaws.wisdom#PutFeedbackResponse": { + "type": "structure", + "members": { + "assistantId": { + "target": "com.amazonaws.wisdom#Uuid", + "traits": { + "smithy.api#documentation": "

The identifier of the Wisdom assistant.

", + "smithy.api#required": {} + } + }, + "assistantArn": { + "target": "com.amazonaws.wisdom#UuidOrArn", + "traits": { + "smithy.api#documentation": "

The Amazon Resource Name (ARN) of the Wisdom assistant.

", + "smithy.api#required": {} + } + }, + "targetId": { + "target": "com.amazonaws.wisdom#Uuid", + "traits": { + "smithy.api#documentation": "

The identifier of a recommendation. or The identifier of the result data.

", + "smithy.api#required": {} + } + }, + "targetType": { + "target": "com.amazonaws.wisdom#TargetType", + "traits": { + "smithy.api#documentation": "

The type of the targetId for which The feedback. is targeted.

", + "smithy.api#required": {} + } + }, + "feedback": { + "target": "com.amazonaws.wisdom#FeedbackData", + "traits": { + "smithy.api#documentation": "

The feedback.

", + "smithy.api#required": {} + } + } + } + }, "com.amazonaws.wisdom#QueryAssistant": { "type": "operation", "input": { @@ -3118,6 +3239,21 @@ ] } }, + "com.amazonaws.wisdom#Relevance": { + "type": "string", + "traits": { + "smithy.api#enum": [ + { + "value": "HELPFUL", + "name": "HELPFUL" + }, + { + "value": "NOT_HELPFUL", + "name": "NOT_HELPFUL" + } + ] + } + }, "com.amazonaws.wisdom#RelevanceLevel": { "type": "string", "traits": { @@ -3761,6 +3897,21 @@ "target": "com.amazonaws.wisdom#TagValue" } }, + "com.amazonaws.wisdom#TargetType": { + "type": "string", + "traits": { + "smithy.api#enum": [ + { + "value": "RECOMMENDATION", + "name": "RECOMMENDATION" + }, + { + "value": "RESULT", + "name": "RESULT" + } + ] + } + }, "com.amazonaws.wisdom#TooManyTagsException": { "type": "structure", "members": {