openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Chat/Internal/InternalChatCompletionMessageToolCallFunction.Serialization.cs
30lines · modecode
| 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 | internal partial class InternalChatCompletionMessageToolCallFunction : IJsonModel<InternalChatCompletionMessageToolCallFunction> |
| 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 SerializeArgumentsValue(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 15 | { |
| 16 | string value = Arguments.ToMemory().IsEmpty |
| 17 | ? string.Empty |
| 18 | : Arguments.ToString(); |
| 19 | writer.WriteStringValue(value); |
| 20 | } |
| 21 | |
| 22 | // CUSTOM: Replaced the call to GetRawText() for a call to GetString() because otherwise the starting and ending |
| 23 | // quotes of the string are included in the BinaryData. While this is actually a string in the REST API, we want to |
| 24 | // handle it as JSON binary data instead. |
| 25 | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 26 | private static void DeserializeArgumentsValue(JsonProperty property, ref BinaryData arguments, ModelReaderWriterOptions options = null) |
| 27 | { |
| 28 | arguments = BinaryData.FromString(property.Value.GetString()); |
| 29 | } |
| 30 | } |