Skip to content

Commit 16c3588

Browse files
committed
fixing KernelProcessEventData toObject
1 parent 81a36b7 commit 16c3588

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

dotnet/src/Experimental/Process.Abstractions/KernelProcessEventData.cs

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Runtime.Serialization;
44
using System.Text.Json;
5+
using Microsoft.SemanticKernel.Connectors.OpenAI;
56

67
namespace Microsoft.SemanticKernel;
78

@@ -37,12 +38,23 @@ public sealed record KernelProcessEventData
3738
{
3839
try
3940
{
41+
if (type == typeof(OpenAIChatMessageContent))
42+
{
43+
// Special case for OpenAIChatMessageContent, which only has constructors with parameters
44+
// Instead using base class ChatMessageContent
45+
return JsonSerializer.Deserialize<ChatMessageContent>(this.Content);
46+
}
47+
4048
return JsonSerializer.Deserialize(this.Content, type);
4149
}
4250
catch (JsonException)
4351
{
4452
throw new KernelException($"Cannot deserialize object {this.Content}");
4553
}
54+
catch (NotSupportedException e)
55+
{
56+
throw new KernelException($"Cannot deserialize object {this.Content}, type {type.FullName} has no parameterless constructor", e);
57+
}
4658
}
4759

4860
return null;

dotnet/src/Experimental/Process.Abstractions/Process.Abstractions.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23+
<ProjectReference Include="..\..\Connectors\Connectors.OpenAI\Connectors.OpenAI.csproj" />
2324
<ProjectReference Include="..\..\SemanticKernel.Core\SemanticKernel.Core.csproj" />
2425
</ItemGroup>
2526

0 commit comments

Comments
 (0)