Assert.That(Texts(chat),Is.EqualTo(new[]{"Example question","Example answer",ChatCompression.WithLastMessage(ChatCompressionTarget.NEW_CHAT,"The summary","Second question"),"Second answer"}),"The order of the time stamps is the order of the conversation.");
Assert.That(ordered.Select(block=>block.Role),Is.EqualTo(new[]{ChatRole.USER,ChatRole.AI,ChatRole.USER,ChatRole.AI}),"The summary shares the message of the user, so the roles keep alternating.");
Assert.That(ordered[2].HideFromUser,Is.False,"The user sees what the new chat continues from.");
Assert.That(ordered[2].Time,Is.EqualTo(START.AddMinutes(5)),"The last message of the user keeps its time.");
Assert.That(ordered[3].Time,Is.EqualTo(START.AddMinutes(6)),"The last answer keeps its time.");
Assert.That(chat.Blocks,Is.EqualTo(ordered),"The list is in the order of the conversation as well.");
Assert.That(message.FileAttachments.Select(attachment=>attachment.FileName),Is.EqualTo(new[]{"report.pdf","chart.png"}),"The AI receives the files of the last message in full again.");
Assert.That(Texts(chat),Is.EqualTo(new[]{"The summary","Result of the assistant"}),"The hidden message was summarized, so the summary stands as a message of its own.");
Assert.That(((ContentText)lastAnswer.Content!).ReportedUsage,Is.Null,"What the provider reported was for the request of the compressed chat, which held far more.");
Assert.That(chat.AugmentedData,Is.Empty,"The retrieved data belonged to the last request of the compressed chat.");
Assert.That(chat.SelectedProvider,Is.EqualTo("provider-1"),"The new chat continues with the provider which wrote the summary.");
ChatCompression.TurnIntoContinuation(chat,0,ChatCompressionTarget.NEW_CHAT,"The AI read https://example.org/report.",ChatRestrictions.NONE,"provider-1");
Assert.That(lastAnswer.WebAddressesFromTools,Does.Contain(named),"The summary still shows the page, so the model may read it again, as it could in the compressed chat.");
Assert.That(lastAnswer.WebAddressesFromTools,Does.Not.Contain(forgotten),"Nothing in the new chat shows the page anymore, so it counts no more than before compressing.");
}
}
[Test]
publicvoidTheRestrictionsOnlyTighten()
{
varchat=Chat(
Block(ChatRole.USER,"Question about the confidential handbook",1),
Block(ChatRole.AI,"Answer from the confidential handbook",2),
Assert.That(chat.DataSecurity,Is.EqualTo(DataSourceSecurity.SELF_HOSTED),"The summary carries the confidential content along, so the new chat stays as restricted as the old one.");
Assert.That(chat.RequiredProviderConfidence,Is.EqualTo(ConfidenceLevel.HIGH),"What the summary demands is added.");
}
}
[Test]
publicvoidAnUnansweredQuestionBecomesTheDraft()
{
varpending=Block(ChatRole.USER,"Question which was too long for the model",5);
Assert.That(chat.Draft.Text,Is.EqualTo("Question which was too long for the model"),"The user finds the question in the field for the next message and can send it again.");
Assert.That(Texts(chat),Is.EqualTo(new[]{ChatCompression.WithLastMessage(ChatCompressionTarget.NEW_CHAT,"The summary","Second question"),"Second answer"}),"The question is in the draft, so it is not a message of the new chat as well.");
Assert.That(()=>ChatCompression.TurnIntoContinuation(chat,0,ChatCompressionTarget.NEW_CHAT,"The summary",ChatRestrictions.NONE,"provider-1"),Throws.InvalidOperationException,"A copy which cannot become a continuation must not be stored.");
Assert.That(ChatCompression.ContinuedName(name,"Fortsetzung von {0}","Fortsetzung {1} von {0}"),Is.EqualTo(expected),"A translation may put the name of the chat last.");
Assert.That(message,Does.StartWith("**Summary of the earlier conversation**"),"The conversation goes on where it was, so there is no other chat to name.");
Assert.That(chat.Draft.IsEmpty,Is.True,"The user still has the message being written in the field, and the chat of an assistant reads no draft.");
Assert.That(Texts(chat),Is.EqualTo(new[]{ChatCompression.WithLastMessage(ChatCompressionTarget.SAME_CHAT,"The summary","Second question"),"Second answer"}),"The unanswered question is part of the summary instead.");
privatestaticstringRequestKey(stringaddress)=>WebAddresses.TryCreateRequestKey(address,outvarrequestKey)?requestKey:thrownewArgumentException($"No web address: {address}");