openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Chat/Streaming/StreamingChatFunctionCallUpdate.Serialization.cs
31lines · modeblame
31c2ba63Jose Arriaga Maldonado1 years ago | 1 | using System; |
| 2 | using System.ClientModel.Primitives; | |
| 3 | using System.Runtime.CompilerServices; | |
| 4 | using System.Text.Json; | |
| 5 | | |
| 6 | namespace OpenAI.Chat; | |
| 7 | | |
| 8 | public partial class StreamingChatFunctionCallUpdate : IJsonModel<StreamingChatFunctionCallUpdate> | |
| 9 | { | |
| 10 | // CUSTOM: Replaced the call to WriteRawValue() for a call to WriteStringValue() because even though this property | |
| 11 | // is supposed to be a JSON object, the REST API handles it as a string given that there is no guarantee that it | |
| 12 | // actually is valid JSON. | |
| 13 | [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| 14 | private void SerializeFunctionArgumentsUpdateValue(Utf8JsonWriter writer, ModelReaderWriterOptions options) | |
| 15 | { | |
| 16 | writer.WriteStringValue(FunctionArgumentsUpdate.ToString()); | |
| 17 | } | |
| 18 | | |
| 19 | // CUSTOM: Replaced the call to GetRawText() for a call to GetString() because otherwise the starting and ending | |
| 20 | // quotes of the string are included in the BinaryData. While this is actually a string in the REST API, we want to | |
| 21 | // handle it as JSON binary data instead. | |
| 22 | [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| 23 | private static void DeserializeFunctionArgumentsUpdateValue(JsonProperty property, ref BinaryData arguments, ModelReaderWriterOptions options = null) | |
| 24 | { | |
| 25 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 26 | { | |
| 27 | return; | |
| 28 | } | |
| 29 | arguments = BinaryData.FromString(property.Value.GetString()); | |
| 30 | } | |
| 31 | } |