openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
mailinhphan/clientOptions

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

OpenAI/src/Custom/Chat/Streaming/StreamingChatFunctionCallUpdate.Serialization.cs

31lines · modecode

1using System;
2using System.ClientModel.Primitives;
3using System.Runtime.CompilerServices;
4using System.Text.Json;
5
6namespace OpenAI.Chat;
7
8public 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}