Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite393f33

Browse files
peterwaldstephentoubRussKie
authored
[AI Evaluation] Add versioning to reporting and caching (#6070)
* [AI Evaluation] Add versioning to reporting and caching* Move CacheVersion key down into the DistributedCachingChatClient* Update src/Libraries/Microsoft.Extensions.AI/ChatCompletion/DistributedCachingChatClient.cs* Update src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/CSharp/ScenarioRunResult.csCo-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>* Update src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/CSharp/Defaults.csCo-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>* Rollback formatVersion init change* Make version const internal, update comments.* Add assertion for report version* Make ReportVersion property readonly---------Co-authored-by: Stephen Toub <stoub@microsoft.com>Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>
1 parente351c25 commite393f33

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

‎src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/CSharp/Defaults.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ public static class Defaults
3030
/// in the <see cref="IResponseCacheProvider"/>'s cache before they are considered expired and evicted.
3131
/// </summary>
3232
publicstaticTimeSpanDefaultTimeToLiveForCacheEntries{get;}=TimeSpan.FromDays(14);
33+
34+
/// <summary>
35+
/// Defines the version number for the reporting format. If and when the serialized format undergoes
36+
/// breaking changes, this number will be incremented.
37+
/// </summary>
38+
internalconstintReportingFormatVersion=1;
3339
}

‎src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/CSharp/ScenarioRunResult.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Microsoft.Extensions.AI.Evaluation.Reporting;
3737
/// The <see cref="Evaluation.EvaluationResult"/> for the <see cref="ScenarioRun"/> corresponding to the
3838
/// <see cref="ScenarioRunResult"/> being constructed.
3939
/// </param>
40+
/// <param name="formatVersion">The version of the format used to persist the current <see cref="ScenarioRunResult"/>.</param>
4041
[method:JsonConstructor]
4142
publicsealedclassScenarioRunResult(
4243
stringscenarioName,
@@ -45,7 +46,8 @@ public sealed class ScenarioRunResult(
4546
DateTimecreationTime,
4647
IList<ChatMessage>messages,
4748
ChatResponsemodelResponse,
48-
EvaluationResultevaluationResult)
49+
EvaluationResultevaluationResult,
50+
int?formatVersion=null)
4951
{
5052
/// <summary>
5153
/// Initializes a new instance of the <see cref="ScenarioRunResult"/> class.
@@ -81,6 +83,11 @@ public ScenarioRunResult(
8183
{
8284
}
8385

86+
/// <summary>
87+
/// Gets the version of the format used to persist the current <see cref="ScenarioRunResult"/>.
88+
/// </summary>
89+
publicint?FormatVersion{get;}=formatVersion??Defaults.ReportingFormatVersion;
90+
8491
/// <summary>
8592
/// Gets or sets the <see cref="ScenarioRun.ScenarioName"/>.
8693
/// </summary>

‎src/Libraries/Microsoft.Extensions.AI/ChatCompletion/DistributedCachingChatClient.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ protected override async Task WriteCacheStreamingAsync(string key, IReadOnlyList
107107
/// The generated cache key is not guaranteed to be stable across releases of the library.
108108
/// </para>
109109
/// </remarks>
110-
protectedoverridestringGetCacheKey(paramsReadOnlySpan<object?>values)=>
111-
AIJsonUtilities.HashDataToString(values,_jsonSerializerOptions);
110+
protectedoverridestringGetCacheKey(paramsReadOnlySpan<object?>values)
111+
{
112+
// Bump the cache version to invalidate existing caches if the serialization format changes in a breaking way.
113+
constintCacheVersion=1;
114+
115+
returnAIJsonUtilities.HashDataToString([CacheVersion, ..values],_jsonSerializerOptions);
116+
}
112117
}

‎test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ScenarioRunResultTests.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void SerializeScenarioRunResult()
3838
messages:[newChatMessage(ChatRole.User,"prompt")],
3939
modelResponse:newChatResponse(newChatMessage(ChatRole.Assistant,"response")),
4040
evaluationResult:newEvaluationResult(booleanMetric,numericMetric,stringMetric,metricWithNoValue));
41+
Assert.Equal(Defaults.ReportingFormatVersion,entry.FormatVersion);
4142

4243
stringjson=JsonSerializer.Serialize(entry,JsonUtilities.Default.ScenarioRunResultTypeInfo);
4344
ScenarioRunResult?deserialized=JsonSerializer.Deserialize<ScenarioRunResult>(json,JsonUtilities.Default.ScenarioRunResultTypeInfo);
@@ -49,6 +50,7 @@ public void SerializeScenarioRunResult()
4950
Assert.Equal(entry.CreationTime,deserialized.CreationTime);
5051
Assert.True(entry.Messages.SequenceEqual(deserialized.Messages,ChatMessageComparer.Instance));
5152
Assert.Equal(entry.ModelResponse,deserialized.ModelResponse,ChatResponseComparer.Instance);
53+
Assert.Equal(entry.FormatVersion,deserialized.FormatVersion);
5254

5355
ValidateEquivalence(entry.EvaluationResult,deserialized.EvaluationResult);
5456
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp