-
Couldn't load subscription status.
- Fork 840
Fix ChatMessage.CreatedAt being always overwritten by the latest timestamp. #6885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ade585c
d04e6b5
a2a35dc
f1e3770
d053f6d
44de1fc
5a7d3a6
0747f83
212b4ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -359,6 +359,51 @@ | |
| Assert.Equal("Hello, world!", Assert.IsType<TextContent>(Assert.Single(Assert.Single(response.Messages).Contents)).Text); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(false)] | ||
| [InlineData(true)] | ||
| public async Task ToChatResponse_AlternativeTimestamps(bool useAsync) | ||
| { | ||
| DateTimeOffset early = new(2024, 1, 1, 10, 0, 0, TimeSpan.Zero); | ||
| DateTimeOffset middle = new(2024, 1, 1, 11, 0, 0, TimeSpan.Zero); | ||
| DateTimeOffset late = new(2024, 1, 1, 12, 0, 0, TimeSpan.Zero); | ||
| DateTimeOffset unixEpoch = new(1970, 1, 1, 0, 0, 0, TimeSpan.Zero); | ||
|
|
||
| ChatResponseUpdate[] updates = | ||
| [ | ||
| // Start with an early timestamp | ||
|
Check failure on line 374 in test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs
|
||
| new(ChatRole.Tool, "a") { MessageId = "4", CreatedAt = early }, | ||
|
|
||
| // Unix epoch (as "null") should not overwrite | ||
| new(null, "b") { CreatedAt = unixEpoch }, | ||
|
|
||
| // Newer timestamp should overwrite | ||
stephentoub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| new(null, "c") { CreatedAt = middle }, | ||
|
|
||
| // Older timestamp should not overwrite | ||
| new(null, "d") { CreatedAt = early }, | ||
|
|
||
| // Even newer timestamp should overwrite | ||
| new(null, "e") { CreatedAt = late }, | ||
|
|
||
| // Unix epoch should not overwrite again | ||
| new(null, "f") { CreatedAt = unixEpoch }, | ||
|
|
||
| // null should not overwrite | ||
| new(null, "g") { CreatedAt = null }, | ||
| ]; | ||
stephentoub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ChatResponse response = useAsync ? | ||
| updates.ToChatResponse() : | ||
| await YieldAsync(updates).ToChatResponseAsync(); | ||
| Assert.Single(response.Messages); | ||
|
|
||
| Assert.Equal("abcdefg", response.Messages[0].Text); | ||
| Assert.Equal(ChatRole.Tool, response.Messages[0].Role); | ||
| Assert.Equal(late, response.Messages[0].CreatedAt); | ||
| Assert.Equal(late, response.CreatedAt); | ||
| } | ||
|
|
||
| private static async IAsyncEnumerable<ChatResponseUpdate> YieldAsync(IEnumerable<ChatResponseUpdate> updates) | ||
| { | ||
| foreach (ChatResponseUpdate update in updates) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.