mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Update AIContextProviders to use Microsoft.Extensions.Compliance.Redaction (#4854)
* Update providers to use Microsoft.Extensions.Compliance.Redaction * Fix formatting. * Fix readme
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.AI;
|
||||
using Microsoft.Extensions.Compliance.Redaction;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Shared.Diagnostics;
|
||||
|
||||
@@ -62,6 +63,7 @@ public sealed class TextSearchProvider : MessageAIContextProvider
|
||||
private readonly string _contextPrompt;
|
||||
private readonly string _citationsPrompt;
|
||||
private readonly Func<IList<TextSearchResult>, string>? _contextFormatter;
|
||||
private readonly Redactor _redactor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TextSearchProvider"/> class.
|
||||
@@ -89,6 +91,7 @@ public sealed class TextSearchProvider : MessageAIContextProvider
|
||||
this._contextPrompt = options?.ContextPrompt ?? DefaultContextPrompt;
|
||||
this._citationsPrompt = options?.CitationsPrompt ?? DefaultCitationsPrompt;
|
||||
this._contextFormatter = options?.ContextFormatter;
|
||||
this._redactor = options?.EnableSensitiveTelemetryData == true ? NullRedactor.Instance : (options?.Redactor ?? new ReplacingRedactor("<redacted>"));
|
||||
|
||||
// Create the on-demand search tool (only used if behavior is OnDemandFunctionCalling)
|
||||
this._tools =
|
||||
@@ -180,7 +183,7 @@ public sealed class TextSearchProvider : MessageAIContextProvider
|
||||
|
||||
if (this._logger?.IsEnabled(LogLevel.Trace) is true)
|
||||
{
|
||||
this._logger.LogTrace("TextSearchProvider: Search Results\nInput:{Input}\nOutput:{MessageText}", input, formatted);
|
||||
this._logger.LogTrace("TextSearchProvider: Search Results\nInput:{Input}\nOutput:{MessageText}", this.SanitizeLogData(input), this.SanitizeLogData(formatted));
|
||||
}
|
||||
|
||||
return [new ChatMessage(ChatRole.User, formatted)];
|
||||
@@ -249,7 +252,7 @@ public sealed class TextSearchProvider : MessageAIContextProvider
|
||||
|
||||
if (this._logger.IsEnabled(LogLevel.Trace))
|
||||
{
|
||||
this._logger.LogTrace("TextSearchProvider Input:{UserQuestion}\nOutput:{MessageText}", userQuestion, outputText);
|
||||
this._logger.LogTrace("TextSearchProvider Input:{UserQuestion}\nOutput:{MessageText}", this.SanitizeLogData(userQuestion), this.SanitizeLogData(outputText));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,6 +328,8 @@ public sealed class TextSearchProvider : MessageAIContextProvider
|
||||
public object? RawRepresentation { get; set; }
|
||||
}
|
||||
|
||||
private string SanitizeLogData(string? data) => this._redactor.Redact(data);
|
||||
|
||||
/// <summary>
|
||||
/// Represents the per-session state of a <see cref="TextSearchProvider"/> stored in the <see cref="AgentSession.StateBag"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user