openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Chat/AssistantChatMessage.Serialization.cs
64lines · modeblame
9f9f2936Jose Arriaga Maldonado2 years ago | 1 | using System; |
| 2 | using System.ClientModel.Primitives; | |
| 3 | using System.Collections.Generic; | |
| 4 | using System.Text.Json; | |
| 5 | | |
| 6 | namespace OpenAI.Chat; | |
| 7 | | |
| 8 | [CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel<OpenAI.Chat.AssistantChatMessage>.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))] | |
| 9 | public partial class AssistantChatMessage : IJsonModel<AssistantChatMessage> | |
| 10 | { | |
| 11 | void IJsonModel<AssistantChatMessage>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) | |
| 12 | => CustomSerializationHelpers.SerializeInstance(this, SerializeAssistantChatMessage, writer, options); | |
| 13 | | |
| 14 | internal static void SerializeAssistantChatMessage(AssistantChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) | |
896b9e0bTravis Wilson2 years ago | 15 | => instance.WriteCore(writer, options); |
| 16 | | |
| 17 | protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) | |
9f9f2936Jose Arriaga Maldonado2 years ago | 18 | { |
| 19 | writer.WriteStartObject(); | |
896b9e0bTravis Wilson2 years ago | 20 | if (Optional.IsDefined(ParticipantName)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 21 | { |
| 22 | writer.WritePropertyName("name"u8); | |
896b9e0bTravis Wilson2 years ago | 23 | writer.WriteStringValue(ParticipantName); |
9f9f2936Jose Arriaga Maldonado2 years ago | 24 | } |
896b9e0bTravis Wilson2 years ago | 25 | if (Optional.IsCollectionDefined(ToolCalls)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 26 | { |
| 27 | writer.WritePropertyName("tool_calls"u8); | |
| 28 | writer.WriteStartArray(); | |
896b9e0bTravis Wilson2 years ago | 29 | foreach (var item in ToolCalls) |
9f9f2936Jose Arriaga Maldonado2 years ago | 30 | { |
| 31 | writer.WriteObjectValue(item, options); | |
| 32 | } | |
| 33 | writer.WriteEndArray(); | |
| 34 | } | |
896b9e0bTravis Wilson2 years ago | 35 | if (Optional.IsDefined(FunctionCall)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 36 | { |
896b9e0bTravis Wilson2 years ago | 37 | if (FunctionCall != null) |
9f9f2936Jose Arriaga Maldonado2 years ago | 38 | { |
| 39 | writer.WritePropertyName("function_call"u8); | |
896b9e0bTravis Wilson2 years ago | 40 | writer.WriteObjectValue(FunctionCall, options); |
9f9f2936Jose Arriaga Maldonado2 years ago | 41 | } |
| 42 | else | |
| 43 | { | |
| 44 | writer.WriteNull("function_call"); | |
| 45 | } | |
| 46 | } | |
| 47 | writer.WritePropertyName("role"u8); | |
896b9e0bTravis Wilson2 years ago | 48 | writer.WriteStringValue(Role); |
| 49 | if (Optional.IsCollectionDefined(Content)) | |
9f9f2936Jose Arriaga Maldonado2 years ago | 50 | { |
896b9e0bTravis Wilson2 years ago | 51 | if (Content[0] != null) |
9f9f2936Jose Arriaga Maldonado2 years ago | 52 | { |
| 53 | writer.WritePropertyName("content"u8); | |
896b9e0bTravis Wilson2 years ago | 54 | writer.WriteStringValue(Content[0].Text); |
9f9f2936Jose Arriaga Maldonado2 years ago | 55 | } |
| 56 | else | |
| 57 | { | |
| 58 | writer.WriteNull("content"); | |
| 59 | } | |
| 60 | } | |
896b9e0bTravis Wilson2 years ago | 61 | writer.WriteSerializedAdditionalRawData(_serializedAdditionalRawData, options); |
9f9f2936Jose Arriaga Maldonado2 years ago | 62 | writer.WriteEndObject(); |
| 63 | } | |
| 64 | } |