Navigation
- 00.OVERVIEW
- Action Planner
- Actions
- AI System
- Application class
- Augmentations
- Data Sources
- Function Calls
- Moderator
- Planner
- Powered by AI
- Prompts
- Streaming
- Turns
- User Authentication
The Moderator
is responsible for reviewing the input prompt and approving the AI generated plans. It is configured when orchestrating the Application
class.
The AI system is such that developers can create their own moderator class by simply implementing the moderator interface. The library has a few native moderators that can be used out of the box:
Name | Description |
---|---|
OpenAIModerator | Wrapper around OpenAI's Moderation API. |
AzureContentSafetyModerator | Wrapper around Azure Content Safety API |
Here's an example of configuring the OpenAIModerator
:
JS
const moderator = new OpenAIModerator({
apiKey: process.env.OPENAI_KEY!,
moderate: 'both'
});
const app = new Application({
storage,
ai: {
planner,
moderator
}
});
C#
OpenAIModeratorOptions moderatorOptions = new(config.OpenAI.ApiKey, ModerationType.Both);
IModerator<TurnState> moderator = new OpenAIModerator<TurnState>(moderatorOptions);
AIOptions<TurnState> aIOptions = new(planner)
{
Moderator = moderator
};
var app = new ApplicationBuilder<TurnState>()
.WithStorage(storage)
.WithAIOptions(aIOptions)
.Build();
Python
app = Application[TurnState](ApplicationOptions(
ai=AIOptions(
moderator=OpenAIModerator(OpenAIModeratorOptions(
api_key=config.OPENAI_KEY
))
)
))
This snippet is taken from the [Twenty Questions bot] sample. Note for C# application, the moderator should be registered to the Web app's service collection as a singleton.
Here's an example of configuring the AzureContentSafetyModerator
:
JS
const moderator = new AzureContentSafetyModerator({
apiKey: process.env.AZURE_CONTENT_SAFETY_KEY,
endpoint: process.env.AZURE_CONTENT_SAFETY_ENDPOINT,
apiVersion: "2023-04-30-preview",
moderate: "both"
});
C#
AzureContentSafetyModeratorOptions moderatorOptions = new(config.Azure.ContentSafetyApiKey, config.Azure.ContentSafetyEndpoint, ModerationType.Both);
IModerator<TurnState> moderator = new AzureContentSafetyModerator<TurnState>(moderatorOptions);
Python
app = Application[TurnState](ApplicationOptions(
ai=AIOptions(
moderator=AzureContentSafetyModerator(AzureContentSafetyModeratorOptions(
api_key=config.AZURE_CONTENT_SAFETY_KEY,
endpoint=config.AZURE_CONTENT_SAFETY_ENDPOINT
))
)
))