11import { Agent , AgentOptions } from "./agent" ;
22import { ConversationMessage , ParticipantRole } from "../types" ;
33import { Logger } from "../utils/logger" ;
4- import {
5- ComprehendClient ,
6- DetectSentimentCommand ,
7- DetectPiiEntitiesCommand ,
4+ import {
5+ ComprehendClient ,
6+ DetectSentimentCommand ,
7+ DetectPiiEntitiesCommand ,
88 DetectToxicContentCommand ,
99 DetectSentimentCommandOutput ,
1010 DetectPiiEntitiesCommandOutput ,
@@ -29,6 +29,7 @@ type CheckFunction = (input: string) => Promise<string | null>;
2929
3030// Extended options for ComprehendContentFilterAgent
3131export interface ComprehendFilterAgentOptions extends AgentOptions {
32+ region ?: string ;
3233 enableSentimentCheck ?: boolean ;
3334 enablePiiCheck ?: boolean ;
3435 enableToxicityCheck ?: boolean ;
@@ -40,7 +41,7 @@ export interface ComprehendFilterAgentOptions extends AgentOptions {
4041
4142/**
4243 * ComprehendContentFilterAgent class
43- *
44+ *
4445 * This agent uses Amazon Comprehend to analyze and filter content based on
4546 * sentiment, PII, and toxicity. It can be configured to enable/disable specific
4647 * checks and allows for the addition of custom checks.
@@ -78,8 +79,8 @@ export class ComprehendFilterAgent extends Agent {
7879 this . languageCode = this . validateLanguageCode ( options . languageCode ) ?? 'en' ;
7980
8081 // Ensure at least one check is enabled
81- if ( ! this . enableSentimentCheck &&
82- ! this . enablePiiCheck &&
82+ if ( ! this . enableSentimentCheck &&
83+ ! this . enablePiiCheck &&
8384 ! this . enableToxicityCheck ) {
8485 this . enableToxicityCheck = true ;
8586 }
@@ -165,7 +166,7 @@ export class ComprehendFilterAgent extends Agent {
165166 * @returns A string describing the issue if sentiment is negative, null otherwise
166167 */
167168 private checkSentiment ( result : DetectSentimentCommandOutput ) : string | null {
168- if ( result . Sentiment === 'NEGATIVE' &&
169+ if ( result . Sentiment === 'NEGATIVE' &&
169170 result . SentimentScore ?. Negative > this . sentimentThreshold ) {
170171 return `Negative sentiment detected (${ result . SentimentScore . Negative . toFixed ( 2 ) } )` ;
171172 }
@@ -276,11 +277,11 @@ export class ComprehendFilterAgent extends Agent {
276277 */
277278 private validateLanguageCode ( languageCode : LanguageCode | undefined ) : LanguageCode | undefined {
278279 if ( ! languageCode ) return undefined ;
279-
280+
280281 const validLanguageCodes : LanguageCode [ ] = [
281282 'en' , 'es' , 'fr' , 'de' , 'it' , 'pt' , 'ar' , 'hi' , 'ja' , 'ko' , 'zh' , 'zh-TW'
282283 ] ;
283-
284+
284285 return validLanguageCodes . includes ( languageCode ) ? languageCode : undefined ;
285286 }
286287}
0 commit comments