-
Notifications
You must be signed in to change notification settings - Fork 836
Description
Description
I know that DistributedCachingChatClient.GetCacheKey
is documented with:
/// The generated cache key is not guaranteed to be stable across releases of the library.
... but isn't it expected to be stable across OSes? I think it should be because this is a valid scenario:
- Multiple web servers are hosting an app that uses MEAI. Some servers might be Windows; others Linux
- They all connect to a shared Redis instance that acts as the storage for
DistributedCachingChatClient
In this case, we wouldn't expect all the Windows servers to have one set of cache entries and all the Linux servers to have a different set.
However, the cache keys do vary across the two OSes. I think the underlying reason is that AIJsonUtilities.DefaultOptions
enables indentation and linebreaks during JSON serialization, and so you get different linebreaks going into the hash.
Reproduction Steps
var dcc = new MyDistributedCacheClient();
Console.WriteLine(dcc.GetCacheKey([new ChatMessage(ChatRole.User, "")]));
class MyDistributedCacheClient() : DistributedCachingChatClient(new SomeIChatClient(), new SomeDistributedCache())
{
public string GetCacheKey(IEnumerable<ChatMessage> messages, ChatOptions? options = null)
=> base.GetCacheKey(messages, options);
}
Expected behavior
On Windows and Linux, should write the same string to the console.
Actual behavior
On Windows, outputs E51327685BFC9E6C0D5B61C513E2F5FB9EDD2C9177EC75379B059EE71466383451E959B1FE9C0865596E4EA44CE8D6C6
On Linux, outputs 68F57BBAD7E8DC570361582A11E973AA5B05665766DF422D727C5937738ECB0559AB9338AA68FCFD49467169CEFF9B2A
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response