Skip to content

Commit d836c67

Browse files
committed
feat(backend/WebApp): implement content safety and filter handling
Added content safety analysis and prompt injection detection features to the agent streaming service. Introduced handling for content filter exceptions and integrated SSE events for real-time feedback on content filter violations. Updated the agent controller and streaming service to manage content filter responses and maintain conversation continuity. Modified files (12): - TaskAgent.Application/Interfaces/IAgentStreamingService.cs: Added method for content filter exception retrieval - TaskAgent.Application/Interfaces/IContentSafetyService.cs: Removed interface for content safety service - TaskAgent.Infrastructure/Services/AgentStreamingService.cs: Implemented content filter handling and exception management - TaskAgent.WebApi/Controllers/AgentController.cs: Updated to handle content filter events and responses - TaskAgent.WebApi/Services/SseStreamingService.cs: Added content filter event sending logic - TaskAgent.WebApi/Constants/AgentConstants.cs: Defined constants for content filter events and messages - TaskAgent.Application/DTOs/ContentSafetyResult.cs: Removed DTO for content safety results - TaskAgent.Application/DTOs/PromptInjectionResult.cs: Removed DTO for prompt injection results - TaskAgent.Infrastructure/Constants/ContentSafetyConstants.cs: Removed constants related to content safety - TaskAgent.Infrastructure/Models/ContentSafetyConfig.cs: Removed model for content safety configuration - TaskAgent.Infrastructure/Models/PromptShieldResponse.cs: Removed model for prompt shield response - TaskAgent.Infrastructure/Services/ContentSafetyService.cs: Removed content safety service implementation
1 parent a329b4a commit d836c67

13 files changed

Lines changed: 345 additions & 395 deletions

File tree

src/backend/services/TaskAgent/src/TaskAgent.Application/DTOs/ContentSafetyResult.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/backend/services/TaskAgent/src/TaskAgent.Application/DTOs/PromptInjectionResult.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/backend/services/TaskAgent/src/TaskAgent.Application/Interfaces/IAgentStreamingService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ IAsyncEnumerable<object> StreamResponseAsync(
4141
/// <param name="serializedState">Serialized thread state.</param>
4242
/// <returns>Deserialized agent thread or new thread if deserialization fails.</returns>
4343
object DeserializeThread(string? serializedState);
44+
45+
/// <summary>
46+
/// Gets the content filter exception if one occurred during the last streaming operation.
47+
/// </summary>
48+
/// <returns>ContentFilterException if content was filtered, null otherwise.</returns>
49+
object? GetContentFilterException();
4450
}

src/backend/services/TaskAgent/src/TaskAgent.Application/Interfaces/IContentSafetyService.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/backend/services/TaskAgent/src/TaskAgent.Infrastructure/Constants/ContentSafetyConstants.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/backend/services/TaskAgent/src/TaskAgent.Infrastructure/InfrastructureServiceExtensions.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Azure;
2-
using Azure.AI.ContentSafety;
31
using Microsoft.EntityFrameworkCore;
42
using Microsoft.Extensions.Configuration;
53
using Microsoft.Extensions.DependencyInjection;
@@ -55,47 +53,6 @@ IConfiguration configuration
5553
services.AddScoped<IAgentStreamingService, AgentStreamingService>();
5654
services.AddScoped<IConversationService, ConversationService>();
5755

58-
RegisterContentSafety(services, configuration);
59-
6056
return services;
6157
}
62-
63-
/// <summary>
64-
/// Register Azure Content Safety infrastructure
65-
/// </summary>
66-
private static void RegisterContentSafety(
67-
IServiceCollection services,
68-
IConfiguration configuration
69-
)
70-
{
71-
string? contentSafetyEndpoint = configuration["ContentSafety:Endpoint"];
72-
string? contentSafetyApiKey = configuration["ContentSafety:ApiKey"];
73-
74-
if (
75-
string.IsNullOrWhiteSpace(contentSafetyEndpoint)
76-
|| string.IsNullOrWhiteSpace(contentSafetyApiKey)
77-
)
78-
{
79-
throw new InvalidOperationException(
80-
"Content Safety configuration is required. Please configure ContentSafety:Endpoint and ContentSafety:ApiKey."
81-
);
82-
}
83-
84-
var contentSafetyClient = new ContentSafetyClient(
85-
new Uri(contentSafetyEndpoint),
86-
new AzureKeyCredential(contentSafetyApiKey)
87-
);
88-
services.AddSingleton(contentSafetyClient);
89-
90-
services.AddHttpClient(
91-
"ContentSafety",
92-
client =>
93-
{
94-
client.BaseAddress = new Uri(contentSafetyEndpoint);
95-
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", contentSafetyApiKey);
96-
}
97-
);
98-
99-
services.AddScoped<IContentSafetyService, ContentSafetyService>();
100-
}
10158
}

src/backend/services/TaskAgent/src/TaskAgent.Infrastructure/Models/ContentSafetyConfig.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/backend/services/TaskAgent/src/TaskAgent.Infrastructure/Models/PromptShieldResponse.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)